Home | History | Annotate | Line # | Download | only in quota
quota.c revision 1.37
      1  1.37    bouyer /*	$NetBSD: quota.c,v 1.37 2011/03/24 17:05:46 bouyer 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.37    bouyer __RCSID("$NetBSD: quota.c,v 1.37 2011/03/24 17:05:46 bouyer 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.37    bouyer 	struct	ufs_quota_entry qe[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.35  christos static struct quotause	*getprivs(uint32_t, int);
     89  1.35  christos static void	heading(int, uint32_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.35  christos static void	showquotas(int, uint32_t, const char *);
     93  1.35  christos static void	showuid(uid_t);
     94  1.35  christos static void	showusrname(const char *);
     95  1.35  christos static void	usage(void) __attribute__((__noreturn__));
     96  1.35  christos 
     97  1.35  christos static int	qflag = 0;
     98  1.35  christos static int	vflag = 0;
     99  1.35  christos static int	hflag = 0;
    100  1.35  christos static int	dflag = 0;
    101  1.35  christos static int	Dflag = 0;
    102  1.35  christos static uid_t	myuid;
    103   1.1       cgd 
    104  1.16     lukem int
    105  1.35  christos main(int argc, char *argv[])
    106   1.1       cgd {
    107   1.3       jtc 	int ngroups;
    108   1.8   mycroft 	gid_t mygid, gidset[NGROUPS];
    109   1.1       cgd 	int i, gflag = 0, uflag = 0;
    110  1.11      mark 	int ch;
    111   1.1       cgd 
    112  1.19       mrg 	myuid = getuid();
    113  1.34    bouyer 	while ((ch = getopt(argc, argv, "Ddhugvq")) != -1) {
    114   1.1       cgd 		switch(ch) {
    115   1.1       cgd 		case 'g':
    116   1.1       cgd 			gflag++;
    117   1.1       cgd 			break;
    118   1.1       cgd 		case 'u':
    119   1.1       cgd 			uflag++;
    120   1.1       cgd 			break;
    121   1.1       cgd 		case 'v':
    122   1.1       cgd 			vflag++;
    123   1.1       cgd 			break;
    124   1.1       cgd 		case 'q':
    125   1.1       cgd 			qflag++;
    126   1.1       cgd 			break;
    127  1.34    bouyer 		case 'h':
    128  1.34    bouyer 			hflag++;
    129  1.34    bouyer 			break;
    130  1.34    bouyer 		case 'd':
    131  1.34    bouyer 			dflag++;
    132  1.34    bouyer 			break;
    133  1.34    bouyer 		case 'D':
    134  1.34    bouyer 			Dflag++;
    135  1.34    bouyer 			break;
    136   1.1       cgd 		default:
    137   1.1       cgd 			usage();
    138   1.1       cgd 		}
    139   1.1       cgd 	}
    140   1.1       cgd 	argc -= optind;
    141   1.1       cgd 	argv += optind;
    142   1.1       cgd 	if (!uflag && !gflag)
    143   1.1       cgd 		uflag++;
    144  1.34    bouyer 	if (dflag) {
    145  1.34    bouyer #if 0
    146  1.35  christos 		if (myuid != 0)
    147  1.35  christos 			errx(1, "-d: permission denied");
    148  1.34    bouyer #endif
    149  1.34    bouyer 		if (uflag)
    150  1.37    bouyer 			showquotas(QUOTA_CLASS_USER, 0, "");
    151  1.34    bouyer 		if (gflag)
    152  1.37    bouyer 			showquotas(QUOTA_CLASS_GROUP, 0, "");
    153  1.35  christos 		return 0;
    154  1.34    bouyer 	}
    155   1.1       cgd 	if (argc == 0) {
    156   1.1       cgd 		if (uflag)
    157  1.19       mrg 			showuid(myuid);
    158   1.1       cgd 		if (gflag) {
    159  1.34    bouyer 			if (dflag)
    160  1.34    bouyer 				showgid(0);
    161  1.34    bouyer 			else {
    162  1.34    bouyer 				mygid = getgid();
    163  1.34    bouyer 				ngroups = getgroups(NGROUPS, gidset);
    164  1.34    bouyer 				if (ngroups < 0)
    165  1.34    bouyer 					err(1, "getgroups");
    166  1.34    bouyer 				showgid(mygid);
    167  1.34    bouyer 				for (i = 0; i < ngroups; i++)
    168  1.34    bouyer 					if (gidset[i] != mygid)
    169  1.34    bouyer 						showgid(gidset[i]);
    170  1.34    bouyer 			}
    171   1.1       cgd 		}
    172  1.35  christos 		return 0;
    173   1.1       cgd 	}
    174   1.1       cgd 	if (uflag && gflag)
    175   1.1       cgd 		usage();
    176   1.1       cgd 	if (uflag) {
    177   1.1       cgd 		for (; argc > 0; argc--, argv++) {
    178   1.1       cgd 			if (alldigits(*argv))
    179  1.35  christos 				showuid((uid_t)atoi(*argv));
    180   1.1       cgd 			else
    181   1.1       cgd 				showusrname(*argv);
    182   1.1       cgd 		}
    183  1.35  christos 		return 0;
    184   1.1       cgd 	}
    185   1.1       cgd 	if (gflag) {
    186   1.1       cgd 		for (; argc > 0; argc--, argv++) {
    187   1.1       cgd 			if (alldigits(*argv))
    188  1.35  christos 				showgid((gid_t)atoi(*argv));
    189   1.1       cgd 			else
    190   1.1       cgd 				showgrpname(*argv);
    191   1.1       cgd 		}
    192  1.35  christos 		return 0;
    193   1.1       cgd 	}
    194  1.16     lukem 	/* NOTREACHED */
    195  1.35  christos 	return 0;
    196   1.1       cgd }
    197   1.1       cgd 
    198  1.35  christos static void
    199  1.35  christos usage(void)
    200   1.1       cgd {
    201  1.35  christos 	const char *p = getprogname();
    202  1.35  christos 	fprintf(stderr, "Usage: %s [-Dhguqv]\n"
    203  1.35  christos 	    "\t%s [-Dhqv] -u username ...\n"
    204  1.35  christos 	    "\t%s [-Dhqv] -g groupname ...\n"
    205  1.35  christos 	    "\t%s -d [-Dhguqv]\n", p, p, p, p);
    206   1.1       cgd 	exit(1);
    207   1.1       cgd }
    208   1.1       cgd 
    209   1.1       cgd /*
    210   1.1       cgd  * Print out quotas for a specified user identifier.
    211   1.1       cgd  */
    212  1.35  christos static void
    213  1.35  christos showuid(uid_t uid)
    214   1.1       cgd {
    215   1.1       cgd 	struct passwd *pwd = getpwuid(uid);
    216  1.20   mycroft 	const char *name;
    217   1.1       cgd 
    218   1.1       cgd 	if (pwd == NULL)
    219   1.1       cgd 		name = "(no account)";
    220   1.1       cgd 	else
    221   1.1       cgd 		name = pwd->pw_name;
    222   1.1       cgd 	if (uid != myuid && myuid != 0) {
    223  1.35  christos 		warnx("%s (uid %d): permission denied", name, uid);
    224   1.1       cgd 		return;
    225   1.1       cgd 	}
    226  1.37    bouyer 	showquotas(QUOTA_CLASS_USER, uid, name);
    227   1.1       cgd }
    228   1.1       cgd 
    229   1.1       cgd /*
    230  1.24       wiz  * Print out quotas for a specified user name.
    231   1.1       cgd  */
    232  1.35  christos static void
    233  1.35  christos showusrname(const char *name)
    234   1.1       cgd {
    235   1.1       cgd 	struct passwd *pwd = getpwnam(name);
    236   1.1       cgd 
    237   1.1       cgd 	if (pwd == NULL) {
    238  1.16     lukem 		warnx("%s: unknown user", name);
    239   1.1       cgd 		return;
    240   1.1       cgd 	}
    241   1.1       cgd 	if (pwd->pw_uid != myuid && myuid != 0) {
    242  1.16     lukem 		warnx("%s (uid %d): permission denied", name, pwd->pw_uid);
    243   1.1       cgd 		return;
    244   1.1       cgd 	}
    245  1.37    bouyer 	showquotas(QUOTA_CLASS_USER, pwd->pw_uid, name);
    246   1.1       cgd }
    247   1.1       cgd 
    248   1.1       cgd /*
    249   1.1       cgd  * Print out quotas for a specified group identifier.
    250   1.1       cgd  */
    251  1.35  christos static void
    252  1.35  christos showgid(gid_t gid)
    253   1.1       cgd {
    254   1.1       cgd 	struct group *grp = getgrgid(gid);
    255   1.3       jtc 	int ngroups;
    256   1.8   mycroft 	gid_t mygid, gidset[NGROUPS];
    257  1.16     lukem 	int i;
    258  1.20   mycroft 	const char *name;
    259   1.1       cgd 
    260   1.1       cgd 	if (grp == NULL)
    261   1.1       cgd 		name = "(no entry)";
    262   1.1       cgd 	else
    263   1.1       cgd 		name = grp->gr_name;
    264   1.8   mycroft 	mygid = getgid();
    265   1.1       cgd 	ngroups = getgroups(NGROUPS, gidset);
    266   1.1       cgd 	if (ngroups < 0) {
    267  1.16     lukem 		warn("getgroups");
    268   1.1       cgd 		return;
    269   1.1       cgd 	}
    270   1.8   mycroft 	if (gid != mygid) {
    271   1.8   mycroft 		for (i = 0; i < ngroups; i++)
    272   1.8   mycroft 			if (gid == gidset[i])
    273   1.8   mycroft 				break;
    274  1.19       mrg 		if (i >= ngroups && myuid != 0) {
    275  1.16     lukem 			warnx("%s (gid %d): permission denied", name, gid);
    276   1.8   mycroft 			return;
    277   1.8   mycroft 		}
    278   1.1       cgd 	}
    279  1.37    bouyer 	showquotas(QUOTA_CLASS_GROUP, gid, name);
    280   1.1       cgd }
    281   1.1       cgd 
    282   1.1       cgd /*
    283  1.24       wiz  * Print out quotas for a specified group name.
    284   1.1       cgd  */
    285  1.35  christos static void
    286  1.35  christos showgrpname(const char *name)
    287   1.1       cgd {
    288   1.1       cgd 	struct group *grp = getgrnam(name);
    289   1.3       jtc 	int ngroups;
    290   1.8   mycroft 	gid_t mygid, gidset[NGROUPS];
    291  1.16     lukem 	int i;
    292   1.1       cgd 
    293   1.1       cgd 	if (grp == NULL) {
    294  1.16     lukem 		warnx("%s: unknown group", name);
    295   1.1       cgd 		return;
    296   1.1       cgd 	}
    297   1.8   mycroft 	mygid = getgid();
    298   1.1       cgd 	ngroups = getgroups(NGROUPS, gidset);
    299   1.1       cgd 	if (ngroups < 0) {
    300  1.16     lukem 		warn("getgroups");
    301   1.1       cgd 		return;
    302   1.1       cgd 	}
    303   1.8   mycroft 	if (grp->gr_gid != mygid) {
    304   1.8   mycroft 		for (i = 0; i < ngroups; i++)
    305   1.8   mycroft 			if (grp->gr_gid == gidset[i])
    306   1.8   mycroft 				break;
    307  1.19       mrg 		if (i >= ngroups && myuid != 0) {
    308  1.16     lukem 			warnx("%s (gid %d): permission denied",
    309   1.8   mycroft 			    name, grp->gr_gid);
    310   1.8   mycroft 			return;
    311   1.8   mycroft 		}
    312   1.1       cgd 	}
    313  1.37    bouyer 	showquotas(QUOTA_CLASS_GROUP, grp->gr_gid, name);
    314   1.1       cgd }
    315   1.1       cgd 
    316  1.35  christos static void
    317  1.35  christos showquotas(int type, uint32_t id, const char *name)
    318   1.1       cgd {
    319  1.16     lukem 	struct quotause *qup;
    320   1.6   deraadt 	struct quotause *quplist;
    321  1.34    bouyer 	const char *msgi, *msgb, *nam, *timemsg;
    322  1.16     lukem 	int lines = 0;
    323   1.1       cgd 	static time_t now;
    324  1.35  christos 	char b0[20], b1[20], b2[20], b3[20];
    325   1.1       cgd 
    326   1.1       cgd 	if (now == 0)
    327   1.1       cgd 		time(&now);
    328   1.1       cgd 	quplist = getprivs(id, type);
    329   1.1       cgd 	for (qup = quplist; qup; qup = qup->next) {
    330  1.34    bouyer 		int ql_stat;
    331  1.37    bouyer 		struct ufs_quota_entry *q = qup->qe;
    332   1.1       cgd 		if (!vflag &&
    333  1.37    bouyer 		    q[QUOTA_LIMIT_BLOCK].ufsqe_softlimit == UQUAD_MAX &&
    334  1.37    bouyer 		    q[QUOTA_LIMIT_BLOCK].ufsqe_hardlimit == UQUAD_MAX &&
    335  1.37    bouyer 		    q[QUOTA_LIMIT_FILE].ufsqe_softlimit == UQUAD_MAX &&
    336  1.37    bouyer 		    q[QUOTA_LIMIT_FILE].ufsqe_hardlimit == UQUAD_MAX)
    337   1.1       cgd 			continue;
    338  1.37    bouyer 		ql_stat = quota_check_limit(q[QUOTA_LIMIT_FILE].ufsqe_cur, 1,
    339  1.37    bouyer 		    q[QUOTA_LIMIT_FILE].ufsqe_softlimit,
    340  1.37    bouyer 		    q[QUOTA_LIMIT_FILE].ufsqe_hardlimit,
    341  1.37    bouyer 		    q[QUOTA_LIMIT_FILE].ufsqe_time, now);
    342  1.34    bouyer 		switch(QL_STATUS(ql_stat)) {
    343  1.34    bouyer 		case QL_S_DENY_HARD:
    344   1.1       cgd 			msgi = "File limit reached on";
    345  1.34    bouyer 			break;
    346  1.34    bouyer 		case QL_S_DENY_GRACE:
    347  1.34    bouyer 			msgi = "Over file quota on";
    348  1.34    bouyer 			break;
    349  1.34    bouyer 		case QL_S_ALLOW_SOFT:
    350  1.34    bouyer 			msgi = "In file grace period on";
    351  1.34    bouyer 			break;
    352  1.34    bouyer 		default:
    353  1.34    bouyer 			msgi = NULL;
    354  1.21      ross 		}
    355  1.37    bouyer 		ql_stat = quota_check_limit(q[QUOTA_LIMIT_BLOCK].ufsqe_cur, 1,
    356  1.37    bouyer 		    q[QUOTA_LIMIT_BLOCK].ufsqe_softlimit,
    357  1.37    bouyer 		    q[QUOTA_LIMIT_BLOCK].ufsqe_hardlimit,
    358  1.37    bouyer 		    q[QUOTA_LIMIT_BLOCK].ufsqe_time, now);
    359  1.34    bouyer 		switch(QL_STATUS(ql_stat)) {
    360  1.34    bouyer 		case QL_S_DENY_HARD:
    361   1.1       cgd 			msgb = "Block limit reached on";
    362  1.34    bouyer 			break;
    363  1.34    bouyer 		case QL_S_DENY_GRACE:
    364  1.34    bouyer 			msgb = "Over block quota on";
    365  1.34    bouyer 			break;
    366  1.34    bouyer 		case QL_S_ALLOW_SOFT:
    367  1.34    bouyer 			msgb = "In block grace period on";
    368  1.34    bouyer 			break;
    369  1.34    bouyer 		default:
    370  1.34    bouyer 			msgb = NULL;
    371  1.21      ross 		}
    372   1.1       cgd 		if (qflag) {
    373  1.33     lukem 			if ((msgi != NULL || msgb != NULL) &&
    374   1.1       cgd 			    lines++ == 0)
    375   1.1       cgd 				heading(type, id, name, "");
    376  1.33     lukem 			if (msgi != NULL)
    377   1.1       cgd 				printf("\t%s %s\n", msgi, qup->fsname);
    378  1.33     lukem 			if (msgb != NULL)
    379   1.1       cgd 				printf("\t%s %s\n", msgb, qup->fsname);
    380   1.1       cgd 			continue;
    381   1.1       cgd 		}
    382  1.37    bouyer 		if (vflag || dflag || msgi || msgb ||
    383  1.37    bouyer 		    q[QUOTA_LIMIT_BLOCK].ufsqe_cur ||
    384  1.37    bouyer 		    q[QUOTA_LIMIT_FILE].ufsqe_cur) {
    385   1.1       cgd 			if (lines++ == 0)
    386   1.1       cgd 				heading(type, id, name, "");
    387   1.6   deraadt 			nam = qup->fsname;
    388  1.34    bouyer 			if (strlen(qup->fsname) > 4) {
    389   1.6   deraadt 				printf("%s\n", qup->fsname);
    390   1.6   deraadt 				nam = "";
    391   1.6   deraadt 			}
    392  1.34    bouyer 			if (msgb)
    393  1.35  christos 				timemsg = timeprt(b0, 9, now,
    394  1.37    bouyer 				    q[QUOTA_LIMIT_BLOCK].ufsqe_time);
    395  1.34    bouyer 			else if ((qup->flags & QUOTA2) != 0 && vflag)
    396  1.35  christos 				timemsg = timeprt(b0, 9, 0,
    397  1.37    bouyer 				    q[QUOTA_LIMIT_BLOCK].ufsqe_grace);
    398  1.34    bouyer 			else
    399  1.34    bouyer 				timemsg = "";
    400  1.34    bouyer 
    401  1.35  christos 			printf("%12s%9s%c%8s%9s%8s",
    402  1.35  christos 			    nam,
    403  1.37    bouyer 			    intprt(b1, 9, q[QUOTA_LIMIT_BLOCK].ufsqe_cur,
    404  1.35  christos 			    HN_B, hflag),
    405  1.35  christos 			    (msgb == NULL) ? ' ' : '*',
    406  1.37    bouyer 			    intprt(b2, 9, q[QUOTA_LIMIT_BLOCK].ufsqe_softlimit,
    407  1.35  christos 			    HN_B, hflag),
    408  1.37    bouyer 			    intprt(b3, 9, q[QUOTA_LIMIT_BLOCK].ufsqe_hardlimit,
    409  1.35  christos 			    HN_B, hflag),
    410  1.35  christos 			    timemsg);
    411  1.34    bouyer 
    412  1.34    bouyer 			if (msgi)
    413  1.35  christos 				timemsg = timeprt(b0, 9, now,
    414  1.37    bouyer 				    q[QUOTA_LIMIT_FILE].ufsqe_time);
    415  1.34    bouyer 			else if ((qup->flags & QUOTA2) != 0 && vflag)
    416  1.35  christos 				timemsg = timeprt(b0, 9, 0,
    417  1.37    bouyer 				    q[QUOTA_LIMIT_FILE].ufsqe_grace);
    418  1.34    bouyer 			else
    419  1.34    bouyer 				timemsg = "";
    420  1.34    bouyer 
    421  1.35  christos 			printf("%8s%c%7s%8s%8s\n",
    422  1.37    bouyer 			    intprt(b1, 8, q[QUOTA_LIMIT_FILE].ufsqe_cur, 0,
    423  1.37    bouyer 			     hflag),
    424  1.35  christos 			    (msgi == NULL) ? ' ' : '*',
    425  1.37    bouyer 			    intprt(b2, 8, q[QUOTA_LIMIT_FILE].ufsqe_softlimit,
    426  1.37    bouyer 			     0, hflag),
    427  1.37    bouyer 			    intprt(b3, 8, q[QUOTA_LIMIT_FILE].ufsqe_hardlimit,
    428  1.37    bouyer 			     0, hflag),
    429  1.35  christos 			    timemsg);
    430   1.1       cgd 			continue;
    431   1.1       cgd 		}
    432   1.1       cgd 	}
    433   1.1       cgd 	if (!qflag && lines == 0)
    434   1.1       cgd 		heading(type, id, name, "none");
    435   1.1       cgd }
    436   1.1       cgd 
    437  1.35  christos static void
    438  1.35  christos heading(int type, uint32_t id, const char *name, const char *tag)
    439   1.1       cgd {
    440  1.34    bouyer 	if (dflag)
    441  1.34    bouyer 		printf("Default %s disk quotas: %s\n",
    442  1.37    bouyer 		    ufs_quota_class_names[type], tag);
    443  1.34    bouyer 	else
    444  1.35  christos 		printf("Disk quotas for %s %s (%cid %u): %s\n",
    445  1.37    bouyer 		    ufs_quota_class_names[type], name,
    446  1.37    bouyer 		    *ufs_quota_class_names[type], id, tag);
    447   1.1       cgd 
    448   1.1       cgd 	if (!qflag && tag[0] == '\0') {
    449  1.22    bouyer 		printf("%12s%9s %8s%9s%8s%8s %7s%8s%8s\n"
    450  1.22    bouyer 		    , "Filesystem"
    451  1.22    bouyer 		    , "blocks"
    452  1.22    bouyer 		    , "quota"
    453  1.22    bouyer 		    , "limit"
    454  1.22    bouyer 		    , "grace"
    455  1.22    bouyer 		    , "files"
    456  1.22    bouyer 		    , "quota"
    457  1.22    bouyer 		    , "limit"
    458  1.22    bouyer 		    , "grace"
    459   1.1       cgd 		);
    460   1.1       cgd 	}
    461   1.1       cgd }
    462   1.1       cgd 
    463   1.1       cgd /*
    464   1.1       cgd  * Collect the requested quota information.
    465   1.1       cgd  */
    466  1.35  christos static struct quotause *
    467  1.35  christos getprivs(uint32_t id, int quotatype)
    468   1.1       cgd {
    469  1.16     lukem 	struct quotause *qup, *quptail;
    470   1.1       cgd 	struct quotause *quphead;
    471  1.29  christos 	struct statvfs *fst;
    472   1.6   deraadt 	int nfst, i;
    473  1.34    bouyer 	int8_t version;
    474   1.6   deraadt 
    475  1.16     lukem 	qup = quphead = quptail = NULL;
    476   1.1       cgd 
    477   1.6   deraadt 	nfst = getmntinfo(&fst, MNT_WAIT);
    478  1.16     lukem 	if (nfst == 0)
    479  1.16     lukem 		errx(2, "no filesystems mounted!");
    480  1.19       mrg 	for (i = 0; i < nfst; i++) {
    481   1.6   deraadt 		if (qup == NULL) {
    482  1.35  christos 			if ((qup = malloc(sizeof *qup)) == NULL)
    483  1.35  christos 				err(1, "out of memory");
    484   1.1       cgd 		}
    485  1.31  christos 		if (strncmp(fst[i].f_fstypename, "nfs",
    486  1.31  christos 		    sizeof(fst[i].f_fstypename)) == 0) {
    487  1.34    bouyer 			version = 0;
    488  1.37    bouyer 			if (getnfsquota(fst[i].f_mntfromname,
    489  1.37    bouyer 			    qup->qe, id, ufs_quota_class_names[quotatype]) != 1)
    490   1.6   deraadt 				continue;
    491  1.34    bouyer 		} else if ((fst[i].f_flag & ST_QUOTA) != 0) {
    492  1.37    bouyer 			if (getvfsquota(fst[i].f_mntonname, qup->qe, &version,
    493  1.37    bouyer 			    id, quotatype, dflag, Dflag) != 1)
    494   1.1       cgd 				continue;
    495   1.6   deraadt 		} else
    496   1.6   deraadt 			continue;
    497  1.13       mrg 		(void)strncpy(qup->fsname, fst[i].f_mntonname,
    498  1.13       mrg 		    sizeof(qup->fsname) - 1);
    499  1.34    bouyer 		if (version == 2)
    500  1.34    bouyer 			qup->flags |= QUOTA2;
    501   1.1       cgd 		if (quphead == NULL)
    502   1.1       cgd 			quphead = qup;
    503   1.1       cgd 		else
    504   1.1       cgd 			quptail->next = qup;
    505   1.1       cgd 		quptail = qup;
    506   1.6   deraadt 		quptail->next = 0;
    507   1.6   deraadt 		qup = NULL;
    508   1.1       cgd 	}
    509  1.35  christos 	free(qup);
    510  1.35  christos 	return quphead;
    511   1.1       cgd }
    512