1: # 2: 3: char *dargv[] 4: { 5: "/dev/rrk2", 6: "/dev/rrp0", 7: 0 8: }; 9: #define NINODE 16*16 10: #define NB 10 11: #include "/usr/sys/ino.h" 12: #include "/usr/sys/filsys.h" 13: 14: struct inode inode[NINODE]; 15: struct filsys sblock; 16: 17: int sflg; 18: 19: int fi; 20: int nifiles; 21: int nfile; 22: int nspcl; 23: int nlarg; 24: int nvlarg; 25: int nindir; 26: int nvindir; 27: int ndir; 28: int nused; 29: int nfree; 30: int ino; 31: int ndup; 32: int blist[10] { -1}; 33: int nerror; 34: int bmap[4096]; 35: 36: main(argc, argv) 37: char **argv; 38: { 39: register char **p; 40: register int n, *lp; 41: 42: if (argc == 1) { 43: for (p = dargv; *p;) 44: check(*p++); 45: return(nerror); 46: } 47: while (--argc) { 48: argv++; 49: if (**argv=='-') switch ((*argv)[1]) { 50: case 's': 51: sflg++; 52: continue; 53: 54: case 'b': 55: lp = blist; 56: while (lp < &blist[NB-1] && (n = number(argv[1]))) { 57: *lp++ = n; 58: argv++; 59: argc--; 60: } 61: *lp++ = -1; 62: continue; 63: 64: default: 65: printf("Bad flag\n"); 66: } 67: check(*argv); 68: } 69: return(nerror); 70: } 71: 72: check(file) 73: char *file; 74: { 75: register *ip, i, j; 76: 77: fi = open(file, sflg?2:0); 78: if (fi < 0) { 79: printf("cannot open %s\n", file); 80: nerror =| 04; 81: return; 82: } 83: printf("%s:\n", file); 84: nfile = 0; 85: nspcl = 0; 86: nlarg = 0; 87: nvlarg = 0; 88: nindir = 0; 89: nvindir = 0; 90: ndir = 0; 91: nused = 0; 92: nfree = 0; 93: ndup = 0; 94: for (ip = bmap; ip < &bmap[4096];) 95: *ip++ = 0; 96: sync(); 97: bread(1, &sblock, 512); 98: nifiles = sblock.s_isize*16; 99: for(i=0; ino < nifiles; i =+ NINODE/16) { 100: bread(i+2, inode, sizeof inode); 101: for(j=0; j<NINODE && ino<nifiles; j++) { 102: ino++; 103: pass1(&inode[j]); 104: } 105: } 106: ino = 0; 107: sync(); 108: bread(1, &sblock, 512); 109: if (sflg) { 110: makefree(); 111: return; 112: } 113: while(i = alloc()) { 114: if (chk(i, "free")) 115: break; 116: nfree++; 117: } 118: if (ndup) { 119: printf("%l dups in free\n", ndup); 120: nerror =| 02; 121: } 122: j = 0; 123: for (ip = bmap; ip < &bmap[4096];) { 124: i = *ip++; 125: while (i) { 126: if (i<0) 127: j--; 128: i =<< 1; 129: } 130: } 131: j =+ sblock.s_fsize - sblock.s_isize - 2; 132: if (j) 133: printf("missing%5l\n", j); 134: printf("spcl %6l\n", nspcl); 135: printf("files %6l\n", nfile); 136: printf("large %6l\n", nlarg); 137: if (nvlarg) 138: printf("huge %6l\n", nvlarg); 139: printf("direc %6l\n", ndir); 140: printf("indir %6l\n", nindir); 141: if (nvindir) 142: printf("indir2%6l\n", nvindir); 143: printf("used %6l\n", nused); 144: printf("free %6l\n", nfree); 145: close(fi); 146: } 147: 148: pass1(aip) 149: struct inode *aip; 150: { 151: int buf[256], vbuf[256]; 152: register i, j, *ip; 153: 154: ip = aip; 155: if ((ip->i_mode&IALLOC) == 0) 156: return; 157: if ((ip->i_mode&IFCHR&IFBLK) != 0) { 158: nspcl++; 159: return; 160: } 161: if ((ip->i_mode&IFMT) == IFDIR) 162: ndir++; 163: else 164: nfile++; 165: if ((ip->i_mode&ILARG) != 0) { 166: nlarg++; 167: for(i=0; i<7; i++) 168: if (ip->i_addr[i] != 0) { 169: nindir++; 170: if (chk(ip->i_addr[i], "indirect")) 171: continue; 172: bread(ip->i_addr[i], buf, 512); 173: for(j=0; j<256; j++) 174: if (buf[j] != 0) 175: chk(buf[j], "data (large)"); 176: } 177: if (ip->i_addr[7]) { 178: nvlarg++; 179: if (chk(ip->i_addr[7], "indirect")) 180: return; 181: bread(ip->i_addr[7], buf, 512); 182: for(i=0; i<256; i++) 183: if (buf[i] != 0) { 184: nvindir++; 185: if (chk(buf[i], "2nd indirect")) 186: continue; 187: bread(buf[i], vbuf, 512); 188: for(j=0; j<256; j++) 189: if (vbuf[j]) 190: chk(vbuf[j], "data (very large)"); 191: } 192: } 193: return; 194: } 195: for(i=0; i<8; i++) { 196: if (ip->i_addr[i] != 0) 197: chk(ip->i_addr[i], "data (small)"); 198: } 199: } 200: 201: chk(ab, s) 202: char *ab; 203: { 204: register char *b; 205: register n, m; 206: 207: b = ab; 208: if (ino) 209: nused++; 210: if (b<sblock.s_isize+2 || b>=sblock.s_fsize) { 211: printf("%l bad; inode=%l, class=%s\n", b, ino, s); 212: return(1); 213: } 214: m = 1 << (b&017); 215: n = (b>>4) & 07777; 216: if (bmap[n]&m) { 217: printf("%l dup; inode=%l, class=%s\n", b, ino, s); 218: ndup++; 219: } 220: bmap[n] =| m; 221: for (n=0; blist[n] != -1; n++) 222: if (b == blist[n]) 223: printf("%l arg; inode=%l, class=%s\n", b, ino, s); 224: return(0); 225: } 226: 227: alloc() 228: { 229: register b, i; 230: int buf[256]; 231: 232: i = --sblock.s_nfree; 233: if (i<0 || i>=100) { 234: printf("bad freeblock\n"); 235: return(0); 236: } 237: b = sblock.s_free[i]; 238: if (b == 0) 239: return(0); 240: if (sblock.s_nfree <= 0) { 241: bread(b, buf, 512); 242: sblock.s_nfree = buf[0]; 243: for(i=0; i<100; i++) 244: sblock.s_free[i] = buf[i+1]; 245: } 246: return(b); 247: } 248: 249: bread(bno, buf, cnt) 250: int *buf; 251: { 252: register *ip; 253: 254: seek(fi, bno, 3); 255: if (read(fi, buf, cnt) != cnt) { 256: printf("read error %d\n", bno); 257: if (sflg) { 258: printf("No update\n"); 259: sflg = 0; 260: } 261: for (ip = buf; ip < &buf[256];) 262: *ip++ = 0; 263: } 264: } 265: 266: free(in) 267: { 268: register i; 269: int buf[256]; 270: 271: if (sblock.s_nfree >= 100) { 272: buf[0] = sblock.s_nfree; 273: for(i=0; i<100; i++) 274: buf[i+1] = sblock.s_free[i]; 275: sblock.s_nfree = 0; 276: bwrite(in, buf); 277: } 278: sblock.s_free[sblock.s_nfree++] = in; 279: } 280: 281: bwrite(bno, buf) 282: { 283: 284: seek(fi, bno, 3); 285: if (write(fi, buf, 512) != 512) 286: printf("write error %d\n", bno); 287: } 288: 289: number(as) 290: char *as; 291: { 292: register n, c; 293: register char *s; 294: 295: s = as; 296: n = 0; 297: while ((c = *s++) >= '0' && c <= '9') { 298: n = n*10+c-'0'; 299: } 300: return(n); 301: } 302: 303: makefree() 304: { 305: register i; 306: 307: sblock.s_nfree = 0; 308: sblock.s_ninode = 0; 309: sblock.s_flock = 0; 310: sblock.s_ilock = 0; 311: sblock.s_fmod = 0; 312: free(0); 313: for(i=sblock.s_fsize-1; i>=sblock.s_isize+2; i--) { 314: if ((bmap[(i>>4)&07777] & (1<<(i&017)))==0) 315: free(i); 316: } 317: bwrite(1, &sblock); 318: close(fi); 319: sync(); 320: return; 321: }