Module Name: src
Committed By: dholland
Date: Wed Nov 30 16:12:32 UTC 2011
Modified Files:
src/usr.bin/quota: quota.c
Log Message:
Adjust the quota-fetching code to allow more than two object types.
(as far as we can so far, at least)
Note that quota won't actually work fully with multiple object types
as it is, but this and the last change are a good start and do fold
together a lot of duplicated code.
To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/quota/quota.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/quota/quota.c
diff -u src/usr.bin/quota/quota.c:1.42 src/usr.bin/quota/quota.c:1.43
--- src/usr.bin/quota/quota.c:1.42 Wed Nov 30 16:09:29 2011
+++ src/usr.bin/quota/quota.c Wed Nov 30 16:12:32 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: quota.c,v 1.42 2011/11/30 16:09:29 dholland Exp $ */
+/* $NetBSD: quota.c,v 1.43 2011/11/30 16:12:32 dholland Exp $ */
/*
* Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
#if 0
static char sccsid[] = "@(#)quota.c 8.4 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: quota.c,v 1.42 2011/11/30 16:09:29 dholland Exp $");
+__RCSID("$NetBSD: quota.c,v 1.43 2011/11/30 16:12:32 dholland Exp $");
#endif
#endif /* not lint */
@@ -80,7 +80,8 @@ struct quotause {
struct quotause *next;
long flags;
uid_t id;
- struct quotaval qv[QUOTA_NLIMITS];
+ struct quotaval *qvs;
+ unsigned numqvs;
char fsname[MAXPATHLEN + 1];
};
#define FOUND 0x01
@@ -353,8 +354,8 @@ showonequota(int type, id_t id, const ch
const char *msg;
int isquota2;
- qvs = qup->qv;
- numqvs = QUOTA_NLIMITS;
+ qvs = qup->qvs;
+ numqvs = qup->numqvs;
if (now == 0) {
time(&now);
@@ -399,7 +400,8 @@ showonequota(int type, id_t id, const ch
isquota2 = (qup->flags & QUOTA2) != 0;
for (i=0; i<numqvs; i++) {
- printqv(&qvs[i], isquota2, isbytes[i], now);
+ printqv(&qvs[i], isquota2,
+ i >= QUOTA_NLIMITS ? 0 : isbytes[i], now);
}
printf("\n");
}
@@ -494,16 +496,26 @@ getprivs(id_t id, int quotatype)
for (i = 0; i < nfst; i++) {
if (qup == NULL) {
if ((qup = malloc(sizeof *qup)) == NULL)
- err(1, "out of memory");
+ err(1, "Out of memory");
}
if (strncmp(fst[i].f_fstypename, "nfs",
sizeof(fst[i].f_fstypename)) == 0) {
version = 0;
+ qup->numqvs = QUOTA_NLIMITS;
+ qup->qvs = malloc(qup->numqvs * sizeof(qup->qvs[0]));
+ if (qup->qvs == NULL) {
+ err(1, "Out of memory");
+ }
if (getnfsquota(fst[i].f_mntfromname,
- qup->qv, id, ufs_quota_class_names[quotatype]) != 1)
+ qup->qvs, id, ufs_quota_class_names[quotatype]) != 1)
continue;
} else if ((fst[i].f_flag & ST_QUOTA) != 0) {
- if (getvfsquota(fst[i].f_mntonname, qup->qv, &version,
+ qup->numqvs = QUOTA_NLIMITS;
+ qup->qvs = malloc(qup->numqvs * sizeof(qup->qvs[0]));
+ if (qup->qvs == NULL) {
+ err(1, "Out of memory");
+ }
+ if (getvfsquota(fst[i].f_mntonname, qup->qvs, &version,
id, quotatype, dflag, Dflag) != 1)
continue;
} else