1: # include <sys/param.h>
2: # include <sys/inode.h>
3: # include <sys/stat.h>
4: # include <sys/qstat.h>
5:
6: struct stat sbuf;
7: struct qstat qsbuf;
8: int start;
9: int fdir;
10: int ldir;
11: daddr_t nused;
12: daddr_t nquot;
13: char dotq[] ".q";
14: char dot[] ".";
15: char dotdot[] "..";
16: char dummy1[] ".1.1.1";
17: char dummy2[] ".2.2.2";
18: char dummy3[] ".3.3.3";
19: extern daddr_t atol();
20:
21: main(argc, argv)
22: char *argv[];
23: {
24: register i, j;
25: int flag;
26:
27: fdir = 1;
28: start = 0;
29: for(i=1; i<argc; i++) {
30: start = 1;
31: if(isdir(argv[i]))
32: continue;
33: ldir = i;
34: if(fdir >= ldir) {
35: printf("no directories specified\n");
36: exit(1);
37: }
38: if(!isnumb(argv[i])) {
39: printf("%s not a directory\n", argv[i]);
40: exit(1);
41: }
42: nused = 0;
43: flag = 1;
44: if(i+1 < argc && isnumb(argv[i+1])) {
45: nused = atol(argv[i]);
46: flag = 0;
47: i++;
48: }
49: nquot = atol(argv[i]);
50: for(j=fdir; j<ldir; j++)
51: setq(argv[j], flag, nused, nquot);
52: fdir = i;
53: start = 0;
54: }
55: if(start) {
56: printf("no quota specified\n");
57: exit(1);
58: }
59: exit(0);
60: }
61:
62: isdir(s)
63: char *s;
64: {
65:
66: if(stat(s, &sbuf) < 0)
67: return(0);
68: if((sbuf.st_mode&S_IFMT)==S_IFDIR)
69: return(1);
70: return(0);
71: }
72:
73: isnumb(s)
74: char *s;
75: {
76: register c;
77:
78: while(c = *s++)
79: if(c < '0' || c > '9')
80: return(0);
81: return(1);
82: }
83:
84: setq(dir, flg, n, m)
85: char *dir;
86: int flg;
87: daddr_t n, m;
88: {
89: register i;
90: int count, f, junk[25];
91:
92: if(i=fork()) {
93: while(wait(junk) != -1)
94: ;
95: return;
96: }
97: if(chdir(dir) < 0) {
98: printf("chdir:");
99: perror(dir);
100: exit(1);
101: }
102: count = 0;
103:
104: loop:
105: if(count > 2) {
106: printf("attempts fail\n");
107: exit(1);
108: }
109: count++;
110: if(qstat(dotq, &qsbuf) >= 0) {
111: if((qsbuf.qs_mode&S_IFMT) != S_IFQUOT) {
112: unlink(dotq);
113: goto loop;
114: }
115: if(flg==1)
116: n=qsbuf.qs_un.qs_qused;
117: if(quota(dotq, fsbtodb(n), fsbtodb(m)) < 0) {
118: printf("quota:");
119: perror(dotq);
120: exit(1);
121: }
122: exit(0);
123: }
124: unlink(dummy1);
125: f = open(dot, 0);
126: if(f < 0) {
127: printf("open:");
128: perror(dir);
129: exit(1);
130: }
131: for(i=0; i<sizeof junk / sizeof (int); i++)
132: junk[i] = 0;
133: read(f, junk, 48);
134: close(f);
135: for(i=0; i<24; i=+8) {
136: if(junk[i] == 0) {
137: if (mknod(dotq, S_IFQUOT, 0) < 0) {
138: perror("mknod:1");
139: exit(1);
140: }
141: goto slot;
142: }
143: if(junk[i+1] == '.')
144: continue;
145: if(junk[i+1] == '..' && junk[i+2] == 0)
146: continue;
147: junk[i+8] = 0;
148: link(junk+i+1, dummy1);
149: unlink(junk+i+1);
150: if (mknod(dotq, S_IFQUOT, 0) < 0) {
151: perror("mknod:2");
152: exit(1);
153: }
154: link(dummy1, junk+i+1);
155: goto slot;
156: }
157: printf("first 3 slots contain . and ..\n");
158: exit(1);
159:
160: slot:
161: i = open(dotdot, 0); /* keep .. referenced during procedure */
162: unlink(dummy1);
163: unlink(dummy2);
164: unlink(dummy3);
165: link(dotq, dummy1);
166: link(dot, dummy2);
167: link(dotdot, dummy3);
168: unlink(dotq);
169: unlink(dot);
170: unlink(dotdot);
171: link(dummy1, dotq);
172: link(dummy2, dot);
173: link(dummy3, dotdot);
174: unlink(dummy1);
175: unlink(dummy2);
176: unlink(dummy3);
177: close(i);
178: goto loop;
179: }
Defined functions
isdir
defined in line
62; used 1 times
main
defined in line
21;
never used
setq
defined in line
84; used 1 times
Defined variables
dot
defined in line
14; used 4 times
dotq
defined in line
13; used 9 times
fdir
defined in line
9; used 4 times
ldir
defined in line
10; used 3 times
nquot
defined in line
12; used 2 times
nused
defined in line
11; used 3 times
qsbuf
defined in line
7; used 3 times
sbuf
defined in line
6; used 2 times
start
defined in line
8; used 4 times