Deleted Added
full compact
quota.c (194494) quota.c (207736)
1/*
2 * Copyright (c) 1980, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Robert Elz at The University of Melbourne.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 34 unchanged lines hidden (view full) ---

43#ifndef lint
44static const char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93";
45#endif /* not lint */
46
47/*
48 * Disk quota reporting program.
49 */
50#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1980, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Robert Elz at The University of Melbourne.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 34 unchanged lines hidden (view full) ---

43#ifndef lint
44static const char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93";
45#endif /* not lint */
46
47/*
48 * Disk quota reporting program.
49 */
50#include <sys/cdefs.h>
51__FBSDID("$FreeBSD: head/usr.bin/quota/quota.c 194494 2009-06-19 15:58:24Z brooks $");
51__FBSDID("$FreeBSD: head/usr.bin/quota/quota.c 207736 2010-05-07 00:41:12Z mckusick $");
52
53#include <sys/param.h>
54#include <sys/types.h>
55#include <sys/file.h>
56#include <sys/stat.h>
57#include <sys/mount.h>
58#include <sys/socket.h>
59

--- 22 unchanged lines hidden (view full) ---

82
83struct quotause {
84 struct quotause *next;
85 long flags;
86 struct dqblk dqblk;
87 char fsname[MAXPATHLEN + 1];
88};
89
52
53#include <sys/param.h>
54#include <sys/types.h>
55#include <sys/file.h>
56#include <sys/stat.h>
57#include <sys/mount.h>
58#include <sys/socket.h>
59

--- 22 unchanged lines hidden (view full) ---

