diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-11-11 08:10:37 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-11-11 08:10:37 +0000 |
commit | 43e84db7adee63859bd25952b428bbb51277ec55 (patch) | |
tree | 1a812962b78f82ccd4d3c9625b36ecddee1e89c4 | |
parent | c0fde543f73b264955d8f5256d1020d6f5067306 (diff) |
only do block checks on files that need it, therefore explicitly avoiding
fifos (which linux handles incorrectly, leaving block numbers there at
inconvenient times); patch from krw@tcn.net
-rw-r--r-- | sbin/fsck_ext2fs/pass1.c | 110 |
1 files changed, 58 insertions, 52 deletions
diff --git a/sbin/fsck_ext2fs/pass1.c b/sbin/fsck_ext2fs/pass1.c index eab8dfa98f3..e753290ab8d 100644 --- a/sbin/fsck_ext2fs/pass1.c +++ b/sbin/fsck_ext2fs/pass1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pass1.c,v 1.3 1997/06/14 04:16:54 downsj Exp $ */ +/* $OpenBSD: pass1.c,v 1.4 1998/11/11 08:10:36 deraadt Exp $ */ /* $NetBSD: pass1.c,v 1.1 1997/06/11 11:21:51 bouyer Exp $ */ /* @@ -42,7 +42,7 @@ static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93"; #if 0 static char rcsid[] = "$NetBSD: pass1.c,v 1.1 1997/06/11 11:21:51 bouyer Exp $"; #else -static char rcsid[] = "$OpenBSD: pass1.c,v 1.3 1997/06/14 04:16:54 downsj Exp $"; +static char rcsid[] = "$OpenBSD: pass1.c,v 1.4 1998/11/11 08:10:36 deraadt Exp $"; #endif #endif #endif /* not lint */ @@ -108,6 +108,8 @@ pass1() freeinodebuf(); } +#define MODE_USES_BLOCKS( mode ) (mode == IFREG || mode == IFDIR || mode == IFLNK) + static void checkinode(inumber, idesc) ino_t inumber; @@ -180,46 +182,48 @@ checkinode(inumber, idesc) dp->e2di_mode = IFREG|0600; inodirty(); } - ndb = howmany(dp->e2di_size, sblock.e2fs_bsize); - if (ndb < 0) { - if (debug) - printf("bad size %qu ndb %d:", - dp->e2di_size, ndb); - goto unknown; - } - if (mode == IFBLK || mode == IFCHR) - ndb++; - if (mode == IFLNK) { - /* - * Fake ndb value so direct/indirect block checks below - * will detect any garbage after symlink string. - */ - if (dp->e2di_size < EXT2_MAXSYMLINKLEN || - (EXT2_MAXSYMLINKLEN == 0 && dp->e2di_blocks == 0)) { - ndb = howmany(dp->e2di_size, sizeof(u_int32_t)); - if (ndb > NDADDR) { - j = ndb - NDADDR; - for (ndb = 1; j > 1; j--) - ndb *= NINDIR(&sblock); - ndb += NDADDR; - } - } - } - for (j = ndb; j < NDADDR; j++) - if (dp->e2di_blocks[j] != 0) { + if (MODE_USES_BLOCKS( mode )) { + ndb = howmany(dp->e2di_size, sblock.e2fs_bsize); + if (ndb < 0) { if (debug) - printf("bad direct addr: %d\n", dp->e2di_blocks[j]); + printf("bad size %qu ndb %d:", + dp->e2di_size, ndb); goto unknown; } - for (j = 0, ndb -= NDADDR; ndb > 0; j++) - ndb /= NINDIR(&sblock); - for (; j < NIADDR; j++) - if (dp->e2di_blocks[j+NDADDR] != 0) { - if (debug) - printf("bad indirect addr: %d\n", - dp->e2di_blocks[j+NDADDR]); - goto unknown; + if (mode == IFBLK || mode == IFCHR) + ndb++; + if (mode == IFLNK) { + /* + * Fake ndb value so direct/indirect block checks below + * will detect any garbage after symlink string. + */ + if (dp->e2di_size < EXT2_MAXSYMLINKLEN || + (EXT2_MAXSYMLINKLEN == 0 && dp->e2di_blocks == 0)) { + ndb = howmany(dp->e2di_size, sizeof(u_int32_t)); + if (ndb > NDADDR) { + j = ndb - NDADDR; + for (ndb = 1; j > 1; j--) + ndb *= NINDIR(&sblock); + ndb += NDADDR; + } + } } + for (j = ndb; j < NDADDR; j++) + if (dp->e2di_blocks[j] != 0) { + if (debug) + printf("bad direct addr: %d\n", dp->e2di_blocks[j]); + goto unknown; + } + for (j = 0, ndb -= NDADDR; ndb > 0; j++) + ndb /= NINDIR(&sblock); + for (; j < NIADDR; j++) + if (dp->e2di_blocks[j+NDADDR] != 0) { + if (debug) + printf("bad indirect addr: %d\n", + dp->e2di_blocks[j+NDADDR]); + goto unknown; + } + } if (ftypeok(dp) == 0) goto unknown; n_files++; @@ -245,20 +249,22 @@ checkinode(inumber, idesc) } else { statemap[inumber] = FSTATE; } - badblk = dupblk = 0; - idesc->id_number = inumber; - (void)ckinode(dp, idesc); - idesc->id_entryno *= btodb(sblock.e2fs_bsize); - if (dp->e2di_nblock != idesc->id_entryno) { - pwarn("INCORRECT BLOCK COUNT I=%u (%d should be %d)", - inumber, dp->e2di_nblock, idesc->id_entryno); - if (preen) - printf(" (CORRECTED)\n"); - else if (reply("CORRECT") == 0) - return; - dp = ginode(inumber); - dp->e2di_nblock = idesc->id_entryno; - inodirty(); + if (MODE_USES_BLOCKS( mode )) { + badblk = dupblk = 0; + idesc->id_number = inumber; + (void)ckinode(dp, idesc); + idesc->id_entryno *= btodb(sblock.e2fs_bsize); + if (dp->e2di_nblock != idesc->id_entryno) { + pwarn("INCORRECT BLOCK COUNT I=%u (%d should be %d)", + inumber, dp->e2di_nblock, idesc->id_entryno); + if (preen) + printf(" (CORRECTED)\n"); + else if (reply("CORRECT") == 0) + return; + dp = ginode(inumber); + dp->e2di_nblock = idesc->id_entryno; + inodirty(); + } } return; unknown: |