home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / source / s1 / dcheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1975-05-13  |  3.3 KB  |  220 lines

  1. #
  2.  
  3. char    *dargv[]
  4. {
  5.     "/dev/rrk2",
  6.     "/dev/rrp0",
  7.     0
  8. };
  9.  
  10. #define NINODE    16*16
  11. #define    NI    20
  12.  
  13. #include "/usr/sys/ino.h"
  14. #include "/usr/sys/filsys.h"
  15.  
  16. struct    inode    inode[NINODE];
  17. struct    filsys    sblock;
  18.  
  19. int    sflg;
  20. int    headpr;
  21.  
  22. int    ilist[NI] { -1};
  23. int    fi;
  24. char    *ecount;
  25. char    *lasts;
  26. int    ino;
  27. int    nerror;
  28. int    nfiles;
  29. struct dir {
  30.     int    ino;
  31.     char    name[14];
  32. };
  33.  
  34. main(argc, argv)
  35. char **argv;
  36. {
  37.     register char **p;
  38.     register int n, *lp;
  39.  
  40.     ecount = sbrk(0);
  41.     if (argc == 1) {
  42.         for (p = dargv; *p;)
  43.             check(*p++);
  44.         return(nerror);
  45.     }
  46.     while (--argc) {
  47.         argv++;
  48.         if (**argv=='-') switch ((*argv)[1]) {
  49.         case 's':
  50.             sflg++;
  51.             continue;
  52.  
  53.         case 'i':
  54.             lp = ilist;
  55.             while (lp < &ilist[NI-1] && (n = number(argv[1]))) {
  56.                 *lp++ = n;
  57.                 argv++;
  58.                 argc--;
  59.             }
  60.             *lp++ = -1;
  61.             continue;
  62.  
  63.         default:
  64.             printf("Bad flag\n");
  65.         }
  66.         check(*argv);
  67.     }
  68.     return(nerror);
  69. }
  70.  
  71. check(file)
  72. char *file;
  73. {
  74.     register i, j;
  75.     fi = open(file, 0);
  76.     if(fi < 0) {
  77.         printf("cannot open %s\n", file);
  78.         return;
  79.     }
  80.     headpr = 0;
  81.     printf("%s:\n", file);
  82.     sync();
  83.     bread(1, &sblock, 512);
  84.     nfiles = sblock.s_isize*16;
  85.     if (lasts < nfiles) {
  86.         if ((sbrk(nfiles - lasts)) == -1) {
  87.             printf("Not enough core\n");
  88.             exit(04);
  89.         }
  90.         lasts = nfiles;
  91.     }
  92.     for (i=0; i<nfiles; i++)
  93.         ecount[i] = 0;
  94.     for(i=0; ino<nfiles; i =+ NINODE/16) {
  95.         bread(i+2, inode, sizeof inode);
  96.         for(j=0; j<NINODE && ino<nfiles; j++) {
  97.             ino++;
  98.             pass1(&inode[j]);
  99.         }
  100.     }
  101.     ino = 0;
  102.     for (i=0; ino<nfiles; i =+ NINODE/16) {
  103.         bread(i+2, inode, sizeof inode);
  104.         for (j=0; j<NINODE && ino<nfiles; j++) {
  105.             ino++;
  106.             pass2(&inode[j]);
  107.         }
  108.     }
  109. }
  110.  
  111. pass1(aip)
  112. struct inode *aip;
  113. {
  114.     register doff;
  115.     register struct inode *ip;
  116.     register struct dir *dp;
  117.     int i;
  118.  
  119.     ip = aip;
  120.     if((ip->i_mode&IALLOC) == 0)
  121.         return;
  122.     if((ip->i_mode&IFMT) != IFDIR)
  123.         return;
  124.     doff = 0;
  125.     while (dp = dread(ip, doff)) {
  126.         doff =+ 16;
  127.         if (dp->ino==0)
  128.             continue;
  129.         for (i=0; ilist[i] != -1; i++)
  130.             if (ilist[i]==dp->ino)
  131.                 printf("%5l arg; %l/%.14s\n", dp->ino, ino, dp->name);
  132.         ecount[dp->ino]++;
  133.     }
  134. }
  135.  
  136. pass2(aip)
  137. {
  138.     register struct inode *ip;
  139.     register i;
  140.  
  141.     ip = aip;
  142.     i = ino;
  143.     if ((ip->i_mode&IALLOC)==0 && ecount[i]==0)
  144.         return;
  145.     if (ip->i_nlink==ecount[i] && ip->i_nlink!=0)
  146.         return;
  147.     if (headpr==0) {
  148.         printf("entries    link cnt\n");
  149.         headpr++;
  150.     }
  151.     printf("%l    %d    %d\n", ino,
  152.         ecount[i]&0377, ip->i_nlink&0377);
  153. }
  154.  
  155. dread(aip, aoff)
  156. {
  157.     register b, off;
  158.     register struct inode *ip;
  159.     static ibuf[256];
  160.     static char buf[512];
  161.  
  162.     off = aoff;
  163.     ip = aip;
  164.     if ((off&0777)==0) {
  165.         if (off==0177000) {
  166.             printf("Monstrous directory %l\n", ino);
  167.             return(0);
  168.         }
  169.         if ((ip->i_mode&ILARG)==0) {
  170.             if (off>=010000 || (b = ip->i_addr[off>>9])==0)
  171.                 return(0);
  172.             bread(b, buf, 512);
  173.         } else {
  174.             if (off==0) {
  175.                 if (ip->i_addr[0]==0)
  176.                     return(0);
  177.                 bread(ip->i_addr[0], ibuf, 512);
  178.             }
  179.             if ((b = ibuf[(off>>9)&0177])==0)
  180.                 return(0);
  181.             bread(b, buf, 512);
  182.         }
  183.     }
  184.     return(&buf[off&0777]);
  185. }
  186.  
  187. bread(bno, buf, cnt)
  188. {
  189.  
  190.     seek(fi, bno, 3);
  191.     if(read(fi, buf, cnt) != cnt) {
  192.         printf("read error %d\n", bno);
  193.         exit();
  194.     }
  195. }
  196.  
  197. bwrite(bno, buf)
  198. {
  199.  
  200.     seek(fi, bno, 3);
  201.     if(write(fi, buf, 512) != 512) {
  202.         printf("write error %d\n", bno);
  203.         exit();
  204.     }
  205. }
  206.  
  207. number(as)
  208. char *as;
  209. {
  210.     register n, c;
  211.     register char *s;
  212.  
  213.     s = as;
  214.     n = 0;
  215.     while ((c = *s++) >= '0' && c <= '9') {
  216.         n = n*10+c-'0';
  217.     }
  218.     return(n);
  219. }
  220.