82
83struct quotause {
84 struct quotause *next;
85 long flags;
86 struct dqblk dqblk;
87 char fsname[MAXPATHLEN + 1];
88};
89
90static char *timeprt(time_t seconds);
90static char *timeprt(int64_t seconds);
91static struct quotause *getprivs(long id, int quotatype);
92static void usage(void);
93static int showuid(u_long uid);
94static int showgid(u_long gid);
95static int showusrname(char *name);
96static int showgrpname(char *name);
97static int showquotas(int type, u_long id, const char *name);
98static void showrawquotas(int type, u_long id, struct quotause *qup);
99static void heading(int type, u_long id, const char *name, const char *tag);
91static struct quotause *getprivs(long id, int quotatype);
92static void usage(void);
93static int showuid(u_long uid);
94static int showgid(u_long gid);
95static int showusrname(char *name);
96static int showgrpname(char *name);
97static int showquotas(int type, u_long id, const char *name);
98static void showrawquotas(int type, u_long id, struct quotause *qup);
99static void heading(int type, u_long id, const char *name, const char *tag);
100static int ufshasquota(struct fstab *fs, int type, char **qfnamep);
101static int getufsquota(struct fstab *fs, struct quotause *qup, long id,
102 int quotatype);
103static int getnfsquota(struct statfs *fst, struct quotause *qup, long id,
104 int quotatype);
105static int callaurpc(char *host, int prognum, int versnum, int procnum,
106 xdrproc_t inproc, char *in, xdrproc_t outproc, char *out);
107static int alldigits(char *s);
108
109int hflag;
110int lflag;
111int rflag;
112int qflag;
113int vflag;
114char *filename = NULL;
115
116int
117main(int argc, char *argv[])
118{
119 int ngroups;
100static int getufsquota(struct fstab *fs, struct quotause *qup, long id,
101 int quotatype);
102static int getnfsquota(struct statfs *fst, struct quotause *qup, long id,
103 int quotatype);
104static int callaurpc(char *host, int prognum, int versnum, int procnum,
105 xdrproc_t inproc, char *in, xdrproc_t outproc, char *out);
106static int alldigits(char *s);
107
108int hflag;
109int lflag;
110int rflag;
111int qflag;
112int vflag;
113char *filename = NULL;
114
115int
116main(int argc, char *argv[])
117{
118 int ngroups;
120 long ngroups_max;
121 gid_t mygid, *gidset;
119 gid_t mygid, gidset[NGROUPS];
122 int i, ch, gflag = 0, uflag = 0, errflag = 0;
123
124 while ((ch = getopt(argc, argv, "f:ghlrquv")) != -1) {
125 switch(ch) {
126 case 'f':
127 filename = optarg;
128 break;
129 case 'g':

--- 25 unchanged lines hidden (view full) ---

155 argv += optind;
156 if (!uflag && !gflag)
157 uflag++;
158 if (argc == 0) {
159 if (uflag)
160 errflag += showuid(getuid());
161 if (gflag) {
162 mygid = getgid();
120 int i, ch, gflag = 0, uflag = 0, errflag = 0;
121
122 while ((ch = getopt(argc, argv, "f:ghlrquv")) != -1) {
123 switch(ch) {
124 case 'f':
125 filename = optarg;
126 break;
127 case 'g':

--- 25 unchanged lines hidden (view full) ---

153 argv += optind;
154 if (!uflag && !gflag)
155 uflag++;
156 if (argc == 0) {
157 if (uflag)
158 errflag += showuid(getuid());
159 if (gflag) {
160 mygid = getgid();
163 ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1;
164 if ((gidset = malloc(sizeof(gid_t) * ngroups_max))
165 == NULL)
166 err(1, "malloc");
167 ngroups = getgroups(ngroups_max, gidset);
161 ngroups = getgroups(NGROUPS, gidset);
168 if (ngroups < 0)
169 err(1, "getgroups");
170 errflag += showgid(mygid);
171 for (i = 0; i < ngroups; i++)
172 if (gidset[i] != mygid)
173 errflag += showgid(gidset[i]);
162 if (ngroups < 0)
163 err(1, "getgroups");
164 errflag += showgid(mygid);
165 for (i = 0; i < ngroups; i++)
166 if (gidset[i] != mygid)
167 errflag += showgid(gidset[i]);
174 free(gidset);
175 }
176 return(errflag);
177 }
178 if (uflag && gflag)
179 usage();
180 if (uflag) {
181 for (; argc > 0; argc--, argv++) {
182 if (alldigits(*argv))

--- 83 unchanged lines hidden (view full) ---

266 if (grp == NULL) {
267 warnx("%s: unknown group", name);
268 return(1);
269 }
270 return(showquotas(GRPQUOTA, grp->gr_gid, name));
271}
272
273static void
168 }
169 return(errflag);
170 }
171 if (uflag && gflag)
172 usage();
173 if (uflag) {
174 for (; argc > 0; argc--, argv++) {
175 if (alldigits(*argv))

--- 83 unchanged lines hidden (view full) ---

259 if (grp == NULL) {
260 warnx("%s: unknown group", name);
261 return(1);
262 }
263 return(showquotas(GRPQUOTA, grp->gr_gid, name));
264}
265
266static void
274prthumanval(int len, int64_t bytes)
267prthumanval(int len, u_int64_t bytes)
275{
276 char buf[len + 1];
277
278 humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
279 HN_B | HN_NOSPACE | HN_DECIMAL);
280
281 (void)printf(" %*s", len, buf);
282}

--- 8 unchanged lines hidden (view full) ---

291 char *bgrace = NULL, *igrace = NULL;
292 int lines = 0, overquota = 0;
293 static time_t now;
294
295 if (now == 0)
296 time(&now);
297 quplist = getprivs(id, type);
298 for (qup = quplist; qup; qup = qup->next) {
268{
269 char buf[len + 1];
270
271 humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
272 HN_B | HN_NOSPACE | HN_DECIMAL);
273
274 (void)printf(" %*s", len, buf);
275}

--- 8 unchanged lines hidden (view full) ---

284 char *bgrace = NULL, *igrace = NULL;
285 int lines = 0, overquota = 0;
286 static time_t now;
287
288 if (now == 0)
289 time(&now);
290 quplist = getprivs(id, type);
291 for (qup = quplist; qup; qup = qup->next) {
299 msgi = (char *)0;
292 msgi = NULL;
300 if (qup->dqblk.dqb_ihardlimit &&
301 qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_ihardlimit) {
302 overquota++;
303 msgi = "File limit reached on";
304 }
305 else if (qup->dqblk.dqb_isoftlimit &&
306 qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit) {
307 overquota++;
308 if (qup->dqblk.dqb_itime > now)
309 msgi = "In file grace period on";
310 else
311 msgi = "Over file quota on";
312 }
293 if (qup->dqblk.dqb_ihardlimit &&
294 qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_ihardlimit) {
295 overquota++;
296 msgi = "File limit reached on";
297 }
298 else if (qup->dqblk.dqb_isoftlimit &&
299 qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit) {
300 overquota++;
301 if (qup->dqblk.dqb_itime > now)
302 msgi = "In file grace period on";
303 else
304 msgi = "Over file quota on";
305 }
313 msgb = (char *)0;
306 msgb = NULL;
314 if (qup->dqblk.dqb_bhardlimit &&
315 qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bhardlimit) {
316 overquota++;
317 msgb = "Block limit reached on";
318 }
319 else if (qup->dqblk.dqb_bsoftlimit &&
320 qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit) {
321 overquota++;

--- 8 unchanged lines hidden (view full) ---

330 }
331 if (!vflag &&
332 qup->dqblk.dqb_isoftlimit == 0 &&
333 qup->dqblk.dqb_ihardlimit == 0 &&
334 qup->dqblk.dqb_bsoftlimit == 0 &&
335 qup->dqblk.dqb_bhardlimit == 0)
336 continue;
337 if (qflag) {
307 if (qup->dqblk.dqb_bhardlimit &&
308 qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bhardlimit) {
309 overquota++;
310 msgb = "Block limit reached on";
311 }
312 else if (qup->dqblk.dqb_bsoftlimit &&
313 qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit) {
314 overquota++;

--- 8 unchanged lines hidden (view full) ---

323 }
324 if (!vflag &&
325 qup->dqblk.dqb_isoftlimit == 0 &&
326 qup->dqblk.dqb_ihardlimit == 0 &&
327 qup->dqblk.dqb_bsoftlimit == 0 &&
328 qup->dqblk.dqb_bhardlimit == 0)
329 continue;
330 if (qflag) {
338 if ((msgi != (char *)0 || msgb != (char *)0) &&
331 if ((msgi != NULL || msgb != NULL) &&
339 lines++ == 0)
340 heading(type, id, name, "");
332 lines++ == 0)
333 heading(type, id, name, "");
341 if (msgi != (char *)0)
334 if (msgi != NULL)
342 printf("\t%s %s\n", msgi, qup->fsname);
335 printf("\t%s %s\n", msgi, qup->fsname);
343 if (msgb != (char *)0)
336 if (msgb != NULL)
344 printf("\t%s %s\n", msgb, qup->fsname);
345 continue;
346 }
337 printf("\t%s %s\n", msgb, qup->fsname);
338 continue;
339 }
347 if (vflag ||
348 qup->dqblk.dqb_curblocks ||
349 qup->dqblk.dqb_curinodes) {
350 if (lines++ == 0)
351 heading(type, id, name, "");
352 nam = qup->fsname;
353 if (strlen(qup->fsname) > 15) {
354 printf("%s\n", qup->fsname);
355 nam = "";
356 }
357 printf("%15s", nam);
358 if (hflag) {
359 printf(" ");
360 prthumanval(4, dbtob(qup->dqblk.dqb_curblocks));
361 printf("%c ", (msgb == (char *)0) ? ' ' : '*');
362 prthumanval(4, dbtob(qup->dqblk.dqb_bsoftlimit));
363 printf(" ");
364 prthumanval(4, dbtob(qup->dqblk.dqb_bhardlimit));
365 } else {
366 printf(" %7ju%c %6ju %7ju",
367 (uintmax_t)(dbtob(qup->dqblk.dqb_curblocks)
368 / 1024),
369 (msgb == NULL) ? ' ' : '*',
370 (uintmax_t)(dbtob(qup->dqblk.dqb_bsoftlimit)
371 / 1024),
372 (uintmax_t)(dbtob(qup->dqblk.dqb_bhardlimit)
373 / 1024));
374 }
375 if (msgb != NULL)
376 bgrace = timeprt(qup->dqblk.dqb_btime);
377 if (msgi != NULL)
378 igrace = timeprt(qup->dqblk.dqb_itime);
379 printf(" %7s %7ju%c %6ju %7ju %7s\n",
380 (msgb == NULL) ? "" : bgrace,
381 (uintmax_t)qup->dqblk.dqb_curinodes,
382 (msgi == NULL) ? ' ' : '*',
383 (uintmax_t)qup->dqblk.dqb_isoftlimit,
384 (uintmax_t)qup->dqblk.dqb_ihardlimit,
385 (msgi == NULL) ? "" : igrace
386 );
387 if (msgb != NULL)
388 free(bgrace);
389 if (msgi != NULL)
390 free(igrace);
340 if (!vflag &&
341 qup->dqblk.dqb_curblocks == 0 &&
342 qup->dqblk.dqb_curinodes == 0)
391 continue;
343 continue;
344 if (lines++ == 0)
345 heading(type, id, name, "");
346 nam = qup->fsname;
347 if (strlen(qup->fsname) > 15) {
348 printf("%s\n", qup->fsname);
349 nam = "";
350 }
351 printf("%-15s", nam);
352 if (hflag) {
353 prthumanval(7, dbtob(qup->dqblk.dqb_curblocks));
354 printf("%c", (msgb == NULL) ? ' ' : '*');
355 prthumanval(7, dbtob(qup->dqblk.dqb_bsoftlimit));
356 prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit));
357 } else {
358 printf(" %7ju%c %7ju %7ju",
359 dbtob(1024) * (uintmax_t)qup->dqblk.dqb_curblocks,
360 (msgb == NULL) ? ' ' : '*',
361 dbtob(1024) * (uintmax_t)qup->dqblk.dqb_bsoftlimit,
362 dbtob(1024) * (uintmax_t)qup->dqblk.dqb_bhardlimit);
392 }
363 }
364 if (msgb != NULL)
365 bgrace = timeprt(qup->dqblk.dqb_btime);
366 if (msgi != NULL)
367 igrace = timeprt(qup->dqblk.dqb_itime);
368 printf("%8s %6ju%c %6ju %6ju%8s\n"
369 , (msgb == NULL) ? "" : bgrace
370 , (uintmax_t)qup->dqblk.dqb_curinodes
371 , (msgi == NULL) ? ' ' : '*'
372 , (uintmax_t)qup->dqblk.dqb_isoftlimit
373 , (uintmax_t)qup->dqblk.dqb_ihardlimit
374 , (msgi == NULL) ? "" : igrace
375 );
376 if (msgb != NULL)
377 free(bgrace);
378 if (msgi != NULL)
379 free(igrace);
393 }
394 if (!qflag && !rflag && lines == 0)
395 heading(type, id, name, "none");
380 }
381 if (!qflag && !rflag && lines == 0)
382 heading(type, id, name, "none");
396 return(overquota);
383 return (overquota);
397}
398
399static void
400showrawquotas(int type, u_long id, struct quotause *qup)
401{
384}
385
386static void
387showrawquotas(int type, u_long id, struct quotause *qup)
388{
402 time_t tt;
389 time_t t;
390
403 printf("Raw %s quota information for id %lu on %s\n",
404 type == USRQUOTA ? "user" : "group", id, qup->fsname);
391 printf("Raw %s quota information for id %lu on %s\n",
392 type == USRQUOTA ? "user" : "group", id, qup->fsname);
405 printf("block hard limit: %ju\n", (uintmax_t)qup->dqblk.dqb_bhardlimit);
406 printf("block soft limit: %ju\n", (uintmax_t)qup->dqblk.dqb_bsoftlimit);
407 printf("current block count: %ju\n", (uintmax_t)qup->dqblk.dqb_curblocks);
408 printf("i-node hard limit: %ju\n", (uintmax_t)qup->dqblk.dqb_ihardlimit);
409 printf("i-node soft limit: %ju\n", (uintmax_t)qup->dqblk.dqb_isoftlimit);
410 printf("current i-node count: %ju\n", (uintmax_t)qup->dqblk.dqb_curinodes);
411 printf("block grace time: %jd", (intmax_t)qup->dqblk.dqb_btime);
393 printf("block hard limit: %ju\n",
394 (uintmax_t)qup->dqblk.dqb_bhardlimit);
395 printf("block soft limit: %ju\n",
396 (uintmax_t)qup->dqblk.dqb_bsoftlimit);
397 printf("current block count: %ju\n",
398 (uintmax_t)qup->dqblk.dqb_curblocks);
399 printf("i-node hard limit: %ju\n",
400 (uintmax_t)qup->dqblk.dqb_ihardlimit);
401 printf("i-node soft limit: %ju\n",
402 (uintmax_t)qup->dqblk.dqb_isoftlimit);
403 printf("current i-node count: %ju\n",
404 (uintmax_t)qup->dqblk.dqb_curinodes);
405 printf("block grace time: %jd",
406 (intmax_t)qup->dqblk.dqb_btime);
412 if (qup->dqblk.dqb_btime != 0) {
407 if (qup->dqblk.dqb_btime != 0) {
413 tt = qup->dqblk.dqb_btime;
414 printf(" %s", ctime(&tt));
415 } else
408 t = qup->dqblk.dqb_btime;
409 printf(" %s", ctime(&t));
410 } else {
416 printf("\n");
411 printf("\n");
412 }
417 printf("i-node grace time: %jd", (intmax_t)qup->dqblk.dqb_itime);
418 if (qup->dqblk.dqb_itime != 0) {
413 printf("i-node grace time: %jd", (intmax_t)qup->dqblk.dqb_itime);
414 if (qup->dqblk.dqb_itime != 0) {
419 tt = qup->dqblk.dqb_itime;
420 printf(" %s", ctime(&tt));
421 } else
415 t = qup->dqblk.dqb_itime;
416 printf(" %s", ctime(&t));
417 } else {
422 printf("\n");
418 printf("\n");
419 }
423}
424
425
426static void
427heading(int type, u_long id, const char *name, const char *tag)
428{
429
430 printf("Disk quotas for %s %s (%cid %lu): %s\n", qfextension[type],
431 name, *qfextension[type], id, tag);
432 if (!qflag && tag[0] == '\0') {
420}
421
422
423static void
424heading(int type, u_long id, const char *name, const char *tag)
425{
426
427 printf("Disk quotas for %s %s (%cid %lu): %s\n", qfextension[type],
428 name, *qfextension[type], id, tag);
429 if (!qflag && tag[0] == '\0') {
433 printf("%15s %7s %6s %7s %7s %7s %6s %7s %7s\n"
430 printf("%-15s %7s %8s %7s %7s %6s %7s %6s%8s\n"
434 , "Filesystem"
435 , "usage"
436 , "quota"
437 , "limit"
438 , "grace"
439 , "files"
440 , "quota"
441 , "limit"
442 , "grace"
443 );
444 }
445}
446
447/*
448 * Calculate the grace period and return a printable string for it.
449 */
450static char *
431 , "Filesystem"
432 , "usage"
433 , "quota"
434 , "limit"
435 , "grace"
436 , "files"
437 , "quota"
438 , "limit"
439 , "grace"
440 );
441 }
442}
443
444/*
445 * Calculate the grace period and return a printable string for it.
446 */
447static char *
451timeprt(time_t seconds)
448timeprt(int64_t seconds)
452{
453 time_t hours, minutes;
449{
450 time_t hours, minutes;
454 char *buf;
451 char *buf;
455 static time_t now;
456
457 if (now == 0)
458 time(&now);
459 if (now > seconds) {
452 static time_t now;
453
454 if (now == 0)
455 time(&now);
456 if (now > seconds) {
460 return strdup("none");
457 if ((buf = strdup("none")) == NULL)
458 errx(1, "strdup() failed in timeprt()");
459 return (buf);
461 }
462 seconds -= now;
463 minutes = (seconds + 30) / 60;
464 hours = (minutes + 30) / 60;
465 if (hours >= 36) {
466 if (asprintf(&buf, "%lddays", ((long)hours + 12) / 24) < 0)
460 }
461 seconds -= now;
462 minutes = (seconds + 30) / 60;
463 hours = (minutes + 30) / 60;
464 if (hours >= 36) {
465 if (asprintf(&buf, "%lddays", ((long)hours + 12) / 24) < 0)
467 errx(1, "asprintf failed in timeprt(1)");
466 errx(1, "asprintf() failed in timeprt(1)");
468 return (buf);
469 }
470 if (minutes >= 60) {
471 if (asprintf(&buf, "%2ld:%ld", (long)minutes / 60,
472 (long)minutes % 60) < 0)
467 return (buf);
468 }
469 if (minutes >= 60) {
470 if (asprintf(&buf, "%2ld:%ld", (long)minutes / 60,
471 (long)minutes % 60) < 0)
473 errx(1, "asprintf failed in timeprt(2)");
472 errx(1, "asprintf() failed in timeprt(2)");
474 return (buf);
475 }
476 if (asprintf(&buf, "%2ld", (long)minutes) < 0)
473 return (buf);
474 }
475 if (asprintf(&buf, "%2ld", (long)minutes) < 0)
477 errx(1, "asprintf failed in timeprt(3)");
476 errx(1, "asprintf() failed in timeprt(3)");
478 return (buf);
479}
480
481/*
482 * Collect the requested quota information.
483 */
484static struct quotause *
485getprivs(long id, int quotatype)

--- 8 unchanged lines hidden (view full) ---

494 qup = quphead = (struct quotause *)0;
495
496 if (filename != NULL && statfs(filename, &sfb) != 0)
497 err(1, "cannot statfs %s", filename);
498 nfst = getmntinfo(&fst, MNT_NOWAIT);
499 if (nfst == 0)
500 errx(2, "no filesystems mounted!");
501 setfsent();
477 return (buf);
478}
479
480/*
481 * Collect the requested quota information.
482 */
483static struct quotause *
484getprivs(long id, int quotatype)

--- 8 unchanged lines hidden (view full) ---

493 qup = quphead = (struct quotause *)0;
494
495 if (filename != NULL && statfs(filename, &sfb) != 0)
496 err(1, "cannot statfs %s", filename);
497 nfst = getmntinfo(&fst, MNT_NOWAIT);
498 if (nfst == 0)
499 errx(2, "no filesystems mounted!");
500 setfsent();
502 for (i=0; i<nfst; i++) {
501 for (i = 0; i < nfst; i++) {
503 if (qup == NULL) {
504 if ((qup = (struct quotause *)malloc(sizeof *qup))
505 == NULL)
506 errx(2, "out of memory");
507 }
508 /*
509 * See if the user requested a specific file system
510 * or specified a file inside a mounted file system.

--- 32 unchanged lines hidden (view full) ---

543 }
544 if (qup)
545 free(qup);
546 endfsent();
547 return (quphead);
548}
549
550/*
502 if (qup == NULL) {
503 if ((qup = (struct quotause *)malloc(sizeof *qup))
504 == NULL)
505 errx(2, "out of memory");
506 }
507 /*
508 * See if the user requested a specific file system
509 * or specified a file inside a mounted file system.

--- 32 unchanged lines hidden (view full) ---

542 }
543 if (qup)
544 free(qup);
545 endfsent();
546 return (quphead);
547}
548
549/*
551 * Check to see if a particular quota is to be enabled.
550 * Check to see if a particular quota is available.
552 */
553static int
551 */
552static int
554ufshasquota(struct fstab *fs, int type, char **qfnamep)
553getufsquota(struct fstab *fs, struct quotause *qup, long id, int quotatype)
555{
554{
556 char *opt;
557 char *cp;
558 struct statfs sfb;
559 static char initname, usrname[100], grpname[100];
560 static char buf[BUFSIZ];
555 struct quotafile *qf;
561
556
562 if (!initname) {
563 (void)snprintf(usrname, sizeof(usrname), "%s%s",
564 qfextension[USRQUOTA], qfname);
565 (void)snprintf(grpname, sizeof(grpname), "%s%s",
566 qfextension[GRPQUOTA], qfname);
567 initname = 1;
568 }
569 strcpy(buf, fs->fs_mntops);
570 for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
571 if ((cp = index(opt, '=')))
572 *cp++ = '\0';
573 if (type == USRQUOTA && strcmp(opt, usrname) == 0)
574 break;
575 if (type == GRPQUOTA && strcmp(opt, grpname) == 0)
576 break;
577 }
578 if (!opt)
557 if ((qf = quota_open(fs, quotatype, O_RDONLY)) == NULL)
579 return (0);
558 return (0);
580 if (cp)
581 *qfnamep = cp;
582 else {
583 (void)snprintf(buf, sizeof(buf), "%s/%s.%s", fs->fs_file,
584 qfname, qfextension[type]);
585 *qfnamep = buf;
586 }
587 if (statfs(fs->fs_file, &sfb) != 0) {
588 warn("cannot statfs mount point %s", fs->fs_file);
559 if (quota_read(qf, &qup->dqblk, id) != 0)
589 return (0);
560 return (0);
590 }
591 if (strcmp(fs->fs_file, sfb.f_mntonname)) {
592 warnx("%s not mounted for %s quotas", fs->fs_file,
593 type == USRQUOTA ? "user" : "group");
594 return (0);
595 }
561 quota_close(qf);
596 return (1);
597}
598
599static int
562 return (1);
563}
564
565static int
600getufsquota(struct fstab *fs, struct quotause *qup, long id, int quotatype)
601{
602 char *qfpathname;
603 int fd, qcmd;
604
605 qcmd = QCMD(Q_GETQUOTA, quotatype);
606 if (!ufshasquota(fs, quotatype, &qfpathname))
607 return (0);
608
609 if (quotactl(fs->fs_file, qcmd, id, (char *)&qup->dqblk) != 0) {
610 if ((fd = open(qfpathname, O_RDONLY)) < 0) {
611 warn("%s", qfpathname);
612 return (0);
613 }
614 (void) lseek(fd, (off_t)(id * sizeof(struct dqblk)), L_SET);
615 switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) {
616 case 0: /* EOF */
617 /*
618 * Convert implicit 0 quota (EOF)
619 * into an explicit one (zero'ed dqblk)
620 */
621 bzero((caddr_t)&qup->dqblk, sizeof(struct dqblk));
622 break;
623 case sizeof(struct dqblk): /* OK */
624 break;
625 default: /* ERROR */
626 warn("read error: %s", qfpathname);
627 close(fd);
628 return (0);
629 }
630 close(fd);
631 }
632 return (1);
633}
634
635static int
636getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype)
637{
638 struct getquota_args gq_args;
639 struct getquota_rslt gq_rslt;
640 struct dqblk *dqp = &qup->dqblk;
641 struct timeval tv;
642 char *cp;
643

--- 127 unchanged lines hidden ---
566getnfsquota(struct statfs *fst, struct quotause *qup, long id, int quotatype)
567{
568 struct getquota_args gq_args;
569 struct getquota_rslt gq_rslt;
570 struct dqblk *dqp = &qup->dqblk;
571 struct timeval tv;
572 char *cp;
573

--- 127 unchanged lines hidden ---