# 2.11BSD#431 - /usr/src/usr.sbin/quot/quot.c

##### Functions

    acct              X
    bread             X
    check             X
    copy              X
    main              X
    qcmp              X
    report            X

##### Variables

    cflg              X
    dargv             X
    du                X
    fflg              X
    fi                X
    ino               X
    itab              X
    nfiles            X
    nflg              X
    overflow          X
    sblock            X
    sizes             X

##### Macros

    ISIZ              X
    ITABSZ            X
    NUID              X
    TSIZE             X

##### struct's

    du                X

       1:
       2: /*
       3:  * Disk usage by user
       4:  */
       5: #include <stdio.h>
       6: #include <ctype.h>
       7: #include <pwd.h>
       8: #include <sys/param.h>
       9: #include <sys/inode.h>
      10: #include <sys/fs.h>
      11:
      12: char    *dargv[] = {
      13: #ifndef MENLO
      14:     "/dev/rrp3",
      15: #else
      16:     "/dev/rrp0",  /* /we -- pag 7/1/79 */
      17: #endif
      18:     0
      19: };
      20:
      21: #define ITABSZ  256
      22: #define ISIZ    (DEV_BSIZE/sizeof(struct dinode))
      23: #define NUID    300
      24: struct  fs  sblock;
      25: struct  dinode  itab[ITABSZ];
      26: struct du
      27: {
      28:     long    blocks;
      29:     long    nfiles;
      30:     int uid;
      31:     char    *name;
      32: } du[NUID];
      33: #define TSIZE   500
      34: int sizes[TSIZE];
      35: long    overflow;
      36:
      37: int nflg;
      38: int fflg;
      39: int cflg;
      40:
      41: int fi;
      42: unsigned    ino;
      43: unsigned    nfiles;
      44:
      45: struct  passwd  *getpwent();
      46: char    *malloc();
      47: char    *copy();
      48:
      49: main(argc, argv)
      50: char **argv;
      51: {
      52:     register int n;
      53:     register struct passwd *lp;
      54:     register char **p;
      55:
      56:     for(n=0; n<NUID; n++)
      57:         du[n].uid = n;
      58:     while((lp=getpwent()) != 0) {
      59:         n = lp->pw_uid;
      60:         if (n>NUID)
      61:             continue;
      62:         if(du[n].name)
      63:             continue;
      64:         du[n].name = copy(lp->pw_name);
      65:     }
      66:     if (argc == 1) {
      67:         for (p = dargv; *p;) {
      68:             check(*p++);
      69:             report();
      70:         }
      71:         return(0);
      72:     }
      73:     while (--argc) {
      74:         argv++;
      75:         if (argv[0][0]=='-') {
      76:             if (argv[0][1]=='n')
      77:                 nflg++;
      78:             else if (argv[0][1]=='f')
      79:                 fflg++;
      80:             else if (argv[0][1]=='c')
      81:                 cflg++;
      82:         } else {
      83:             check(*argv);
      84:             report();
      85:         }
      86:     }
      87:     return(0);
      88: }
      89:
      90: check(file)
      91: char *file;
      92: {
      93:     register unsigned i, j;
      94:     register c;
      95:
      96:     fi = open(file, 0);
      97:     if (fi < 0) {
      98:         printf("cannot open %s\n", file);
      99:         return;
     100:     }
     101:     printf("%s:\n", file);
     102:     sync();
     103:     bread(1, (char *)&sblock, sizeof sblock);
     104:     nfiles = (sblock.fs_isize-2)*(DEV_BSIZE/sizeof(struct dinode));
     105:     ino = 0;
     106:     if (nflg) {
     107:         if (isdigit(c = getchar()))
     108:             ungetc(c, stdin);
     109:         else while (c!='\n' && c != EOF)
     110:             c = getchar();
     111:     }
     112:     for(i=2; ino<nfiles; i += ITABSZ/ISIZ) {
     113:         bread(i, (char *)itab, sizeof itab);
     114:         for (j=0; j<ITABSZ && ino<nfiles; j++) {
     115:             ino++;
     116:             acct(&itab[j]);
     117:         }
     118:     }
     119: }
     120:
     121: acct(ip)
     122: register struct dinode *ip;
     123: {
     124:     register n;
     125:     register char *np;
     126:     static fino;
     127:
     128:     if ((ip->di_mode&IFMT) == 0)
     129:         return;
     130:     if (cflg) {
     131:         if ((ip->di_mode&IFMT)!=IFDIR && (ip->di_mode&IFMT)!=IFREG)
     132:             return;
     133:         n = (ip->di_size+DEV_BSIZE-1)/DEV_BSIZE;
     134:         if (n >= TSIZE) {
     135:             overflow += n;
     136:             n = TSIZE-1;
     137:         }
     138:         sizes[n]++;
     139:         return;
     140:     }
     141:     if (ip->di_uid >= NUID)
     142:         return;
     143:     du[ip->di_uid].blocks += (ip->di_size+DEV_BSIZE-1)/DEV_BSIZE;
     144:     du[ip->di_uid].nfiles++;
     145:     if (nflg) {
     146:     tryagain:
     147:         if (fino==0)
     148:             if (scanf("%d", &fino)<=0)
     149:                 return;
     150:         if (fino > ino)
     151:             return;
     152:         if (fino<ino) {
     153:             while ((n=getchar())!='\n' && n!=EOF)
     154:                 ;
     155:             fino = 0;
     156:             goto tryagain;
     157:         }
     158:         if (np = du[ip->di_uid].name)
     159:             printf("%.7s\t", np);
     160:         else
     161:             printf("%d\t", ip->di_uid);
     162:         while ((n = getchar())==' ' || n=='\t')
     163:             ;
     164:         putchar(n);
     165:         while (n!=EOF && n!='\n') {
     166:             n = getchar();
     167:             putchar(n);
     168:         }
     169:         fino = 0;
     170:     }
     171: }
     172:
     173: bread(bno, buf, cnt)
     174: unsigned bno;
     175: char *buf;
     176: {
     177:
     178:     lseek(fi, (long)bno*DEV_BSIZE, 0);
     179:     if (read(fi, buf, cnt) != cnt) {
     180:         printf("read error %u\n", bno);
     181:         exit(1);
     182:     }
     183: }
     184:
     185: qcmp(p1, p2)
     186: register struct du *p1, *p2;
     187: {
     188:     if (p1->blocks > p2->blocks)
     189:         return(-1);
     190:     if (p1->blocks < p2->blocks)
     191:         return(1);
     192:     return(strcmp(p1->name, p2->name));
     193: }
     194:
     195: report()
     196: {
     197:     register i;
     198:
     199:     if (nflg)
     200:         return;
     201:     if (cflg) {
     202:         long t = 0;
     203:         for (i=0; i<TSIZE-1; i++)
     204:             if (sizes[i]) {
     205:                 t += i*sizes[i];
     206:                 printf("%d\t%d\t%ld\n", i, sizes[i], t);
     207:             }
     208:         printf("%d\t%d\t%ld\n", TSIZE-1, sizes[TSIZE-1], overflow+t);
     209:         return;
     210:     }
     211:     qsort(du, NUID, sizeof(du[0]), qcmp);
     212:     for (i=0; i<NUID; i++) {
     213:         if (du[i].blocks==0)
     214:             return;
     215:         printf("%5D\t", du[i].blocks);
     216:         if (fflg)
     217:             printf("%5D\t", du[i].nfiles);
     218:         if (du[i].name)
     219:             printf("%s\n", du[i].name);
     220:         else
     221:             printf("#%d\n", du[i].uid);
     222:     }
     223: }
     224:
     225: char *
     226: copy(s)
     227: char *s;
     228: {
     229:     register char *p;
     230:     register n;
     231:
     232:     for(n=0; s[n]; n++)
     233:         ;
     234:     p = malloc((unsigned)n+1);
     235:     for(n=0; p[n] = s[n]; n++)
     236:         ;
     237:     return(p);
     238: }

