From c1ef9f83c919949e90841ae0990aa9a0273d6490 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 3 Dec 1998 02:27:35 +0000 Subject: Reviewed by: Don Lewis Submitted by: Kirk McKusick Obtained from: Mckusick, BSDI and a host of others This exactly matches Kirks sources imported under the Tag MCKUSICK2. These are as supplied by kirk with one small change needed to compile under freeBSD. Some FreeBSD patches will be added back, though many have been added to Kirk's sources already. --- sbin/fsck_ffs/setup.c | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) (limited to 'sbin/fsck_ffs/setup.c') diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index 25dab92..5a842f4 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -32,16 +32,13 @@ */ #ifndef lint -#if 0 static const char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95"; -#endif -static const char rcsid[] = - "$Id: setup.c,v 1.11 1998/06/15 07:07:21 charnier Exp $"; #endif /* not lint */ #define DKTYPENAMES #include #include +#include #include #include @@ -82,7 +79,7 @@ setup(dev) havesb = 0; fswritefd = -1; - skipclean = preen; + skipclean = fflag ? 0 : preen; if (stat(dev, &statb) < 0) { printf("Can't stat %s: %s\n", dev, strerror(errno)); return (0); @@ -114,8 +111,7 @@ setup(dev) asblk.b_un.b_buf = malloc(SBSIZE); if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL) errx(EEXIT, "cannot allocate space for superblock"); - lp = getdisklabel((char *)NULL, fsreadfd); - if (lp) + if ((lp = getdisklabel(NULL, fsreadfd))) dev_bsize = secsize = lp->d_secsize; else dev_bsize = secsize = DEV_BSIZE; @@ -147,6 +143,10 @@ setup(dev) pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag); bflag = 0; } + if (skipclean && sblock.fs_clean) { + pwarn("FILESYSTEM CLEAN; SKIPPING CHECKS\n"); + return (-1); + } maxfsblock = sblock.fs_size; maxino = sblock.fs_ncg * sblock.fs_ipg; /* @@ -265,12 +265,6 @@ setup(dev) } } /* - * If we survive the above basic checks and are preening, - * quit here unless forced. - */ - if (skipclean && sblock.fs_clean && !fflag) - return (-1); - /* * allocate and initialize the necessary maps */ bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short)); @@ -280,22 +274,11 @@ setup(dev) (unsigned)bmapsize); goto badsb; } - statemap = calloc((unsigned)(maxino + 1), sizeof(char)); - if (statemap == NULL) { - printf("cannot alloc %u bytes for statemap\n", - (unsigned)(maxino + 1)); - goto badsb; - } - typemap = calloc((unsigned)(maxino + 1), sizeof(char)); - if (typemap == NULL) { - printf("cannot alloc %u bytes for typemap\n", - (unsigned)(maxino + 1)); - goto badsb; - } - lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short)); - if (lncntp == NULL) { - printf("cannot alloc %u bytes for lncntp\n", - (unsigned)(maxino + 1) * sizeof(short)); + inostathead = calloc((unsigned)(sblock.fs_ncg), + sizeof(struct inostatlist)); + if (inostathead == NULL) { + printf("cannot alloc %u bytes for inostathead\n", + (unsigned)(sizeof(struct inostatlist) * (sblock.fs_ncg))); goto badsb; } numdirs = sblock.fs_cstotal.cs_ndir; @@ -474,9 +457,11 @@ calcsb(dev, devfd, fs) fstypenames[pp->p_fstype] : "unknown"); return (0); } - if (pp->p_fsize == 0 || pp->p_frag == 0) { - pfatal("%s: LABELED AS A %s FILE SYSTEM, BUT BLOCK SIZE IS 0\n", - dev, fstypenames[pp->p_fstype]); + if (pp->p_fsize == 0 || pp->p_frag == 0 || + pp->p_cpg == 0 || pp->p_size == 0) { + pfatal("%s: %s: type %s fsize %d, frag %d, cpg %d, size %d\n", + dev, "INCOMPLETE LABEL", fstypenames[pp->p_fstype], + pp->p_fsize, pp->p_frag, pp->p_cpg, pp->p_size); return (0); } memset(fs, 0, sizeof(struct fs)); -- cgit v1.1