diff options
Diffstat (limited to 'sbin/fsck/pass1.c')
| -rw-r--r-- | sbin/fsck/pass1.c | 107 |
1 files changed, 18 insertions, 89 deletions
diff --git a/sbin/fsck/pass1.c b/sbin/fsck/pass1.c index 0d3fc478f37fe..30c0e7d5b5411 100644 --- a/sbin/fsck/pass1.c +++ b/sbin/fsck/pass1.c @@ -36,7 +36,7 @@ static const char sccsid[] = "@(#)pass1.c 8.6 (Berkeley) 4/28/95"; #endif static const char rcsid[] = - "$Id: pass1.c,v 1.13 1998/07/06 19:11:35 bde Exp $"; + "$Id: pass1.c,v 1.11 1998/06/15 07:07:16 charnier Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -52,17 +52,14 @@ static const char rcsid[] = static ufs_daddr_t badblk; static ufs_daddr_t dupblk; -static ino_t lastino; /* last inode in use */ static void checkinode __P((ino_t inumber, struct inodesc *)); void pass1() { - u_int8_t *cp; ino_t inumber; - int c, i, cgd, inosused; - struct inostat *info; + int c, i, cgd; struct inodesc idesc; /* @@ -84,84 +81,15 @@ pass1() memset(&idesc, 0, sizeof(struct inodesc)); idesc.id_type = ADDR; idesc.id_func = pass1check; + inumber = 0; n_files = n_blks = 0; + resetinodebuf(); for (c = 0; c < sblock.fs_ncg; c++) { - inumber = c * sblock.fs_ipg; - setinodebuf(inumber); - inosused = sblock.fs_ipg; - /* - * If we are using soft updates, then we can trust the - * cylinder group inode allocation maps to tell us which - * inodes are allocated. We will scan the used inode map - * to find the inodes that are really in use, and then - * read only those inodes in from disk. - */ - if (preen && usedsoftdep) { - getblk(&cgblk, cgtod(&sblock, c), sblock.fs_cgsize); - if (!cg_chkmagic(&cgrp)) - pfatal("CG %d: BAD MAGIC NUMBER\n", c); - cp = &cg_inosused(&cgrp)[(sblock.fs_ipg - 1) / NBBY]; - for ( ; inosused > 0; inosused -= NBBY, cp--) { - if (*cp == 0) - continue; - for (i = 1 << (NBBY - 1); i > 0; i >>= 1) { - if (*cp & i) - break; - inosused--; - } - break; - } - if (inosused < 0) - inosused = 0; - } - /* - * Allocate inoinfo structures for the allocated inodes. - */ - inostathead[c].il_numalloced = inosused; - if (inosused == 0) { - inostathead[c].il_stat = 0; - continue; - } - info = calloc((unsigned)inosused, sizeof(struct inostat)); - if (info == NULL) - pfatal("cannot alloc %u bytes for inoinfo\n", - (unsigned)(sizeof(struct inostat) * inosused)); - inostathead[c].il_stat = info; - /* - * Scan the allocated inodes. - */ - for (i = 0; i < inosused; i++, inumber++) { - if (inumber < ROOTINO) { - (void)getnextinode(inumber); + for (i = 0; i < sblock.fs_ipg; i++, inumber++) { + if (inumber < ROOTINO) continue; - } checkinode(inumber, &idesc); } - lastino += 1; - if (inosused < sblock.fs_ipg || inumber == lastino) - continue; - /* - * If we were not able to determine in advance which inodes - * were in use, then reduce the size of the inoinfo structure - * to the size necessary to describe the inodes that we - * really found. - */ - inosused = lastino - (c * sblock.fs_ipg); - if (inosused < 0) - inosused = 0; - inostathead[c].il_numalloced = inosused; - if (inosused == 0) { - free(inostathead[c].il_stat); - inostathead[c].il_stat = 0; - continue; - } - info = calloc((unsigned)inosused, sizeof(struct inostat)); - if (info == NULL) - pfatal("cannot alloc %u bytes for inoinfo\n", - (unsigned)(sizeof(struct inostat) * inosused)); - memmove(info, inostathead[c].il_stat, inosused * sizeof(*info)); - free(inostathead[c].il_stat); - inostathead[c].il_stat = info; } freeinodebuf(); } @@ -192,7 +120,7 @@ checkinode(inumber, idesc) inodirty(); } } - inoinfo(inumber)->ino_state = USTATE; + statemap[inumber] = USTATE; return; } lastino = inumber; @@ -230,7 +158,8 @@ checkinode(inumber, idesc) if (debug) { symbuf[dp->di_size] = 0; printf("convert symlink %lu(%s) of size %ld\n", - (u_long)inumber, symbuf, (long)dp->di_size); + (u_long)inumber, symbuf, + (long)dp->di_size); } dp = ginode(inumber); memmove(dp->di_shortlink, symbuf, (long)dp->di_size); @@ -241,7 +170,8 @@ checkinode(inumber, idesc) * Fake ndb value so direct/indirect block checks below * will detect any garbage after symlink string. */ - if (dp->di_size < sblock.fs_maxsymlinklen) { + if (dp->di_size < sblock.fs_maxsymlinklen || + dp->di_blocks == 0) { ndb = howmany(dp->di_size, sizeof(ufs_daddr_t)); if (ndb > NDADDR) { j = ndb - NDADDR; @@ -270,7 +200,7 @@ checkinode(inumber, idesc) if (ftypeok(dp) == 0) goto unknown; n_files++; - inoinfo(inumber)->ino_linkcnt = dp->di_nlink; + lncntp[inumber] = dp->di_nlink; if (dp->di_nlink <= 0) { zlnp = (struct zlncnt *)malloc(sizeof *zlnp); if (zlnp == NULL) { @@ -287,14 +217,13 @@ checkinode(inumber, idesc) } if (mode == IFDIR) { if (dp->di_size == 0) - inoinfo(inumber)->ino_state = DCLEAR; + statemap[inumber] = DCLEAR; else - inoinfo(inumber)->ino_state = DSTATE; + statemap[inumber] = DSTATE; cacheino(dp, inumber); - countdirs++; } else - inoinfo(inumber)->ino_state = FSTATE; - inoinfo(inumber)->ino_type = IFTODT(mode); + statemap[inumber] = FSTATE; + typemap[inumber] = IFTODT(mode); if (doinglevel2 && (dp->di_ouid != (u_short)-1 || dp->di_ogid != (u_short)-1)) { dp = ginode(inumber); @@ -322,9 +251,9 @@ checkinode(inumber, idesc) return; unknown: pfatal("UNKNOWN FILE TYPE I=%lu", inumber); - inoinfo(inumber)->ino_state = FCLEAR; + statemap[inumber] = FCLEAR; if (reply("CLEAR") == 1) { - inoinfo(inumber)->ino_state = USTATE; + statemap[inumber] = USTATE; dp = ginode(inumber); clearinode(dp); inodirty(); |
