setup.c (92806) | setup.c (92839) |
---|---|
1/* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static const char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95"; 37#endif 38static const char rcsid[] = | 1/* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static const char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95"; 37#endif 38static const char rcsid[] = |
39 "$FreeBSD: head/sbin/fsck_ffs/setup.c 92806 2002-03-20 17:55:10Z obrien $"; | 39 "$FreeBSD: head/sbin/fsck_ffs/setup.c 92839 2002-03-20 22:57:10Z imp $"; |
40#endif /* not lint */ 41 42#define DKTYPENAMES 43#include <sys/param.h> 44#include <sys/stat.h> 45#include <sys/disklabel.h> 46#include <sys/file.h> 47#include <sys/sysctl.h> --- 7 unchanged lines hidden (view full) --- 55#include <string.h> 56 57#include "fsck.h" 58 59struct bufarea asblk; 60#define altsblock (*asblk.b_un.b_fs) 61#define POWEROF2(num) (((num) & ((num) - 1)) == 0) 62 | 40#endif /* not lint */ 41 42#define DKTYPENAMES 43#include <sys/param.h> 44#include <sys/stat.h> 45#include <sys/disklabel.h> 46#include <sys/file.h> 47#include <sys/sysctl.h> --- 7 unchanged lines hidden (view full) --- 55#include <string.h> 56 57#include "fsck.h" 58 59struct bufarea asblk; 60#define altsblock (*asblk.b_un.b_fs) 61#define POWEROF2(num) (((num) & ((num) - 1)) == 0) 62 |
63static void badsb __P((int listerr, char *s)); 64static int calcsb __P((char *dev, int devfd, struct fs *fs)); 65static struct disklabel *getdisklabel __P((char *s, int fd)); | 63static void badsb(int listerr, char *s); 64static int calcsb(char *dev, int devfd, struct fs *fs); 65static struct disklabel *getdisklabel(char *s, int fd); |
66 67/* 68 * Read in a superblock finding an alternate if necessary. 69 * Return 1 if successful, 0 if unsuccessful, -1 if filesystem 70 * is already clean (preen mode only). 71 */ 72int | 66 67/* 68 * Read in a superblock finding an alternate if necessary. 69 * Return 1 if successful, 0 if unsuccessful, -1 if filesystem 70 * is already clean (preen mode only). 71 */ 72int |
73setup(dev) 74 char *dev; | 73setup(char *dev) |
75{ 76 long cg, asked, i, j; 77 long bmapsize; 78 off_t sizepb; 79 struct stat statb; 80 struct fs proto; 81 size_t size; 82 --- 272 unchanged lines hidden (view full) --- 355 ckfini(0); 356 return (0); 357} 358 359/* 360 * Read in the super block and its summary info. 361 */ 362int | 74{ 75 long cg, asked, i, j; 76 long bmapsize; 77 off_t sizepb; 78 struct stat statb; 79 struct fs proto; 80 size_t size; 81 --- 272 unchanged lines hidden (view full) --- 354 ckfini(0); 355 return (0); 356} 357 358/* 359 * Read in the super block and its summary info. 360 */ 361int |
363readsb(listerr) 364 int listerr; | 362readsb(int listerr) |
365{ 366 ufs_daddr_t super = bflag ? bflag : SBOFF / dev_bsize; 367 368 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0) 369 return (0); 370 sblk.b_bno = super; 371 sblk.b_size = SBSIZE; 372 /* --- 90 unchanged lines hidden (view full) --- 463 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE"); 464 return (0); 465 } 466 havesb = 1; 467 return (1); 468} 469 470static void | 363{ 364 ufs_daddr_t super = bflag ? bflag : SBOFF / dev_bsize; 365 366 if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0) 367 return (0); 368 sblk.b_bno = super; 369 sblk.b_size = SBSIZE; 370 /* --- 90 unchanged lines hidden (view full) --- 461 "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE"); 462 return (0); 463 } 464 havesb = 1; 465 return (1); 466} 467 468static void |
471badsb(listerr, s) 472 int listerr; 473 char *s; | 469badsb(int listerr, char *s) |
474{ 475 476 if (!listerr) 477 return; 478 if (preen) 479 printf("%s: ", cdevname); 480 pfatal("BAD SUPER BLOCK: %s\n", s); 481} 482 483void | 470{ 471 472 if (!listerr) 473 return; 474 if (preen) 475 printf("%s: ", cdevname); 476 pfatal("BAD SUPER BLOCK: %s\n", s); 477} 478 479void |
484sblock_init() | 480sblock_init(void) |
485{ 486 struct disklabel *lp; 487 488 fswritefd = -1; 489 fsmodified = 0; 490 lfdir = 0; 491 initbarea(&sblk); 492 initbarea(&asblk); --- 9 unchanged lines hidden (view full) --- 502 503/* 504 * Calculate a prototype superblock based on information in the disk label. 505 * When done the cgsblock macro can be calculated and the fs_ncg field 506 * can be used. Do NOT attempt to use other macros without verifying that 507 * their needed information is available! 508 */ 509static int | 481{ 482 struct disklabel *lp; 483 484 fswritefd = -1; 485 fsmodified = 0; 486 lfdir = 0; 487 initbarea(&sblk); 488 initbarea(&asblk); --- 9 unchanged lines hidden (view full) --- 498 499/* 500 * Calculate a prototype superblock based on information in the disk label. 501 * When done the cgsblock macro can be calculated and the fs_ncg field 502 * can be used. Do NOT attempt to use other macros without verifying that 503 * their needed information is available! 504 */ 505static int |
510calcsb(dev, devfd, fs) 511 char *dev; 512 int devfd; 513 struct fs *fs; | 506calcsb(char *dev, int devfd, struct fs *fs) |
514{ 515 struct disklabel *lp; 516 struct partition *pp; 517 char *cp; 518 int i; 519 520 cp = strchr(dev, '\0') - 1; 521 if (cp == (char *)-1 || ((*cp < 'a' || *cp > 'h') && !isdigit(*cp))) { --- 41 unchanged lines hidden (view full) --- 563 fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg); 564 for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1) 565 fs->fs_fsbtodb++; 566 dev_bsize = lp->d_secsize; 567 return (1); 568} 569 570static struct disklabel * | 507{ 508 struct disklabel *lp; 509 struct partition *pp; 510 char *cp; 511 int i; 512 513 cp = strchr(dev, '\0') - 1; 514 if (cp == (char *)-1 || ((*cp < 'a' || *cp > 'h') && !isdigit(*cp))) { --- 41 unchanged lines hidden (view full) --- 556 fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg); 557 for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1) 558 fs->fs_fsbtodb++; 559 dev_bsize = lp->d_secsize; 560 return (1); 561} 562 563static struct disklabel * |
571getdisklabel(s, fd) 572 char *s; 573 int fd; | 564getdisklabel(char *s, int fd) |
574{ 575 static struct disklabel lab; 576 577 if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { 578 if (s == NULL) 579 return ((struct disklabel *)NULL); 580 pwarn("ioctl (GCINFO): %s\n", strerror(errno)); 581 errx(EEXIT, "%s: can't read disk label", s); 582 } 583 return (&lab); 584} | 565{ 566 static struct disklabel lab; 567 568 if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { 569 if (s == NULL) 570 return ((struct disklabel *)NULL); 571 pwarn("ioctl (GCINFO): %s\n", strerror(errno)); 572 errx(EEXIT, "%s: can't read disk label", s); 573 } 574 return (&lab); 575} |