Module Name: src Committed By: dholland Date: Wed Feb 1 17:48:11 UTC 2012
Modified Files: src/usr.bin/quota: quota.c src/usr.sbin/repquota: repquota.c Log Message: Simplify elaborate calls to quota_check_limit(). To generate a diff of this commit: cvs rdiff -u -r1.46 -r1.47 src/usr.bin/quota/quota.c cvs rdiff -u -r1.40 -r1.41 src/usr.sbin/repquota/repquota.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.46 src/usr.bin/quota/quota.c:1.47 --- src/usr.bin/quota/quota.c:1.46 Mon Jan 30 16:46:30 2012 +++ src/usr.bin/quota/quota.c Wed Feb 1 17:48:10 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: quota.c,v 1.46 2012/01/30 16:46:30 dholland Exp $ */ +/* $NetBSD: quota.c,v 1.47 2012/02/01 17:48:10 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.46 2012/01/30 16:46:30 dholland Exp $"); +__RCSID("$NetBSD: quota.c,v 1.47 2012/02/01 17:48:10 dholland Exp $"); #endif #endif /* not lint */ @@ -610,46 +610,31 @@ anyover(struct quotaval *qvs, unsigned n static int isover(struct quotaval *qv, time_t now) { - int ql_stat; - - ql_stat = quota_check_limit(qv->qv_usage, 1, - qv->qv_softlimit, - qv->qv_hardlimit, - qv->qv_expiretime, now); - switch(QL_STATUS(ql_stat)) { - case QL_S_DENY_HARD: - case QL_S_DENY_GRACE: - case QL_S_ALLOW_SOFT: - return 1; - default: - break; - } - return 0; + return (qv->qv_usage >= qv->qv_hardlimit || + qv->qv_usage >= qv->qv_softlimit); } static const char * getovermsg(struct quotaval *qv, const char *what, time_t now) { static char buf[64]; - int ql_stat; - ql_stat = quota_check_limit(qv->qv_usage, 1, - qv->qv_softlimit, - qv->qv_hardlimit, - qv->qv_expiretime, now); - switch(QL_STATUS(ql_stat)) { - case QL_S_DENY_HARD: + if (qv->qv_usage >= qv->qv_hardlimit) { snprintf(buf, sizeof(buf), "%c%s limit reached on", toupper((unsigned char)what[0]), what+1); - break; - case QL_S_DENY_GRACE: - snprintf(buf, sizeof(buf), "Over %s quota on", what); - break; - case QL_S_ALLOW_SOFT: - snprintf(buf, sizeof(buf), "In %s grace period on", what); - break; - default: + return buf; + } + + if (qv->qv_usage < qv->qv_softlimit) { + /* Ok */ return NULL; } + + if (now > qv->qv_expiretime) { + snprintf(buf, sizeof(buf), "Over %s quota on", what); + return buf; + } + + snprintf(buf, sizeof(buf), "In %s grace period on", what); return buf; } Index: src/usr.sbin/repquota/repquota.c diff -u src/usr.sbin/repquota/repquota.c:1.40 src/usr.sbin/repquota/repquota.c:1.41 --- src/usr.sbin/repquota/repquota.c:1.40 Wed Feb 1 05:12:45 2012 +++ src/usr.sbin/repquota/repquota.c Wed Feb 1 17:48:10 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: repquota.c,v 1.40 2012/02/01 05:12:45 dholland Exp $ */ +/* $NetBSD: repquota.c,v 1.41 2012/02/01 17:48:10 dholland Exp $ */ /* * Copyright (c) 1980, 1990, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)repquota.c 8.2 (Berkeley) 11/22/94"; #else -__RCSID("$NetBSD: repquota.c,v 1.40 2012/02/01 05:12:45 dholland Exp $"); +__RCSID("$NetBSD: repquota.c,v 1.41 2012/02/01 17:48:10 dholland Exp $"); #endif #endif /* not lint */ @@ -118,6 +118,7 @@ static void usage(void) __attribute__((_ static void printquotas(int, struct quotahandle *); static void exportquotas(void); static int oneof(const char *, char *[], int cnt); +static int isover(struct quotaval *qv, time_t now); int main(int argc, char **argv) @@ -330,17 +331,11 @@ printquotas(int idtype, struct quotahand if (fup == 0) continue; for (i = 0; i < REPQUOTA_NUMOBJTYPES; i++) { - switch (QL_STATUS(quota_check_limit(q[i].qv_usage, 1, - q[i].qv_softlimit, q[i].qv_hardlimit, - q[i].qv_expiretime, now))) { - case QL_S_DENY_HARD: - case QL_S_DENY_GRACE: - case QL_S_ALLOW_SOFT: + if (isover(&q[i], now)) { timemsg[i] = timeprt(b0[i], 8, now, q[i].qv_expiretime); overchar[i] = '+'; - break; - default: + } else { if (vflag && q[i].qv_grace != QUOTA_NOTIME) { timemsg[i] = timeprt(b0[i], 8, 0, q[i].qv_grace); @@ -348,7 +343,6 @@ printquotas(int idtype, struct quotahand timemsg[i] = ""; } overchar[i] = '-'; - break; } } @@ -571,3 +565,10 @@ oneof(const char *target, char *list[], return i; return -1; } + +static int +isover(struct quotaval *qv, time_t now) +{ + return (qv->qv_usage >= qv->qv_hardlimit || + qv->qv_usage >= qv->qv_softlimit); +}