quota.c revision 1.41 1 1.41 dholland /* $NetBSD: quota.c,v 1.41 2011/11/30 16:07:28 dholland Exp $ */
2 1.12 tls
3 1.1 cgd /*
4 1.5 mycroft * Copyright (c) 1980, 1990, 1993
5 1.5 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Robert Elz at The University of Melbourne.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.26 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 cgd * may be used to endorse or promote products derived from this software
20 1.1 cgd * without specific prior written permission.
21 1.1 cgd *
22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 cgd * SUCH DAMAGE.
33 1.1 cgd */
34 1.1 cgd
35 1.16 lukem #include <sys/cdefs.h>
36 1.1 cgd #ifndef lint
37 1.32 lukem __COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\
38 1.32 lukem The Regents of the University of California. All rights reserved.");
39 1.1 cgd #endif /* not lint */
40 1.1 cgd
41 1.1 cgd #ifndef lint
42 1.15 mrg #if 0
43 1.15 mrg static char sccsid[] = "@(#)quota.c 8.4 (Berkeley) 4/28/95";
44 1.15 mrg #else
45 1.41 dholland __RCSID("$NetBSD: quota.c,v 1.41 2011/11/30 16:07:28 dholland Exp $");
46 1.15 mrg #endif
47 1.1 cgd #endif /* not lint */
48 1.1 cgd
49 1.1 cgd /*
50 1.1 cgd * Disk quota reporting program.
51 1.1 cgd */
52 1.1 cgd #include <sys/param.h>
53 1.6 deraadt #include <sys/types.h>
54 1.1 cgd #include <sys/file.h>
55 1.1 cgd #include <sys/stat.h>
56 1.6 deraadt #include <sys/mount.h>
57 1.6 deraadt #include <sys/socket.h>
58 1.15 mrg
59 1.15 mrg #include <ctype.h>
60 1.16 lukem #include <err.h>
61 1.15 mrg #include <errno.h>
62 1.15 mrg #include <fstab.h>
63 1.15 mrg #include <grp.h>
64 1.15 mrg #include <netdb.h>
65 1.15 mrg #include <pwd.h>
66 1.1 cgd #include <stdio.h>
67 1.7 cgd #include <stdlib.h>
68 1.16 lukem #include <string.h>
69 1.18 kleink #include <time.h>
70 1.16 lukem #include <unistd.h>
71 1.1 cgd
72 1.37 bouyer #include <quota/quotaprop.h>
73 1.37 bouyer #include <quota/quota.h>
74 1.6 deraadt
75 1.36 christos #include "printquota.h"
76 1.36 christos #include "getvfsquota.h"
77 1.1 cgd
78 1.1 cgd struct quotause {
79 1.1 cgd struct quotause *next;
80 1.1 cgd long flags;
81 1.37 bouyer uid_t id;
82 1.38 dholland struct quotaval qv[QUOTA_NLIMITS];
83 1.1 cgd char fsname[MAXPATHLEN + 1];
84 1.6 deraadt };
85 1.1 cgd #define FOUND 0x01
86 1.34 bouyer #define QUOTA2 0x02
87 1.1 cgd
88 1.39 dholland static struct quotause *getprivs(id_t, int);
89 1.39 dholland static void heading(int, id_t, const char *, const char *);
90 1.35 christos static void showgid(gid_t);
91 1.35 christos static void showgrpname(const char *);
92 1.41 dholland static void showonequota(int, id_t, const char *, struct quotause *);
93 1.39 dholland static void showquotas(int, id_t, const char *);
94 1.35 christos static void showuid(uid_t);
95 1.35 christos static void showusrname(const char *);
96 1.40 dholland static void usage(void) __dead;
97 1.35 christos
98 1.35 christos static int qflag = 0;
99 1.35 christos static int vflag = 0;
100 1.35 christos static int hflag = 0;
101 1.35 christos static int dflag = 0;
102 1.35 christos static int Dflag = 0;
103 1.35 christos static uid_t myuid;
104 1.41 dholland static int needheading;
105 1.1 cgd
106 1.16 lukem int
107 1.35 christos main(int argc, char *argv[])
108 1.1 cgd {
109 1.3 jtc int ngroups;
110 1.8 mycroft gid_t mygid, gidset[NGROUPS];
111 1.1 cgd int i, gflag = 0, uflag = 0;
112 1.11 mark int ch;
113 1.1 cgd
114 1.19 mrg myuid = getuid();
115 1.34 bouyer while ((ch = getopt(argc, argv, "Ddhugvq")) != -1) {
116 1.1 cgd switch(ch) {
117 1.1 cgd case 'g':
118 1.1 cgd gflag++;
119 1.1 cgd break;
120 1.1 cgd case 'u':
121 1.1 cgd uflag++;
122 1.1 cgd break;
123 1.1 cgd case 'v':
124 1.1 cgd vflag++;
125 1.1 cgd break;
126 1.1 cgd case 'q':
127 1.1 cgd qflag++;
128 1.1 cgd break;
129 1.34 bouyer case 'h':
130 1.34 bouyer hflag++;
131 1.34 bouyer break;
132 1.34 bouyer case 'd':
133 1.34 bouyer dflag++;
134 1.34 bouyer break;
135 1.34 bouyer case 'D':
136 1.34 bouyer Dflag++;
137 1.34 bouyer break;
138 1.1 cgd default:
139 1.1 cgd usage();
140 1.1 cgd }
141 1.1 cgd }
142 1.1 cgd argc -= optind;
143 1.1 cgd argv += optind;
144 1.1 cgd if (!uflag && !gflag)
145 1.1 cgd uflag++;
146 1.34 bouyer if (dflag) {
147 1.34 bouyer #if 0
148 1.35 christos if (myuid != 0)
149 1.35 christos errx(1, "-d: permission denied");
150 1.34 bouyer #endif
151 1.34 bouyer if (uflag)
152 1.37 bouyer showquotas(QUOTA_CLASS_USER, 0, "");
153 1.34 bouyer if (gflag)
154 1.37 bouyer showquotas(QUOTA_CLASS_GROUP, 0, "");
155 1.35 christos return 0;
156 1.34 bouyer }
157 1.1 cgd if (argc == 0) {
158 1.1 cgd if (uflag)
159 1.19 mrg showuid(myuid);
160 1.1 cgd if (gflag) {
161 1.34 bouyer if (dflag)
162 1.34 bouyer showgid(0);
163 1.34 bouyer else {
164 1.34 bouyer mygid = getgid();
165 1.34 bouyer ngroups = getgroups(NGROUPS, gidset);
166 1.34 bouyer if (ngroups < 0)
167 1.34 bouyer err(1, "getgroups");
168 1.34 bouyer showgid(mygid);
169 1.34 bouyer for (i = 0; i < ngroups; i++)
170 1.34 bouyer if (gidset[i] != mygid)
171 1.34 bouyer showgid(gidset[i]);
172 1.34 bouyer }
173 1.1 cgd }
174 1.35 christos return 0;
175 1.1 cgd }
176 1.1 cgd if (uflag && gflag)
177 1.1 cgd usage();
178 1.1 cgd if (uflag) {
179 1.1 cgd for (; argc > 0; argc--, argv++) {
180 1.1 cgd if (alldigits(*argv))
181 1.35 christos showuid((uid_t)atoi(*argv));
182 1.1 cgd else
183 1.1 cgd showusrname(*argv);
184 1.1 cgd }
185 1.35 christos return 0;
186 1.1 cgd }
187 1.1 cgd if (gflag) {
188 1.1 cgd for (; argc > 0; argc--, argv++) {
189 1.1 cgd if (alldigits(*argv))
190 1.35 christos showgid((gid_t)atoi(*argv));
191 1.1 cgd else
192 1.1 cgd showgrpname(*argv);
193 1.1 cgd }
194 1.35 christos return 0;
195 1.1 cgd }
196 1.16 lukem /* NOTREACHED */
197 1.35 christos return 0;
198 1.1 cgd }
199 1.1 cgd
200 1.35 christos static void
201 1.35 christos usage(void)
202 1.1 cgd {
203 1.35 christos const char *p = getprogname();
204 1.35 christos fprintf(stderr, "Usage: %s [-Dhguqv]\n"
205 1.35 christos "\t%s [-Dhqv] -u username ...\n"
206 1.35 christos "\t%s [-Dhqv] -g groupname ...\n"
207 1.35 christos "\t%s -d [-Dhguqv]\n", p, p, p, p);
208 1.1 cgd exit(1);
209 1.1 cgd }
210 1.1 cgd
211 1.1 cgd /*
212 1.1 cgd * Print out quotas for a specified user identifier.
213 1.1 cgd */
214 1.35 christos static void
215 1.35 christos showuid(uid_t uid)
216 1.1 cgd {
217 1.1 cgd struct passwd *pwd = getpwuid(uid);
218 1.20 mycroft const char *name;
219 1.1 cgd
220 1.1 cgd if (pwd == NULL)
221 1.1 cgd name = "(no account)";
222 1.1 cgd else
223 1.1 cgd name = pwd->pw_name;
224 1.1 cgd if (uid != myuid && myuid != 0) {
225 1.35 christos warnx("%s (uid %d): permission denied", name, uid);
226 1.1 cgd return;
227 1.1 cgd }
228 1.37 bouyer showquotas(QUOTA_CLASS_USER, uid, name);
229 1.1 cgd }
230 1.1 cgd
231 1.1 cgd /*
232 1.24 wiz * Print out quotas for a specified user name.
233 1.1 cgd */
234 1.35 christos static void
235 1.35 christos showusrname(const char *name)
236 1.1 cgd {
237 1.1 cgd struct passwd *pwd = getpwnam(name);
238 1.1 cgd
239 1.1 cgd if (pwd == NULL) {
240 1.16 lukem warnx("%s: unknown user", name);
241 1.1 cgd return;
242 1.1 cgd }
243 1.1 cgd if (pwd->pw_uid != myuid && myuid != 0) {
244 1.16 lukem warnx("%s (uid %d): permission denied", name, pwd->pw_uid);
245 1.1 cgd return;
246 1.1 cgd }
247 1.37 bouyer showquotas(QUOTA_CLASS_USER, pwd->pw_uid, name);
248 1.1 cgd }
249 1.1 cgd
250 1.1 cgd /*
251 1.1 cgd * Print out quotas for a specified group identifier.
252 1.1 cgd */
253 1.35 christos static void
254 1.35 christos showgid(gid_t gid)
255 1.1 cgd {
256 1.1 cgd struct group *grp = getgrgid(gid);
257 1.3 jtc int ngroups;
258 1.8 mycroft gid_t mygid, gidset[NGROUPS];
259 1.16 lukem int i;
260 1.20 mycroft const char *name;
261 1.1 cgd
262 1.1 cgd if (grp == NULL)
263 1.1 cgd name = "(no entry)";
264 1.1 cgd else
265 1.1 cgd name = grp->gr_name;
266 1.8 mycroft mygid = getgid();
267 1.1 cgd ngroups = getgroups(NGROUPS, gidset);
268 1.1 cgd if (ngroups < 0) {
269 1.16 lukem warn("getgroups");
270 1.1 cgd return;
271 1.1 cgd }
272 1.8 mycroft if (gid != mygid) {
273 1.8 mycroft for (i = 0; i < ngroups; i++)
274 1.8 mycroft if (gid == gidset[i])
275 1.8 mycroft break;
276 1.19 mrg if (i >= ngroups && myuid != 0) {
277 1.16 lukem warnx("%s (gid %d): permission denied", name, gid);
278 1.8 mycroft return;
279 1.8 mycroft }
280 1.1 cgd }
281 1.37 bouyer showquotas(QUOTA_CLASS_GROUP, gid, name);
282 1.1 cgd }
283 1.1 cgd
284 1.1 cgd /*
285 1.24 wiz * Print out quotas for a specified group name.
286 1.1 cgd */
287 1.35 christos static void
288 1.35 christos showgrpname(const char *name)
289 1.1 cgd {
290 1.1 cgd struct group *grp = getgrnam(name);
291 1.3 jtc int ngroups;
292 1.8 mycroft gid_t mygid, gidset[NGROUPS];
293 1.16 lukem int i;
294 1.1 cgd
295 1.1 cgd if (grp == NULL) {
296 1.16 lukem warnx("%s: unknown group", name);
297 1.1 cgd return;
298 1.1 cgd }
299 1.8 mycroft mygid = getgid();
300 1.1 cgd ngroups = getgroups(NGROUPS, gidset);
301 1.1 cgd if (ngroups < 0) {
302 1.16 lukem warn("getgroups");
303 1.1 cgd return;
304 1.1 cgd }
305 1.8 mycroft if (grp->gr_gid != mygid) {
306 1.8 mycroft for (i = 0; i < ngroups; i++)
307 1.8 mycroft if (grp->gr_gid == gidset[i])
308 1.8 mycroft break;
309 1.19 mrg if (i >= ngroups && myuid != 0) {
310 1.16 lukem warnx("%s (gid %d): permission denied",
311 1.8 mycroft name, grp->gr_gid);
312 1.8 mycroft return;
313 1.8 mycroft }
314 1.1 cgd }
315 1.37 bouyer showquotas(QUOTA_CLASS_GROUP, grp->gr_gid, name);
316 1.1 cgd }
317 1.1 cgd
318 1.35 christos static void
319 1.39 dholland showquotas(int type, id_t id, const char *name)
320 1.1 cgd {
321 1.16 lukem struct quotause *qup;
322 1.6 deraadt struct quotause *quplist;
323 1.41 dholland
324 1.41 dholland needheading = 1;
325 1.41 dholland
326 1.41 dholland quplist = getprivs(id, type);
327 1.41 dholland for (qup = quplist; qup; qup = qup->next) {
328 1.41 dholland showonequota(type, id, name, qup);
329 1.41 dholland }
330 1.41 dholland if (!qflag) {
331 1.41 dholland /* In case nothing printed, issue a header saying "none" */
332 1.41 dholland heading(type, id, name, "none");
333 1.41 dholland }
334 1.41 dholland }
335 1.41 dholland
336 1.41 dholland static void
337 1.41 dholland showonequota(int type, id_t id, const char *name, struct quotause *qup)
338 1.41 dholland {
339 1.41 dholland char b0[20], b1[20], b2[20], b3[20];
340 1.34 bouyer const char *msgi, *msgb, *nam, *timemsg;
341 1.41 dholland int ql_stat;
342 1.41 dholland struct quotaval *q = qup->qv;
343 1.1 cgd static time_t now;
344 1.1 cgd
345 1.41 dholland if (now == 0) {
346 1.1 cgd time(&now);
347 1.41 dholland }
348 1.41 dholland
349 1.41 dholland if (!vflag &&
350 1.41 dholland q[QUOTA_LIMIT_BLOCK].qv_softlimit == UQUAD_MAX &&
351 1.41 dholland q[QUOTA_LIMIT_BLOCK].qv_hardlimit == UQUAD_MAX &&
352 1.41 dholland q[QUOTA_LIMIT_FILE].qv_softlimit == UQUAD_MAX &&
353 1.41 dholland q[QUOTA_LIMIT_FILE].qv_hardlimit == UQUAD_MAX)
354 1.41 dholland return;
355 1.41 dholland ql_stat = quota_check_limit(q[QUOTA_LIMIT_FILE].qv_usage, 1,
356 1.41 dholland q[QUOTA_LIMIT_FILE].qv_softlimit,
357 1.41 dholland q[QUOTA_LIMIT_FILE].qv_hardlimit,
358 1.41 dholland q[QUOTA_LIMIT_FILE].qv_expiretime, now);
359 1.41 dholland switch(QL_STATUS(ql_stat)) {
360 1.41 dholland case QL_S_DENY_HARD:
361 1.41 dholland msgi = "File limit reached on";
362 1.41 dholland break;
363 1.41 dholland case QL_S_DENY_GRACE:
364 1.41 dholland msgi = "Over file quota on";
365 1.41 dholland break;
366 1.41 dholland case QL_S_ALLOW_SOFT:
367 1.41 dholland msgi = "In file grace period on";
368 1.41 dholland break;
369 1.41 dholland default:
370 1.41 dholland msgi = NULL;
371 1.41 dholland }
372 1.41 dholland ql_stat = quota_check_limit(q[QUOTA_LIMIT_BLOCK].qv_usage, 1,
373 1.41 dholland q[QUOTA_LIMIT_BLOCK].qv_softlimit,
374 1.41 dholland q[QUOTA_LIMIT_BLOCK].qv_hardlimit,
375 1.41 dholland q[QUOTA_LIMIT_BLOCK].qv_expiretime, now);
376 1.41 dholland switch(QL_STATUS(ql_stat)) {
377 1.41 dholland case QL_S_DENY_HARD:
378 1.41 dholland msgb = "Block limit reached on";
379 1.41 dholland break;
380 1.41 dholland case QL_S_DENY_GRACE:
381 1.41 dholland msgb = "Over block quota on";
382 1.41 dholland break;
383 1.41 dholland case QL_S_ALLOW_SOFT:
384 1.41 dholland msgb = "In block grace period on";
385 1.41 dholland break;
386 1.41 dholland default:
387 1.41 dholland msgb = NULL;
388 1.41 dholland }
389 1.41 dholland if (qflag) {
390 1.41 dholland if (msgi != NULL) {
391 1.41 dholland heading(type, id, name, "");
392 1.41 dholland printf("\t%s %s\n", msgi, qup->fsname);
393 1.41 dholland }
394 1.41 dholland if (msgb != NULL) {
395 1.41 dholland heading(type, id, name, "");
396 1.41 dholland printf("\t%s %s\n", msgb, qup->fsname);
397 1.21 ross }
398 1.41 dholland return;
399 1.41 dholland }
400 1.41 dholland if (vflag || dflag || msgi || msgb ||
401 1.41 dholland q[QUOTA_LIMIT_BLOCK].qv_usage ||
402 1.41 dholland q[QUOTA_LIMIT_FILE].qv_usage) {
403 1.41 dholland heading(type, id, name, "");
404 1.41 dholland nam = qup->fsname;
405 1.41 dholland if (strlen(qup->fsname) > 4) {
406 1.41 dholland printf("%s\n", qup->fsname);
407 1.41 dholland nam = "";
408 1.41 dholland }
409 1.41 dholland if (msgb)
410 1.41 dholland timemsg = timeprt(b0, 9, now,
411 1.41 dholland q[QUOTA_LIMIT_BLOCK].qv_expiretime);
412 1.41 dholland else if ((qup->flags & QUOTA2) != 0 && vflag)
413 1.41 dholland timemsg = timeprt(b0, 9, 0,
414 1.41 dholland q[QUOTA_LIMIT_BLOCK].qv_grace);
415 1.41 dholland else
416 1.41 dholland timemsg = "";
417 1.34 bouyer
418 1.41 dholland printf("%12s%9s%c%8s%9s%8s",
419 1.41 dholland nam,
420 1.41 dholland intprt(b1, 9, q[QUOTA_LIMIT_BLOCK].qv_usage,
421 1.41 dholland HN_B, hflag),
422 1.41 dholland (msgb == NULL) ? ' ' : '*',
423 1.41 dholland intprt(b2, 9, q[QUOTA_LIMIT_BLOCK].qv_softlimit,
424 1.41 dholland HN_B, hflag),
425 1.41 dholland intprt(b3, 9, q[QUOTA_LIMIT_BLOCK].qv_hardlimit,
426 1.41 dholland HN_B, hflag),
427 1.41 dholland timemsg);
428 1.41 dholland
429 1.41 dholland if (msgi)
430 1.41 dholland timemsg = timeprt(b0, 9, now,
431 1.41 dholland q[QUOTA_LIMIT_FILE].qv_expiretime);
432 1.41 dholland else if ((qup->flags & QUOTA2) != 0 && vflag)
433 1.41 dholland timemsg = timeprt(b0, 9, 0,
434 1.41 dholland q[QUOTA_LIMIT_FILE].qv_grace);
435 1.41 dholland else
436 1.41 dholland timemsg = "";
437 1.34 bouyer
438 1.41 dholland printf("%8s%c%7s%8s%8s\n",
439 1.41 dholland intprt(b1, 8, q[QUOTA_LIMIT_FILE].qv_usage, 0,
440 1.41 dholland hflag),
441 1.41 dholland (msgi == NULL) ? ' ' : '*',
442 1.41 dholland intprt(b2, 8, q[QUOTA_LIMIT_FILE].qv_softlimit,
443 1.41 dholland 0, hflag),
444 1.41 dholland intprt(b3, 8, q[QUOTA_LIMIT_FILE].qv_hardlimit,
445 1.41 dholland 0, hflag),
446 1.41 dholland timemsg);
447 1.41 dholland return;
448 1.1 cgd }
449 1.1 cgd }
450 1.1 cgd
451 1.35 christos static void
452 1.39 dholland heading(int type, id_t id, const char *name, const char *tag)
453 1.1 cgd {
454 1.41 dholland if (needheading == 0)
455 1.41 dholland return;
456 1.41 dholland needheading = 0;
457 1.41 dholland
458 1.34 bouyer if (dflag)
459 1.34 bouyer printf("Default %s disk quotas: %s\n",
460 1.37 bouyer ufs_quota_class_names[type], tag);
461 1.34 bouyer else
462 1.35 christos printf("Disk quotas for %s %s (%cid %u): %s\n",
463 1.37 bouyer ufs_quota_class_names[type], name,
464 1.37 bouyer *ufs_quota_class_names[type], id, tag);
465 1.1 cgd
466 1.1 cgd if (!qflag && tag[0] == '\0') {
467 1.22 bouyer printf("%12s%9s %8s%9s%8s%8s %7s%8s%8s\n"
468 1.22 bouyer , "Filesystem"
469 1.22 bouyer , "blocks"
470 1.22 bouyer , "quota"
471 1.22 bouyer , "limit"
472 1.22 bouyer , "grace"
473 1.22 bouyer , "files"
474 1.22 bouyer , "quota"
475 1.22 bouyer , "limit"
476 1.22 bouyer , "grace"
477 1.1 cgd );
478 1.1 cgd }
479 1.1 cgd }
480 1.1 cgd
481 1.1 cgd /*
482 1.1 cgd * Collect the requested quota information.
483 1.1 cgd */
484 1.35 christos static struct quotause *
485 1.39 dholland getprivs(id_t id, int quotatype)
486 1.1 cgd {
487 1.16 lukem struct quotause *qup, *quptail;
488 1.1 cgd struct quotause *quphead;
489 1.29 christos struct statvfs *fst;
490 1.6 deraadt int nfst, i;
491 1.34 bouyer int8_t version;
492 1.6 deraadt
493 1.16 lukem qup = quphead = quptail = NULL;
494 1.1 cgd
495 1.6 deraadt nfst = getmntinfo(&fst, MNT_WAIT);
496 1.16 lukem if (nfst == 0)
497 1.16 lukem errx(2, "no filesystems mounted!");
498 1.19 mrg for (i = 0; i < nfst; i++) {
499 1.6 deraadt if (qup == NULL) {
500 1.35 christos if ((qup = malloc(sizeof *qup)) == NULL)
501 1.35 christos err(1, "out of memory");
502 1.1 cgd }
503 1.31 christos if (strncmp(fst[i].f_fstypename, "nfs",
504 1.31 christos sizeof(fst[i].f_fstypename)) == 0) {
505 1.34 bouyer version = 0;
506 1.37 bouyer if (getnfsquota(fst[i].f_mntfromname,
507 1.38 dholland qup->qv, id, ufs_quota_class_names[quotatype]) != 1)
508 1.6 deraadt continue;
509 1.34 bouyer } else if ((fst[i].f_flag & ST_QUOTA) != 0) {
510 1.38 dholland if (getvfsquota(fst[i].f_mntonname, qup->qv, &version,
511 1.37 bouyer id, quotatype, dflag, Dflag) != 1)
512 1.1 cgd continue;
513 1.6 deraadt } else
514 1.6 deraadt continue;
515 1.13 mrg (void)strncpy(qup->fsname, fst[i].f_mntonname,
516 1.13 mrg sizeof(qup->fsname) - 1);
517 1.34 bouyer if (version == 2)
518 1.34 bouyer qup->flags |= QUOTA2;
519 1.1 cgd if (quphead == NULL)
520 1.1 cgd quphead = qup;
521 1.1 cgd else
522 1.1 cgd quptail->next = qup;
523 1.1 cgd quptail = qup;
524 1.6 deraadt quptail->next = 0;
525 1.6 deraadt qup = NULL;
526 1.1 cgd }
527 1.35 christos free(qup);
528 1.35 christos return quphead;
529 1.1 cgd }
530