#### Defined functions

acct defined in line 121; used 1 times

- in line 116

bread defined in line 173; used 2 times

- in line 103, 113

check defined in line 90; used 2 times

- in line 68, 83

copy defined in line 225; used 2 times

- in line 47, 64

main defined in line 49; never used
qcmp defined in line 185; used 1 times

- in line 211

report defined in line 195; used 2 times

- in line 69, 84

#### Defined variables

cflg defined in line 39; used 3 times

- in line 81, 130, 201

dargv defined in line 12; used 1 times

- in line 67

du defined in line 32; used 14 times

- in line 57-64(3), 143-144(2), 158, 211-221(8)

fflg defined in line 38; used 2 times

- in line 79, 216

fi defined in line 41; used 4 times

- in line 96-97(2), 178-179(2)

ino defined in line 42; used 6 times

- in line 105, 112-115(3), 150-152(2)

itab defined in line 25; used 3 times

- in line 113-116(3)

nfiles defined in line 43; used 6 times

- in line 29, 104, 112-114(2), 144, 217

nflg defined in line 37; used 4 times

- in line 77, 106, 145, 199

overflow defined in line 35; used 2 times

- in line 135, 208

sblock defined in line 24; used 3 times

- in line 103-104(3)

sizes defined in line 34; used 5 times

- in line 138, 204-208(4)

#### Defined struct's

du defined in line 26; used 2 times

- in line 186(2)

#### Defined macros

ISIZ defined in line 22; used 1 times

- in line 112

ITABSZ defined in line 21; used 3 times

- in line 25, 112-114(2)

NUID defined in line 23; used 6 times

- in line 32, 56-60(2), 141, 211-212(2)

TSIZE defined in line 33; used 6 times

- in line 34, 134-136(2), 203-208(3)

Last modified: 1987-02-20 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1663 |