#define NI 16 #define NB 10 #define BITS 8 #define MAXFN 500 #ifndef STANDALONE #include #endif #include #include #include #include #include struct filsys sblock; struct dinode itab[INOPB*NI]; daddr_t iaddr[NADDR]; daddr_t blist[NB]; char *bmap; int sflg; int mflg; int dflg; int fi; ino_t ino; ino_t nrfile; ino_t ndfile; ino_t nbfile; ino_t ncfile; daddr_t ndirect; daddr_t nindir; daddr_t niindir; daddr_t niiindir; daddr_t nfree; daddr_t ndup; int nerror; long atol(); daddr_t alloc(); #ifndef STANDALONE char *malloc(); #endif main(argc, argv) char *argv[]; { register i; long n; blist[0] = -1; #ifndef STANDALONE while (--argc) { argv++; if (**argv=='-') switch ((*argv)[1]) { case 'd': dflg++; continue; case 'm': mflg++; continue; case 's': sflg++; continue; case 'b': for(i=0; i= mino) break; bread((daddr_t)i, (char *)itab, sizeof(itab)); for(j=0; j= mino) break; ino++; pass1(&itab[j]); } } ino = 0; #ifndef STANDALONE sync(); #endif bread((daddr_t)1, (char *)&sblock, sizeof(sblock)); if (sflg) { makefree(); close(fi); #ifndef STANDALONE if (bmap) free(bmap); #endif return; } nfree = 0; while(n = alloc()) { if (chk(n, "free")) break; nfree++; } close(fi); #ifndef STANDALONE if (bmap) free(bmap); #endif i = nrfile + ndfile + ncfile + nbfile; #ifndef STANDALONE printf("files %6u (r=%u,d=%u,b=%u,c=%u)\n", i, nrfile, ndfile, nbfile, ncfile); #else printf("files %u (r=%u,d=%u,b=%u,c=%u)\n", i, nrfile, ndfile, nbfile, ncfile); #endif n = ndirect + nindir + niindir + niindir; #ifdef STANDALONE printf("used %ld (i=%ld,ii=%ld,iii=%ld,d=%ld)\n", n, nindir, niindir, niiindir, ndirect); printf("free %ld\n", nfree); #else printf("used %7ld (i=%ld,ii=%ld,iii=%ld,d=%ld)\n", n, nindir, niindir, niiindir, ndirect); printf("free %7ld\n", nfree); #endif if(!dflg) { n = 0; for(d=sblock.s_isize; ddi_mode & IFMT; if(i == 0) { sblock.s_tinode++; return; } if(i == IFCHR) { ncfile++; return; } if(i == IFBLK) { nbfile++; return; } if(i == IFDIR) ndfile++; else if(i == IFREG) nrfile++; else { printf("bad mode %u\n", ino); return; } l3tol(iaddr, ip->di_addr, NADDR); for(i=0; i=sblock.s_fsize) { printf("%ld bad; inode=%u, class=%s\n", bno, ino, s); return(1); } if(duped(bno)) { printf("%ld dup; inode=%u, class=%s\n", bno, ino, s); ndup++; } for (n=0; blist[n] != -1; n++) if (bno == blist[n]) printf("%ld arg; inode=%u, class=%s\n", bno, ino, s); return(0); } duped(bno) daddr_t bno; { daddr_t d; register m, n; if(dflg) return(0); d = bno - sblock.s_isize; m = 1 << (d%BITS); n = (d/BITS); if(bmap[n] & m) return(1); bmap[n] |= m; return(0); } daddr_t alloc() { int i; daddr_t bno; union { char data[BSIZE]; struct fblk fb; } buf; sblock.s_tfree--; if (sblock.s_nfree<=0) return(0); if (sblock.s_nfree>NICFREE) { printf("Bad free list, s.b. count = %d\n", sblock.s_nfree); return(0); } bno = sblock.s_free[--sblock.s_nfree]; sblock.s_free[sblock.s_nfree] = (daddr_t)0; if(bno == 0) return(bno); if(sblock.s_nfree <= 0) { bread(bno, buf.data, BSIZE); sblock.s_nfree = buf.df_nfree; if (sblock.s_nfree<0 || sblock.s_nfree>NICFREE) { printf("Bad free list, entry count of block %ld = %d\n", bno, sblock.s_nfree); sblock.s_nfree = 0; return(0); } for(i=0; i= NICFREE) { for(i=0; i MAXFN) n = MAXFN; sblock.s_n = n; m = sblock.s_m; if(m <= 0 || m > sblock.s_n) m = 3; sblock.s_m = m; for(i=0; i 0; d -= sblock.s_n) for(i=0; i= sblock.s_isize) if(!duped(f)) bfree(f); } bwrite((daddr_t)1, (char *)&sblock); #ifndef STANDALONE sync(); #endif return; }