Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Feb 2009 14:06:44 +0000 (UTC)
From:      Kirk McKusick <mckusick@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r188145 - projects/quota64/usr.sbin/edquota
Message-ID:  <200902051406.n15E6ivu028774@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mckusick
Date: Thu Feb  5 14:06:43 2009
New Revision: 188145
URL: http://svn.freebsd.org/changeset/base/188145

Log:
  Updates to edquota based on feedback from Dag-Erling Smorgrav.

Modified:
  projects/quota64/usr.sbin/edquota/Makefile
  projects/quota64/usr.sbin/edquota/edquota.8
  projects/quota64/usr.sbin/edquota/edquota.c

Modified: projects/quota64/usr.sbin/edquota/Makefile
==============================================================================
--- projects/quota64/usr.sbin/edquota/Makefile	Thu Feb  5 14:06:09 2009	(r188144)
+++ projects/quota64/usr.sbin/edquota/Makefile	Thu Feb  5 14:06:43 2009	(r188145)
@@ -4,7 +4,7 @@
 PROG=	edquota
 MAN=	edquota.8
 
-CSTD=	c99
+CSTD=	gnu99
 WARNS?=	4
 
 DPADD=	${LIBUTIL}

Modified: projects/quota64/usr.sbin/edquota/edquota.8
==============================================================================
--- projects/quota64/usr.sbin/edquota/edquota.8	Thu Feb  5 14:06:09 2009	(r188144)
+++ projects/quota64/usr.sbin/edquota/edquota.8	Thu Feb  5 14:06:43 2009	(r188145)
@@ -39,10 +39,9 @@
 .Nd edit user quotas
 .Sh SYNOPSIS
 .Nm
-.Op Fl u
+.Op Fl uh
 .Op Fl f Ar fspath
 .Op Fl p Ar proto-username
-.Op Fl h
 .Ar username ...
 .Nm
 .Op Fl u
@@ -54,9 +53,9 @@
 .Ar username ...
 .Nm
 .Fl g
+.Op Fl h
 .Op Fl f Ar fspath
 .Op Fl p Ar proto-groupname
-.Op Fl h
 .Ar groupname ...
 .Nm
 .Fl g
@@ -100,8 +99,11 @@ specifies otherwise.
 .Pp
 The quotas may then be modified, new quotas added, etc.
 Block quotas can be specified in bytes (B), kilobytes (K),
-megabytes (M), terabytes (T), pedabytes (P), or exabytes (E).
+megabytes (M), terabytes (T), petabytes (P), or exabytes (E).
 If no units are specified, kilobytes are assumed.
+Inode quotas can be specified in kiloinodes (K),
+megainodes (M), terainodes (T), petainodes (P), or exainodes (E).
+If no units are specified, the number of inodes specified are used.
 If the
 .Fl h
 flag is specified, the editor will always display the 
@@ -170,8 +172,11 @@ and
 values is omitted, it is assumed to be zero, therefore
 indicating that no particular quota should be imposed.
 Block quotas can be specified in bytes (B), kilobytes (K),
-megabytes (M), terabytes (T), pedabytes (P), or exabytes (E).
+megabytes (M), terabytes (T), petabytes (P), or exabytes (E).
 If no units are specified, kilobytes are assumed.
+Inode quotas can be specified in kiloinodes (K),
+megainodes (M), terainodes (T), petainodes (P), or exainodes (E).
+If no units are specified, the number of inodes specified are used.
 .Pp
 If invoked with the
 .Fl f

Modified: projects/quota64/usr.sbin/edquota/edquota.c
==============================================================================
--- projects/quota64/usr.sbin/edquota/edquota.c	Thu Feb  5 14:06:09 2009	(r188144)
+++ projects/quota64/usr.sbin/edquota/edquota.c	Thu Feb  5 14:06:43 2009	(r188145)
@@ -158,13 +158,11 @@ main(int argc, char *argv[])
 			tflag++;
 			break;
 		case 'e':
-			if ((qup = malloc(sizeof(*qup) + BUFSIZ)) == NULL)
+			if ((qup = calloc(1, sizeof(*qup) + BUFSIZ)) == NULL)
 				errx(2, "out of memory");
-			bzero(qup, sizeof(*qup) + BUFSIZ);
-			i = 0;
 			oldoptarg = optarg;
