Module Name:    src
Committed By:   christos
Date:           Sun Mar  6 22:36:07 UTC 2011

Modified Files:
        src/usr.bin/quota: Makefile getvfsquota.c printquota.c printquota.h
            quota.c
Added Files:
        src/usr.bin/quota: quotautil.c quotautil.h

Log Message:
- merge more code.
- simplify struct access.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/quota/Makefile
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/quota/getvfsquota.c \
    src/usr.bin/quota/printquota.c src/usr.bin/quota/printquota.h
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/quota/quota.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/quota/quotautil.c \
    src/usr.bin/quota/quotautil.h

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/Makefile
diff -u src/usr.bin/quota/Makefile:1.8 src/usr.bin/quota/Makefile:1.9
--- src/usr.bin/quota/Makefile:1.8	Sun Mar  6 15:47:59 2011
+++ src/usr.bin/quota/Makefile	Sun Mar  6 17:36:07 2011
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.8 2011/03/06 20:47:59 christos Exp $	
+#	$NetBSD: Makefile,v 1.9 2011/03/06 22:36:07 christos Exp $	
 #	from: @(#)Makefile	8.1 (Berkeley) 6/6/93
 
 WARNS ?= 4
 .include <bsd.own.mk>
 PROG=	quota
-SRCS=	quota.c printquota.c getvfsquota.c
+SRCS=	quota.c printquota.c getvfsquota.c quotautil.c
 
 CPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
 DPADD=	${LIBRPCSVC} ${LIBPROP}

Index: src/usr.bin/quota/getvfsquota.c
diff -u src/usr.bin/quota/getvfsquota.c:1.3 src/usr.bin/quota/getvfsquota.c:1.4
--- src/usr.bin/quota/getvfsquota.c:1.3	Sun Mar  6 15:47:59 2011
+++ src/usr.bin/quota/getvfsquota.c	Sun Mar  6 17:36:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getvfsquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $ */
+/*	$NetBSD: getvfsquota.c,v 1.4 2011/03/06 22:36:07 christos Exp $ */
 
 /*-
   * Copyright (c) 2011 Manuel Bouyer
@@ -29,7 +29,7 @@
   */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: getvfsquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $");
+__RCSID("$NetBSD: getvfsquota.c,v 1.4 2011/03/06 22:36:07 christos Exp $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -42,9 +42,8 @@
 #include <ufs/ufs/quota2_prop.h>
 #include <sys/quota.h>
 
-#include <getvfsquota.h>
-
-const char *qfextension[] = INITQFNAMES;
+#include "getvfsquota.h"
+#include "quotautil.h"
 
 /* retrieve quotas from vfs, for the given user id */
 int
Index: src/usr.bin/quota/printquota.c
diff -u src/usr.bin/quota/printquota.c:1.3 src/usr.bin/quota/printquota.c:1.4
--- src/usr.bin/quota/printquota.c:1.3	Sun Mar  6 15:47:59 2011
+++ src/usr.bin/quota/printquota.c	Sun Mar  6 17:36:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: printquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $ */
+/*	$NetBSD: printquota.c,v 1.4 2011/03/06 22:36:07 christos Exp $ */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)quota.c	8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: printquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $");
+__RCSID("$NetBSD: printquota.c,v 1.4 2011/03/06 22:36:07 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,7 +59,7 @@
 #include <limits.h>
 #include <inttypes.h>
 
-#include <printquota.h>
+#include "printquota.h"
 
 /*
  * convert 64bit value to a printable string
@@ -138,13 +138,12 @@
 	return buf;
 }
 
-#if 0
 /*
  * Calculate the grace period and return a precise string for it,
  * either in seconds or in format xWyDzHtMuS
  */
 const char *
-timepprt(char *buf, size_t len, time_t seconds, int hflag, int space)
+timepprt(char *buf, size_t len, time_t seconds, int hflag)
 {
 	ssize_t i = 0;
 
@@ -158,7 +157,7 @@
 		seconds = seconds % WEEK;
 	}
 
-	if (remain < 3 || seconds == 0)
+	if (len - i < 3 || seconds == 0)
 		return buf;
 
 	if ((seconds / DAY) > 0) {
@@ -166,7 +165,7 @@
 		seconds = seconds % DAY;
 	}
 
-	if (remain < 4 || seconds == 0)
+	if (len - i < 4 || seconds == 0)
 		return buf;
 
 	if ((seconds / HOUR) > 0) {
@@ -174,7 +173,7 @@
 		seconds = seconds % HOUR;
 	}
 
-	if (remain < 4 || seconds == 0)
+	if (len - i < 4 || seconds == 0)
 		return buf;
 
 	if ((seconds / MINUTE) > 0) {
@@ -183,7 +182,7 @@
 		seconds = seconds % MINUTE;
 	}
 
-	if (remain < 4 || seconds == 0)
+	if (len - i < 4 || seconds == 0)
 		return buf;
 
 	(void)snprintf(buf + i, len - i, "%" PRId64 "S", seconds);
@@ -272,4 +271,3 @@
 		*val = btodb(*val);
 	return ret;
 }
