diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-05-28 12:37:29 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-05-28 12:37:29 +0000 |
commit | e46f5e95760dac2ff2a6ff4cba61e0064463b15a (patch) | |
tree | 32adabece506945c0469614bf8e9c2e2854617bb /sbin | |
parent | adc3b23b1d13b546bef5946e0c0b103883acc1cc (diff) |
be more careful
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fsck_ffs/inode.c | 9 | ||||
-rw-r--r-- | sbin/fsck_ffs/pass2.c | 15 | ||||
-rw-r--r-- | sbin/fsck_ffs/setup.c | 88 |
3 files changed, 89 insertions, 23 deletions
diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index d7c71139228..393138d06aa 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -1,4 +1,4 @@ -/* $NetBSD: inode.c,v 1.17 1995/12/17 06:03:36 thorpej Exp $ */ +/* $NetBSD: inode.c,v 1.18 1996/05/21 16:58:12 mycroft Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95"; #else -static char rcsid[] = "$NetBSD: inode.c,v 1.17 1995/12/17 06:03:36 thorpej Exp $"; +static char rcsid[] = "$NetBSD: inode.c,v 1.18 1996/05/21 16:58:12 mycroft Exp $"; #endif #endif /* not lint */ @@ -140,9 +140,10 @@ iblock(idesc, ilevel, isize) ilevel--; for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++) sizepb *= NINDIR(&sblock); - nif = howmany(isize , sizepb); - if (nif > NINDIR(&sblock)) + if (isize > sizepb * NINDIR(&sblock)) nif = NINDIR(&sblock); + else + nif = howmany(isize, sizepb); if (idesc->id_func == pass1check && nif < NINDIR(&sblock)) { aplim = &bp->b_un.b_indir[NINDIR(&sblock)]; for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) { diff --git a/sbin/fsck_ffs/pass2.c b/sbin/fsck_ffs/pass2.c index 4c17f67db1f..07f82c5a234 100644 --- a/sbin/fsck_ffs/pass2.c +++ b/sbin/fsck_ffs/pass2.c @@ -1,4 +1,4 @@ -/* $NetBSD: pass2.c,v 1.12 1995/03/18 14:55:52 cgd Exp $ */ +/* $NetBSD: pass2.c,v 1.14 1996/05/21 15:32:16 mycroft Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)pass2.c 8.6 (Berkeley) 10/27/94"; #else -static char rcsid[] = "$NetBSD: pass2.c,v 1.12 1995/03/18 14:55:52 cgd Exp $"; +static char rcsid[] = "$NetBSD: pass2.c,v 1.14 1996/05/21 15:32:16 mycroft Exp $"; #endif #endif /* not lint */ @@ -127,7 +127,6 @@ pass2() memset(&curino, 0, sizeof(struct inodesc)); curino.id_type = DATA; curino.id_func = pass2check; - dp = &dino; inpend = &inpsort[inplast]; for (inpp = inpsort; inpp < inpend; inpp++) { inp = *inpp; @@ -140,7 +139,6 @@ pass2() dp = ginode(inp->i_number); dp->di_size = inp->i_isize; inodirty(); - dp = &dino; } } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) { getpathname(pathbuf, inp->i_number, inp->i_number); @@ -151,18 +149,17 @@ pass2() inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ); if (preen || reply("ADJUST") == 1) { dp = ginode(inp->i_number); - dp->di_size = roundup(inp->i_isize, DIRBLKSIZ); + dp->di_size = inp->i_isize; inodirty(); - dp = &dino; } } memset(&dino, 0, sizeof(struct dinode)); dino.di_mode = IFDIR; - dp->di_size = inp->i_isize; - memcpy(&dp->di_db[0], &inp->i_blks[0], (size_t)inp->i_numblks); + dino.di_size = inp->i_isize; + memcpy(&dino.di_db[0], &inp->i_blks[0], (size_t)inp->i_numblks); curino.id_number = inp->i_number; curino.id_parent = inp->i_parent; - (void)ckinode(dp, &curino); + (void)ckinode(&dino, &curino); } /* * Now that the parents of all directories have been found, diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index 64bc542b990..e30dbd8bb04 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -1,4 +1,4 @@ -/* $NetBSD: setup.c,v 1.22 1995/07/12 01:49:23 cgd Exp $ */ +/* $NetBSD: setup.c,v 1.25 1996/05/21 17:36:21 mycroft Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)setup.c 8.5 (Berkeley) 11/23/94"; #else -static char rcsid[] = "$NetBSD: setup.c,v 1.22 1995/07/12 01:49:23 cgd Exp $"; +static char rcsid[] = "$NetBSD: setup.c,v 1.25 1996/05/21 17:36:21 mycroft Exp $"; #endif #endif /* not lint */ @@ -79,6 +79,7 @@ setup(dev) struct stat statb; struct fs proto; int doskipclean; + u_int64_t maxfilesize; havesb = 0; fswritefd = -1; @@ -135,10 +136,10 @@ setup(dev) printf("%s %s\n%s %s\n%s %s\n", "SEARCH FOR ALTERNATE SUPER-BLOCK", "FAILED. YOU MUST USE THE", - "-b OPTION TO FSCK TO SPECIFY THE", + "-b OPTION TO FSCK_FFS TO SPECIFY THE", "LOCATION OF AN ALTERNATE", "SUPER-BLOCK TO SUPPLY NEEDED", - "INFORMATION; SEE fsck(8)."); + "INFORMATION; SEE fsck_ffs(8)."); return(0); } doskipclean = 0; @@ -157,6 +158,12 @@ setup(dev) } maxfsblock = sblock.fs_size; maxino = sblock.fs_ncg * sblock.fs_ipg; + sizepb = sblock.fs_bsize; + maxfilesize = sblock.fs_bsize * NDADDR - 1; + for (i = 0; i < NIADDR; i++) { + sizepb *= NINDIR(&sblock); + maxfilesize += sizepb; + } /* * Check and potentially fix certain fields in the super block. */ @@ -199,7 +206,73 @@ setup(dev) dirty(&asblk); } } + if (sblock.fs_bmask != ~(sblock.fs_bsize - 1)) { + pwarn("INCORRECT BMASK=%x IN SUPERBLOCK", + sblock.fs_bmask); + sblock.fs_bmask = ~(sblock.fs_bsize - 1); + if (preen) + printf(" (FIXED)\n"); + if (preen || reply("FIX") == 1) { + sbdirty(); + dirty(&asblk); + } + } + if (sblock.fs_fmask != ~(sblock.fs_fsize - 1)) { + pwarn("INCORRECT FMASK=%x IN SUPERBLOCK", + sblock.fs_fmask); + sblock.fs_fmask = ~(sblock.fs_fsize - 1); + if (preen) + printf(" (FIXED)\n"); + if (preen || reply("FIX") == 1) { + sbdirty(); + dirty(&asblk); + } + } if (sblock.fs_inodefmt >= FS_44INODEFMT) { + if (sblock.fs_maxfilesize != maxfilesize) { + pwarn("INCORRECT MAXFILESIZE=%qd IN SUPERBLOCK", + sblock.fs_maxfilesize); + sblock.fs_maxfilesize = maxfilesize; + if (preen) + printf(" (FIXED)\n"); + if (preen || reply("FIX") == 1) { + sbdirty(); + dirty(&asblk); + } + } + if (sblock.fs_maxsymlinklen != MAXSYMLINKLEN) { + pwarn("INCORRECT MAXSYMLINKLEN=%d IN SUPERBLOCK", + sblock.fs_maxsymlinklen); + sblock.fs_maxsymlinklen = MAXSYMLINKLEN; + if (preen) + printf(" (FIXED)\n"); + if (preen || reply("FIX") == 1) { + sbdirty(); + dirty(&asblk); + } + } + if (sblock.fs_qbmask != ~sblock.fs_bmask) { + pwarn("INCORRECT QBMASK=%qx IN SUPERBLOCK", + sblock.fs_qbmask); + sblock.fs_qbmask = ~sblock.fs_bmask; + if (preen) + printf(" (FIXED)\n"); + if (preen || reply("FIX") == 1) { + sbdirty(); + dirty(&asblk); + } + } + if (sblock.fs_qfmask != ~sblock.fs_fmask) { + pwarn("INCORRECT QFMASK=%qx IN SUPERBLOCK", + sblock.fs_qfmask); + sblock.fs_qfmask = ~sblock.fs_fmask; + if (preen) + printf(" (FIXED)\n"); + if (preen || reply("FIX") == 1) { + sbdirty(); + dirty(&asblk); + } + } newinofmt = 1; } else { sblock.fs_qbmask = ~sblock.fs_bmask; @@ -216,12 +289,7 @@ setup(dev) return(0); doinglevel2++; sblock.fs_inodefmt = FS_44INODEFMT; - sizepb = sblock.fs_bsize; - sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1; - for (i = 0; i < NIADDR; i++) { - sizepb *= NINDIR(&sblock); - sblock.fs_maxfilesize += sizepb; - } + sblock.fs_maxfilesize = maxfilesize; sblock.fs_maxsymlinklen = MAXSYMLINKLEN; sblock.fs_qbmask = ~sblock.fs_bmask; sblock.fs_qfmask = ~sblock.fs_fmask; |