summaryrefslogtreecommitdiffstats
path: root/usr.sbin/edquota
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2009-02-05 14:06:43 +0000
committermckusick <mckusick@FreeBSD.org>2009-02-05 14:06:43 +0000
commitbe3f4e53a7008d1f7bcccee63364ad886523f523 (patch)
tree86f82b417a3e5470900040112d9b69009cfa73ba /usr.sbin/edquota
parent21c39c52cea3a2dccab11d37f1967c9666ed749e (diff)
downloadFreeBSD-src-be3f4e53a7008d1f7bcccee63364ad886523f523.zip
FreeBSD-src-be3f4e53a7008d1f7bcccee63364ad886523f523.tar.gz
Updates to edquota based on feedback from Dag-Erling Smorgrav.
Diffstat (limited to 'usr.sbin/edquota')
-rw-r--r--usr.sbin/edquota/Makefile2
-rw-r--r--usr.sbin/edquota/edquota.815
-rw-r--r--usr.sbin/edquota/edquota.c91
3 files changed, 67 insertions, 41 deletions
diff --git a/usr.sbin/edquota/Makefile b/usr.sbin/edquota/Makefile
index b622212..1196e47 100644
--- a/usr.sbin/edquota/Makefile
+++ b/usr.sbin/edquota/Makefile
@@ -4,7 +4,7 @@
PROG= edquota
MAN= edquota.8
-CSTD= c99
+CSTD= gnu99
WARNS?= 4
DPADD= ${LIBUTIL}
diff --git a/usr.sbin/edquota/edquota.8 b/usr.sbin/edquota/edquota.8
index 9c90de4..326c837 100644
--- a/usr.sbin/edquota/edquota.8
+++ b/usr.sbin/edquota/edquota.8
@@ -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
diff --git a/usr.sbin/edquota/edquota.c b/usr.sbin/edquota/edquota.c
index 2798d8a..3331548 100644
--- a/usr.sbin/edquota/edquota.c
+++ b/usr.sbin/edquota/edquota.c
@@ -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 outfd, char *name, int quotatype)
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 *inname)
{
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 *inname)
}
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 *inname)
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;
}
OpenPOWER on IntegriCloud