From bea492ce603ed2e3cd048ae9f5779f8e8289e86d Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Thu, 2 Oct 1980 01:28:01 -0800 Subject: [PATCH] date and time created 80/10/01 17:28:01 by bill SCCS-vsn: usr.sbin/quot/quot.c 4.1 --- usr/src/usr.sbin/quot/quot.c | 236 +++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) create mode 100644 usr/src/usr.sbin/quot/quot.c diff --git a/usr/src/usr.sbin/quot/quot.c b/usr/src/usr.sbin/quot/quot.c new file mode 100644 index 0000000000..ccb3b40ebc --- /dev/null +++ b/usr/src/usr.sbin/quot/quot.c @@ -0,0 +1,236 @@ +static char *sccsid = "@(#)quot.c 4.1 (Berkeley) %G%"; +/* + * Disk usage by user + */ + +char *dargv[] = { + "/dev/rrp3", + 0 +}; + +#include +#include +#include +#include +#include +#include +#include + +#define ITABSZ 256 +#define ISIZ (BSIZE/sizeof(struct dinode)) +#define NUID 1000 +struct filsys sblock; +struct dinode itab[ITABSZ]; +struct du +{ + long blocks; + long nfiles; + int uid; + char *name; +} du[NUID]; +#define TSIZE 500 +int sizes[TSIZE]; +long overflow; + +int nflg; +int fflg; +int cflg; + +int fi; +unsigned ino; +unsigned nfiles; + +struct passwd *getpwent(); +char *malloc(); +char *copy(); + +main(argc, argv) +char **argv; +{ + register int n; + register struct passwd *lp; + register char **p; + + for(n=0; npw_uid; + if (n>NUID) + continue; + if(du[n].name) + continue; + du[n].name = copy(lp->pw_name); + } + if (argc == 1) { + for (p = dargv; *p;) { + check(*p++); + report(); + } + return(0); + } + while (--argc) { + argv++; + if (argv[0][0]=='-') { + if (argv[0][1]=='n') + nflg++; + else if (argv[0][1]=='f') + fflg++; + else if (argv[0][1]=='c') + cflg++; + } else { + check(*argv); + report(); + } + } + return(0); +} + +check(file) +char *file; +{ + register unsigned i, j; + register c; + + fi = open(file, 0); + if (fi < 0) { + printf("cannot open %s\n", file); + return; + } + printf("%s:\n", file); + sync(); + bread(1, (char *)&sblock, sizeof sblock); + nfiles = (sblock.s_isize-2)*(BSIZE/sizeof(struct dinode)); + ino = 0; + if (nflg) { + if (isdigit(c = getchar())) + ungetc(c, stdin); + else while (c!='\n' && c != EOF) + c = getchar(); + } + for(i=2; inodi_mode&IFMT) == 0) + return; + if (cflg) { + if ((ip->di_mode&IFMT)!=IFDIR && (ip->di_mode&IFMT)!=IFREG) + return; + n = (ip->di_size+BSIZE-1)/BSIZE; + if (n >= TSIZE) { + overflow += n; + n = TSIZE-1; + } + sizes[n]++; + return; + } + if (ip->di_uid >= NUID) + return; + du[ip->di_uid].blocks += (ip->di_size+BSIZE-1)/BSIZE; + du[ip->di_uid].nfiles++; + if (nflg) { + tryagain: + if (fino==0) + if (scanf("%d", &fino)<=0) + return; + if (fino > ino) + return; + if (finodi_uid].name) + printf("%.7s ", np); + else + printf("%d ", ip->di_uid); + while ((n = getchar())==' ' || n=='\t') + ; + putchar(n); + while (n!=EOF && n!='\n') { + n = getchar(); + putchar(n); + } + fino = 0; + } +} + +bread(bno, buf, cnt) +unsigned bno; +char *buf; +{ + + lseek(fi, (long)bno*BSIZE, 0); + if (read(fi, buf, cnt) != cnt) { + printf("read error %u\n", bno); + exit(1); + } +} + +qcmp(p1, p2) +register struct du *p1, *p2; +{ + if (p1->blocks > p2->blocks) + return(-1); + if (p1->blocks < p2->blocks) + return(1); + return(strcmp(p1->name, p2->name)); +} + +report() +{ + register i; + + if (nflg) + return; + if (cflg) { + long t = 0; + for (i=0; i