date and time created 83/05/25 15:03:54 by mckusick
[unix-history] / usr / src / usr.sbin / repquota / repquota.c
CommitLineData
fe35ac74
KM
1#ifndef lint
2static char sccsid[] = "@(#)repquota.c 4.1 (Melbourne) %G%";
3#endif
4
5/*
6 * Quota report
7 */
8#include <stdio.h>
9#include <ctype.h>
10#include <pwd.h>
11#include <sys/param.h>
12#define QUOTA
13#include <sys/quota.h>
14
15#define NUID 3000
16
17struct dqblk dq[NUID];
18
19char *dn[NUID];
20int nuids;
21
22main(argc, argv)
23 char **argv;
24{
25 register struct passwd *lp;
26 register n;
27 register i;
28 register FILE *qf;
29 char *copy();
30 struct passwd *getpwent();
31
32 argc--;
33 if ((qf = fopen(*++argv, "r")) == NULL) {
34 fprintf(stderr, "Can't open %s\n", *argv);
35 exit(1);
36 }
37 argc--, argv++;
38 nuids = fread(dq, sizeof(struct dqblk), NUID, qf);
39 fclose(qf);
40 while ((lp = getpwent()) != (struct passwd *)0) {
41 n = lp->pw_uid;
42 if (n >= NUID)
43 continue;
44 if (dn[n])
45 continue;
46 dn[n] = copy(lp->pw_name);
47 }
48
49 for (n = 0; n < nuids; n++) {
50 if (argc > 0) {
51 for (i = 0; i < argc; i++) {
52 register char *p;
53
54 for (p = argv[i]; *p && isdigit(*p); p++)
55 ;
56 if (*p)
57 continue;
58 if (n == atoi(argv[i]))
59 goto rep;
60 }
61 if (!dn[n])
62 continue;
63 for (i = 0; i < argc; i++)
64 if (strcmp(argv[i], dn[n]) == 0)
65 break;
66 if (i >= argc)
67 continue;
68 } else if (dq[n].dqb_curinodes == 0 && dq[n].dqb_curblocks == 0)
69 continue;
70 rep:
71 if (dn[n])
72 printf("%-10s", dn[n]);
73 else
74 printf("#%-9d", n);
75
76 printf("%c%c %5d %5d %5d %5d %5d %5d %5d %5d\n"
77 , dq[n].dqb_bsoftlimit && dq[n].dqb_curblocks >= dq[n].dqb_bsoftlimit
78 ? '+' : '-'
79 , dq[n].dqb_isoftlimit && dq[n].dqb_curinodes >= dq[n].dqb_isoftlimit
80 ? '+' : '-'
81 , dq[n].dqb_curblocks
82 , dq[n].dqb_bsoftlimit
83 , dq[n].dqb_bhardlimit
84 , dq[n].dqb_bwarn
85 , dq[n].dqb_curinodes
86 , dq[n].dqb_isoftlimit
87 , dq[n].dqb_ihardlimit
88 , dq[n].dqb_iwarn
89 );
90 }
91 exit(0);
92}
93
94char *
95copy(s)
96 char *s;
97{
98 register char *p;
99 register n;
100 char *malloc();
101
102 for(n=0; s[n]; n++)
103 ;
104 p = malloc((unsigned)n+1);
105 for(n=0; p[n] = s[n]; n++)
106 ;
107 return(p);
108}