-#endif
Index: src/usr.bin/quota/printquota.h
diff -u src/usr.bin/quota/printquota.h:1.3 src/usr.bin/quota/printquota.h:1.4
--- src/usr.bin/quota/printquota.h:1.3	Sun Mar  6 15:47:59 2011
+++ src/usr.bin/quota/printquota.h	Sun Mar  6 17:36:07 2011
@@ -1,10 +1,7 @@
-/*	$NetBSD: printquota.h,v 1.3 2011/03/06 20:47:59 christos Exp $ */
+/*	$NetBSD: printquota.h,v 1.4 2011/03/06 22:36:07 christos Exp $ */
 
 const char *intprt(char *, size_t, uint64_t, int, int);
 const char *timeprt(char *, size_t, time_t, time_t);
-#if 0
-const char *timepprt(time_t, int, int);
+const char *timepprt(char *, size_t, time_t, int);
 int timeprd(const char *, time_t *);
 int intrd(char *str, uint64_t *val, u_int);
-#endif
-

Index: src/usr.bin/quota/quota.c
diff -u src/usr.bin/quota/quota.c:1.35 src/usr.bin/quota/quota.c:1.36
--- src/usr.bin/quota/quota.c:1.35	Sun Mar  6 15:47:59 2011
+++ src/usr.bin/quota/quota.c	Sun Mar  6 17:36:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: quota.c,v 1.35 2011/03/06 20:47:59 christos Exp $	*/
+/*	$NetBSD: quota.c,v 1.36 2011/03/06 22:36:07 christos Exp $	*/
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)quota.c	8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: quota.c,v 1.35 2011/03/06 20:47:59 christos Exp $");
+__RCSID("$NetBSD: quota.c,v 1.36 2011/03/06 22:36:07 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -76,8 +76,9 @@
 #include <rpc/pmap_prot.h>
 #include <rpcsvc/rquota.h>
 
-#include <printquota.h>
-#include <getvfsquota.h>
+#include "printquota.h"
+#include "quotautil.h"
+#include "getvfsquota.h"
 
 struct quotause {
 	struct	quotause *next;
@@ -88,7 +89,6 @@
 #define	FOUND	0x01
 #define	QUOTA2	0x02
 
-static int	alldigits(const char *);
 static int	callaurpc(const char *, rpcprog_t, rpcvers_t, rpcproc_t,
     xdrproc_t, void *, xdrproc_t, void *);
 static int	getnfsquota(struct statvfs *, struct quotause *, uint32_t, int);
@@ -335,14 +335,14 @@
 	quplist = getprivs(id, type);
 	for (qup = quplist; qup; qup = qup->next) {
 		int ql_stat;
+		struct quota2_val *q = qup->q2e.q2e_val;
 		if (!vflag &&
-		    qup->q2e.q2e_val[QL_BLOCK].q2v_softlimit == UQUAD_MAX &&
-		    qup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit == UQUAD_MAX &&
-		    qup->q2e.q2e_val[QL_FILE].q2v_softlimit == UQUAD_MAX &&
-		    qup->q2e.q2e_val[QL_FILE].q2v_hardlimit == UQUAD_MAX)
+		    q[QL_BLOCK].q2v_softlimit == UQUAD_MAX &&
+		    q[QL_BLOCK].q2v_hardlimit == UQUAD_MAX &&
+		    q[QL_FILE].q2v_softlimit == UQUAD_MAX &&
+		    q[QL_FILE].q2v_hardlimit == UQUAD_MAX)
 			continue;
-		ql_stat = quota2_check_limit(&qup->q2e.q2e_val[QL_FILE],
-		    1, now);
+		ql_stat = quota2_check_limit(&q[QL_FILE], 1, now);
 		switch(QL_STATUS(ql_stat)) {
 		case QL_S_DENY_HARD:
 			msgi = "File limit reached on";
@@ -356,8 +356,7 @@
 		default:
 			msgi = NULL;
 		}
-		ql_stat = quota2_check_limit(&qup->q2e.q2e_val[QL_BLOCK],
-		    1, now);
+		ql_stat = quota2_check_limit(&q[QL_BLOCK], 1, now);
 		switch(QL_STATUS(ql_stat)) {
 		case QL_S_DENY_HARD:
 			msgb = "Block limit reached on";
@@ -381,9 +380,8 @@
 				printf("\t%s %s\n", msgb, qup->fsname);
 			continue;
 		}
-		if (vflag || dflag || msgi || msgb ||
-		    qup->q2e.q2e_val[QL_BLOCK].q2v_cur ||
-		    qup->q2e.q2e_val[QL_FILE].q2v_cur) {
+		if (vflag || dflag || msgi || msgb || q[QL_BLOCK].q2v_cur ||
+		    q[QL_FILE].q2v_cur) {
 			if (lines++ == 0)
 				heading(type, id, name, "");
 			nam = qup->fsname;
@@ -393,46 +391,38 @@
 			} 
 			if (msgb)
 				timemsg = timeprt(b0, 9, now,
-				    qup->q2e.q2e_val[QL_BLOCK].q2v_time);
+				    q[QL_BLOCK].q2v_time);
 			else if ((qup->flags & QUOTA2) != 0 && vflag)
 				timemsg = timeprt(b0, 9, 0,
-				    qup->q2e.q2e_val[QL_BLOCK].q2v_grace);
+				    q[QL_BLOCK].q2v_grace);
 			else
 				timemsg = "";
 				
 			printf("%12s%9s%c%8s%9s%8s",
 			    nam,
-			    intprt(b1, 9,
-			    qup->q2e.q2e_val[QL_BLOCK].q2v_cur,
+			    intprt(b1, 9, q[QL_BLOCK].q2v_cur,
 			    HN_B, hflag),
 			    (msgb == NULL) ? ' ' : '*',
-			    intprt(b2, 9,
-			    qup->q2e.q2e_val[QL_BLOCK].q2v_softlimit,
+			    intprt(b2, 9, q[QL_BLOCK].q2v_softlimit,
 			    HN_B, hflag),
-			    intprt(b3, 9,
-			    qup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit,
+			    intprt(b3, 9, q[QL_BLOCK].q2v_hardlimit,
 			    HN_B, hflag),
 			    timemsg);
 
 			if (msgi)
 				timemsg = timeprt(b0, 9, now, 
-				    qup->q2e.q2e_val[QL_FILE].q2v_time);
+				    q[QL_FILE].q2v_time);
 			else if ((qup->flags & QUOTA2) != 0 && vflag)
 				timemsg = timeprt(b0, 9, 0,
-				    qup->q2e.q2e_val[QL_FILE].q2v_grace);
+				    q[QL_FILE].q2v_grace);
 			else
 				timemsg = "";
 				
 			printf("%8s%c%7s%8s%8s\n",
-			    intprt(b1, 8,
-			    qup->q2e.q2e_val[QL_FILE].q2v_cur, 0, hflag),
+			    intprt(b1, 8, q[QL_FILE].q2v_cur, 0, hflag),
 			    (msgi == NULL) ? ' ' : '*',
-			    intprt(b2, 8,
-			    qup->q2e.q2e_val[QL_FILE].q2v_softlimit,
-			    0, hflag),
-			    intprt(b3, 8,
-			    qup->q2e.q2e_val[QL_FILE].q2v_hardlimit,
-			    0, hflag),
+			    intprt(b2, 8, q[QL_FILE].q2v_softlimit, 0, hflag),
+			    intprt(b3, 8, q[QL_FILE].q2v_hardlimit, 0, hflag),
 			    timemsg);
 			continue;
 		}
@@ -648,16 +638,3 @@
  
 	return (int) clnt_stat;
 }