-			for (cp = optarg; (cp = strsep(&optarg, ":")) != NULL;
-			    i++) {
+			for (i = 0, cp = optarg;
+			     (cp = strsep(&optarg, ":")) != NULL; i++) {
 				if (cp != oldoptarg)
 					*(cp - 1) = ':';
 				switch (i) {
@@ -183,12 +181,14 @@ main(int argc, char *argv[])
 						cvtval(lim, *endpt);
 					continue;
 				case 3:
+					lim = strtoll(cp, &endpt, 10);
 					qup->dqblk.dqb_isoftlimit =
-						strtoll(cp, NULL, 10);
+						cvtval(lim, *endpt);
 					continue;
 				case 4:
+					lim = strtoll(cp, &endpt, 10);
 					qup->dqblk.dqb_ihardlimit =
-						strtoll(cp, NULL, 10);
+						cvtval(lim, *endpt);
 					continue;
 				default:
 					warnx("incorrect quota specification: "
@@ -300,10 +300,10 @@ static void
 usage(void)
 {
 	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
-		"usage: edquota [-u] [-f fspath] [-p username] [-h] username ...",
+		"usage: edquota [-uh] [-f fspath] [-p username] username ...",
 		"       edquota [-u] -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]",
 		"               username ...",
-		"       edquota -g [-f fspath] [-p groupname] [-h] groupname ...",
+		"       edquota -g [-h] [-f fspath] [-p groupname] groupname ...",
 		"       edquota -g -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]",
 		"               groupname ...",
 		"       edquota [-u] -t [-f fspath]",
@@ -536,14 +536,14 @@ writeprivs(struct quotause *quplist, int
 char *
 fmthumanval(int64_t blocks)
 {
-	static char buf[7], numbuf[20];
+	static char numbuf[20];
 
 	if (hflag) {
-		humanize_number(buf, sizeof(buf) - (blocks < 0 ? 0 : 1),
+		humanize_number(numbuf, sizeof(numbuf) - (blocks < 0 ? 0 : 1),
 		    dbtob(blocks), "", HN_AUTOSCALE, HN_NOSPACE);
-		return (buf);
+		return (numbuf);
 	}
-	snprintf(numbuf, 20, "%lluK", dbtokb(blocks));
+	snprintf(numbuf, sizeof(numbuf), "%lluk", dbtokb(blocks));
 	return(numbuf);
 }
 
@@ -555,9 +555,8 @@ readprivs(struct quotause *quplist, char
 {
 	struct quotause *qup;
 	FILE *fd;
-	u_int64_t ihardlimit, isoftlimit, curinodes;
-	u_int64_t bhardlimit, bsoftlimit, curblocks;
-	char bhardunits, bsoftunits, curblockunits;
+	u_int64_t hardlimit, softlimit, curitems;
+	char hardunits, softunits, curitemunits;
 	int cnt;
 	char *cp;
 	struct dqblk dqblk;
@@ -584,47 +583,66 @@ readprivs(struct quotause *quplist, char
 		}
 		cnt = sscanf(cp,
 		    " in use: %llu%c, limits (soft = %llu%c, hard = %llu%c)",
-		    &curblocks, &curblockunits, &bsoftlimit, &bsoftunits,
-		    &bhardlimit, &bhardunits);
+		    &curitems, &curitemunits, &softlimit, &softunits,
+		    &hardlimit, &hardunits);
 		/*
 		 * The next three check for old-style input formats.
 		 */
 		if (cnt != 6)
 			cnt = sscanf(cp,
 			 " in use: %llu%c, limits (soft = %llu%c hard = %llu%c",
-			    &curblocks, &curblockunits, &bsoftlimit,
-			    &bsoftunits, &bhardlimit, &bhardunits);
+			    &curitems, &curitemunits, &softlimit,
+			    &softunits, &hardlimit, &hardunits);
 		if (cnt != 6)
 			cnt = sscanf(cp,
 			" in use: %llu%c, limits (soft = %llu%c hard = %llu%c)",
-			    &curblocks, &curblockunits, &bsoftlimit,
-			    &bsoftunits, &bhardlimit, &bhardunits);
+			    &curitems, &curitemunits, &softlimit,
+			    &softunits, &hardlimit, &hardunits);
 		if (cnt != 6)
 			cnt = sscanf(cp,
 			" in use: %llu%c, limits (soft = %llu%c, hard = %llu%c",
-			    &curblocks, &curblockunits, &bsoftlimit,
-			    &bsoftunits, &bhardlimit, &bhardunits);
+			    &curitems, &curitemunits, &softlimit,
+			    &softunits, &hardlimit, &hardunits);
 		if (cnt != 6) {
 			warnx("%s:%s: bad format", fsp, cp);
 			return (0);
 		}
-		dqblk.dqb_curblocks = cvtval(curblocks, curblockunits);
-		dqblk.dqb_bsoftlimit = cvtval(bsoftlimit, bsoftunits);
-		dqblk.dqb_bhardlimit = cvtval(bhardlimit, bhardunits);
+		dqblk.dqb_curblocks = cvtval(curitems, curitemunits);
+		dqblk.dqb_bsoftlimit = cvtval(softlimit, softunits);
+		dqblk.dqb_bhardlimit = cvtval(hardlimit, hardunits);
 		if ((cp = strtok(line2, "\n")) == NULL) {
 			warnx("%s: %s: bad format", fsp, line2);
 			return (0);
 		}
 		cnt = sscanf(cp,
-		    "\tinodes in use: %llu, limits (soft = %llu, hard = %llu)",
-		    &curinodes, &isoftlimit, &ihardlimit);
+		    " in use: %llu%c, limits (soft = %llu%c, hard = %llu%c)",
+		    &curitems, &curitemunits, &softlimit,
+		    &softunits, &hardlimit, &hardunits);
+		/*
+		 * The next three check for old-style input formats.
+		 */
+		if (cnt != 6)
+			cnt = sscanf(cp,
+			 " in use: %llu%c, limits (soft = %llu%c hard = %llu%c",
+			    &curitems, &curitemunits, &softlimit,
+			    &softunits, &hardlimit, &hardunits);
+		if (cnt != 6)
+			cnt = sscanf(cp,
+			" in use: %llu%c, limits (soft = %llu%c hard = %llu%c)",
+			    &curitems, &curitemunits, &softlimit,
+			    &softunits, &hardlimit, &hardunits);
+		if (cnt != 6)
+			cnt = sscanf(cp,
+			" in use: %llu%c, limits (soft = %llu%c, hard = %llu%c",
+			    &curitems, &curitemunits, &softlimit,
+			    &softunits, &hardlimit, &hardunits);
 		if (cnt != 3) {
 			warnx("%s: %s: bad format", fsp, line2);
 			return (0);
 		}
-		dqblk.dqb_curinodes = curinodes;
-		dqblk.dqb_isoftlimit = isoftlimit;
-		dqblk.dqb_ihardlimit = ihardlimit;
+		dqblk.dqb_curinodes = cvtval(curitems, curitemunits);
+		dqblk.dqb_isoftlimit = cvtval(softlimit, softunits);
+		dqblk.dqb_ihardlimit = cvtval(hardlimit, hardunits);
 		for (qup = quplist; qup; qup = qup->next) {
 			if (strcmp(fsp, qup->fsname))
 				continue;
@@ -651,8 +669,8 @@ readprivs(struct quotause *quplist, char
 			qup->dqblk.dqb_isoftlimit = dqblk.dqb_isoftlimit;
 			qup->dqblk.dqb_ihardlimit = dqblk.dqb_ihardlimit;
 			qup->flags |= FOUND;
-			/* No easy way to check change in curblocks */
-			if (dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes)
+			if (dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks &&
+			    dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes)
 				break;
 			warnx("%s: cannot change current allocation", fsp);
 			break;
@@ -853,8 +871,11 @@ cvtval(u_int64_t limit, char units)
 	case 'e':
 		limit *= btodb(1152921504606846976);
 		break;
+	case ' ':
+		errx(2, "No space permitted between value and units\n");
+		break;
 	default:
-		warnx("%llu%c: unknown units, specify K, M, G, T, P, or E\n",
+		errx(2, "%llu%c: unknown units, specify K, M, G, T, P, or E\n",
 		    limit, units);
 		break;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902051406.n15E6ivu028774>