-
-static int
-alldigits(const char *s)
-{
-	unsigned char c;
-
-	c = *s++;
-	do {
-		if (!isdigit(c))
-			return 0;
-	} while ((c = *s++) != 0);
-	return 1;
-}

Added files:

Index: src/usr.bin/quota/quotautil.c
diff -u /dev/null src/usr.bin/quota/quotautil.c:1.1
--- /dev/null	Sun Mar  6 17:36:07 2011
+++ src/usr.bin/quota/quotautil.c	Sun Mar  6 17:36:07 2011
@@ -0,0 +1,119 @@
+/*	$NetBSD: quotautil.c,v 1.1 2011/03/06 22:36:07 christos Exp $ */
+
+/*
+ * Copyright (c) 1980, 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Robert Elz at The University of Melbourne.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\
+ The Regents of the University of California.  All rights reserved.");
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)quota.c	8.4 (Berkeley) 4/28/95";
+#else
+__RCSID("$NetBSD: quotautil.c,v 1.1 2011/03/06 22:36:07 christos Exp $");
+#endif
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <fstab.h>
+#include <errno.h>
+#include <limits.h>
+#include <inttypes.h>
+
+#include <ufs/ufs/quota2.h>
+#include <ufs/ufs/quota1.h>
+
+#include "quotautil.h"
+
+const char *qfextension[MAXQUOTAS] = INITQFNAMES;
+const char *qfname = QUOTAFILENAME;
+ 
+/*
+ * Check to see if a particular quota is to be enabled.
+ */
+int
+hasquota(char *buf, size_t len, struct fstab *fs, int type)
+{
+	char *opt;
+	char *cp = NULL;
+	static char initname, usrname[100], grpname[100];
+
+	if (!initname) {
+		(void)snprintf(usrname, sizeof(usrname), "%s%s",
+		    qfextension[USRQUOTA], qfname);
+		(void)snprintf(grpname, sizeof(grpname), "%s%s",
+		    qfextension[GRPQUOTA], qfname);
+		initname = 1;
+	}
+	strlcpy(buf, fs->fs_mntops, len);
+	for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
+		if ((cp = strchr(opt, '=')) != NULL)
+			*cp++ = '\0';
+		if (type == USRQUOTA && strcmp(opt, usrname) == 0)
+			break;
+		if (type == GRPQUOTA && strcmp(opt, grpname) == 0)
+			break;
+	}
+	if (!opt)
+		return 0;
+	if (cp) {
+		strlcpy(buf, cp, len);
+		return 1;
+	}
+	(void)snprintf(buf, len, "%s/%s.%s", fs->fs_file, qfname,
+	    qfextension[type]);
+	return 1;
+}
+
+int
+alldigits(const char *s)
+{
+	unsigned char c;
+
+	c = *s++;
+	do {
+		if (!isdigit(c))
+			return 0;
+	} while ((c = *s++) != 0);
+	return 1;
+}
Index: src/usr.bin/quota/quotautil.h
diff -u /dev/null src/usr.bin/quota/quotautil.h:1.1
--- /dev/null	Sun Mar  6 17:36:07 2011
+++ src/usr.bin/quota/quotautil.h	Sun Mar  6 17:36:07 2011
@@ -0,0 +1,7 @@
+/*	$NetBSD: quotautil.h,v 1.1 2011/03/06 22:36:07 christos Exp $ */
+
+const char *qfextension[MAXQUOTAS];
+const char *qfname;
+struct fstab;
+int hasquota(char *, size_t, struct fstab *, int);
+int alldigits(const char *);

Reply via email to