Module Name: src
Committed By: bouyer
Date: Sun Jan 30 00:26:03 UTC 2011
Modified Files:
src/usr.sbin/edquota [bouyer-quota2]: Makefile edquota.c
Log Message:
Convert to new quotactl()
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.5.64.1 src/usr.sbin/edquota/Makefile
cvs rdiff -u -r1.29 -r1.29.16.1 src/usr.sbin/edquota/edquota.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.sbin/edquota/Makefile
diff -u src/usr.sbin/edquota/Makefile:1.5 src/usr.sbin/edquota/Makefile:1.5.64.1
--- src/usr.sbin/edquota/Makefile:1.5 Sat Mar 8 08:01:26 1997
+++ src/usr.sbin/edquota/Makefile Sun Jan 30 00:26:03 2011
@@ -1,7 +1,18 @@
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
-# $NetBSD: Makefile,v 1.5 1997/03/08 08:01:26 mikel Exp $
+# $NetBSD: Makefile,v 1.5.64.1 2011/01/30 00:26:03 bouyer Exp $
+.include <bsd.own.mk>
PROG= edquota
+SRCS= edquota.c
MAN= edquota.8
+CPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
+DPADD= ${LIBPROP}
+LDADD= -lprop
+
+.PATH: ${NETBSDSRCDIR}/usr.bin/quota
+SRCS+= getvfsquota.c
+.PATH: ${NETBSDSRCDIR}/sys/ufs/ufs
+SRCS+= quota2_prop.c quota1_subr.c
+
.include <bsd.prog.mk>
Index: src/usr.sbin/edquota/edquota.c
diff -u src/usr.sbin/edquota/edquota.c:1.29 src/usr.sbin/edquota/edquota.c:1.29.16.1
--- src/usr.sbin/edquota/edquota.c:1.29 Mon Jul 21 13:36:58 2008
+++ src/usr.sbin/edquota/edquota.c Sun Jan 30 00:26:03 2011
@@ -1,3 +1,5 @@
+/* $NetBSD: edquota.c,v 1.29.16.1 2011/01/30 00:26:03 bouyer Exp $ */
+
/*
* Copyright (c) 1980, 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -40,7 +42,7 @@
#if 0
static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95";
#else
-__RCSID("$NetBSD: edquota.c,v 1.29 2008/07/21 13:36:58 lukem Exp $");
+__RCSID("$NetBSD: edquota.c,v 1.29.16.1 2011/01/30 00:26:03 bouyer Exp $");
#endif
#endif /* not lint */
@@ -52,7 +54,14 @@
#include <sys/file.h>
#include <sys/wait.h>
#include <sys/queue.h>
-#include <ufs/ufs/quota.h>
+#include <sys/types.h>
+#include <sys/statvfs.h>
+
+#include <ufs/ufs/quota2_prop.h>
+#include <ufs/ufs/quota1.h>
+#include <sys/quota.h>
+
+#include <assert.h>
#include <err.h>
#include <errno.h>
#include <fstab.h>
@@ -64,40 +73,53 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+
+#include <printquota.h>
+#include <getvfsquota.h>
+
#include "pathnames.h"
const char *qfname = QUOTAFILENAME;
-const char *qfextension[] = INITQFNAMES;
const char *quotagroup = QUOTAGROUP;
char tmpfil[] = _PATH_TMP;
struct quotause {
struct quotause *next;
long flags;
- struct dqblk dqblk;
+ struct quota2_entry q2e;
char fsname[MAXPATHLEN + 1];
- char qfname[1]; /* actually longer */
+ char *qfname;
};
#define FOUND 0x01
+#define QUOTA2 0x02
+#define DEFAULT 0x04
#define MAX_TMPSTR (100+MAXPATHLEN)
-int main __P((int, char **));
-void usage __P((void));
-int getentry __P((const char *, int));
-struct quotause *
- getprivs __P((long, int, char *));
-void putprivs __P((long, int, struct quotause *));
-int editit __P((char *));
-int writeprivs __P((struct quotause *, int, char *, int));
-int readprivs __P((struct quotause *, int));
-int writetimes __P((struct quotause *, int, int));
-int readtimes __P((struct quotause *, int));
-char * cvtstoa __P((time_t));
-int cvtatos __P((time_t, char *, time_t *));
-void freeprivs __P((struct quotause *));
-int alldigits __P((const char *));
-int hasquota __P((struct fstab *, int, char **));
+int main(int, char **);
+void usage(void);
+int getentry(const char *, int);
+struct quotause * getprivs(long, int, const char *, int);
+struct quotause * getprivs2(long, int, const char *, int);
+struct quotause * getprivs1(long, int, const char *);
+void putprivs(long, int, struct quotause *);
+void putprivs2(long, int, struct quotause *);
+void putprivs1(long, int, struct quotause *);
+int editit(char *);
+int writeprivs(struct quotause *, int, char *, int);
+int readprivs(struct quotause *, int);
+int writetimes(struct quotause *, int, int);
+int readtimes(struct quotause *, int);
+char * cvtstoa(time_t);
+int cvtatos(time_t, char *, time_t *);
+void freeq(struct quotause *);
+void freeprivs(struct quotause *);
+int alldigits(const char *);
+int hasquota(struct fstab *, int, char **);
+
+int Hflag = 0;
+int Dflag = 0;
+int dflag = 0;
int
main(argc, argv)
@@ -119,8 +141,17 @@
errx(1, "permission denied");
protoname = NULL;
quotatype = USRQUOTA;
- while ((ch = getopt(argc, argv, "ugtp:s:h:f:")) != -1) {
+ while ((ch = getopt(argc, argv, "DHdugtp:s:h:f:")) != -1) {
switch(ch) {
+ case 'D':
+ Dflag++;
+ break;
+ case 'H':
+ Hflag++;
+ break;
+ case 'd':
+ dflag++;
+ break;
case 'p':
protoname = optarg;
pflag++;
@@ -149,15 +180,16 @@
}
argc -= optind;
argv += optind;
+
if (pflag) {
- if (soft || hard)
+ if (soft || hard || dflag)
usage();
if ((protoid = getentry(protoname, quotatype)) == -1)
exit(1);
- protoprivs = getprivs(protoid, quotatype, fs);
+ protoprivs = getprivs(protoid, quotatype, fs, 0);
for (qup = protoprivs; qup; qup = qup->next) {
- qup->dqblk.dqb_btime = 0;
- qup->dqblk.dqb_itime = 0;
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_time = 0;
+ qup->q2e.q2e_val[Q2V_FILE].q2v_time = 0;
}
while (argc-- > 0) {
if ((id = getentry(*argv++, quotatype)) < 0)
@@ -181,30 +213,44 @@
usage();
hardb = btodb((u_quad_t)hardb * 1024);
}
+ if (dflag) {
+ curprivs = getprivs(0, quotatype, fs, 1);
+ for (lqup = curprivs; lqup; lqup = lqup->next) {
+ if (soft) {
+ lqup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit = softb;
+ lqup->q2e.q2e_val[Q2V_FILE].q2v_softlimit = softi;
+ }
+ if (hard) {
+ lqup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit = hardb;
+ lqup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit = hardi;
+ }
+ }
+ putprivs(0, quotatype, curprivs);
+ freeprivs(curprivs);
+ exit(0);
+ }
for ( ; argc > 0; argc--, argv++) {
if ((id = getentry(*argv, quotatype)) == -1)
continue;
- curprivs = getprivs(id, quotatype, fs);
+ curprivs = getprivs(id, quotatype, fs, 0);
for (lqup = curprivs; lqup; lqup = lqup->next) {
if (soft) {
if (softb &&
- lqup->dqblk.dqb_curblocks >= softb &&
- (lqup->dqblk.dqb_bsoftlimit == 0 ||
- lqup->dqblk.dqb_curblocks <
- lqup->dqblk.dqb_bsoftlimit))
- lqup->dqblk.dqb_btime = 0;
+ lqup->q2e.q2e_val[Q2V_BLOCK].q2v_cur >= softb &&
+ (lqup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit == 0 ||
+ lqup->q2e.q2e_val[Q2V_BLOCK].q2v_cur < lqup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit))
+ lqup->q2e.q2e_val[Q2V_BLOCK].q2v_time = 0;
if (softi &&
- lqup->dqblk.dqb_curinodes >= softi &&
- (lqup->dqblk.dqb_isoftlimit == 0 ||
- lqup->dqblk.dqb_curinodes <
- lqup->dqblk.dqb_isoftlimit))
- lqup->dqblk.dqb_itime = 0;
- lqup->dqblk.dqb_bsoftlimit = softb;
- lqup->dqblk.dqb_isoftlimit = softi;
+ lqup->q2e.q2e_val[Q2V_FILE].q2v_cur >= softb &&
+ (lqup->q2e.q2e_val[Q2V_FILE].q2v_softlimit == 0 ||
+ lqup->q2e.q2e_val[Q2V_FILE].q2v_cur < lqup->q2e.q2e_val[Q2V_FILE].q2v_softlimit))
+ lqup->q2e.q2e_val[Q2V_FILE].q2v_time = 0;
+ lqup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit = softb;
+ lqup->q2e.q2e_val[Q2V_FILE].q2v_softlimit = softi;
}
if (hard) {
- lqup->dqblk.dqb_bhardlimit = hardb;
- lqup->dqblk.dqb_ihardlimit = hardi;
+ lqup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit = hardb;
+ lqup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit = hardi;
}
}
putprivs(id, quotatype, curprivs);
@@ -217,7 +263,7 @@
if (tflag) {
if (soft || hard)
usage();
- protoprivs = getprivs(0, quotatype, fs);
+ protoprivs = getprivs(0, quotatype, fs, 0);
if (writetimes(protoprivs, tmpfd, quotatype) == 0)
exit(1);
if (editit(tmpfil) && readtimes(protoprivs, tmpfd))
@@ -225,10 +271,17 @@
freeprivs(protoprivs);
exit(0);
}
+ if (dflag) {
+ curprivs = getprivs(0, quotatype, fs, 1);
+ if (writeprivs(curprivs, tmpfd, NULL, quotatype) &&
+ editit(tmpfil) && readprivs(curprivs, tmpfd))
+ putprivs(0, quotatype, curprivs);
+ freeprivs(curprivs);
+ }
for ( ; argc > 0; argc--, argv++) {
if ((id = getentry(*argv, quotatype)) == -1)
continue;
- curprivs = getprivs(id, quotatype, fs);
+ curprivs = getprivs(id, quotatype, fs, 0);
if (writeprivs(curprivs, tmpfd, *argv, quotatype) == 0)
continue;
if (editit(tmpfil) && readprivs(curprivs, tmpfd))
@@ -244,12 +297,13 @@
usage()
{
fprintf(stderr,
- "usage: edquota [-u] [-p username] [-f filesystem] username ...\n"
- "\tedquota -g [-p groupname] [-f filesystem] groupname ...\n"
- "\tedquota [-u] [-f filesystem] [-s b#/i#] [-h b#/i#] username ...\n"
- "\tedquota -g [-f filesystem] [-s b#/i#] [-h b#/i#] groupname ...\n"
- "\tedquota [-u] [-f filesystem] -t\n"
- "\tedquota -g [-f filesystem] -t\n"
+ "usage:\n"
+ " edquota [-D] [-H] [-u] [-p username] [-f filesystem] [-d] username ...\n"
+ " edquota [-D] [-H] -g [-p groupname] [-f filesystem] [-d] groupname ...\n"
+ " edquota [-D] [-H] [-u] [-f filesystem] [-s b#/i#] [-h b#/i#] [-d] username ...\n"
+ " edquota [-D] [-H] -g [-f filesystem] [-s b#/i#] [-h b#/i#] [-d] groupname ...\n"
+ " edquota [-D] [-H] [-u] [-f filesystem] -t\n"
+ " edquota [-D] [-H] -g [-f filesystem] -t\n"
);
exit(1);
}
@@ -292,78 +346,40 @@
* Collect the requested quota information.
*/
struct quotause *
-getprivs(id, quotatype, filesys)
- long id;
- int quotatype;
- char *filesys;
+getprivs(long id, int quotatype, const char *filesys, int defaultq)
{
- struct fstab *fs;
- struct quotause *qup, *quptail;
- struct quotause *quphead;
- int qcmd, qupsize, fd;
- char *qfpathname;
- static int warned = 0;
-
- setfsent();
- quptail = NULL;
- quphead = (struct quotause *)0;
- qcmd = QCMD(Q_GETQUOTA, quotatype);
- while ((fs = getfsent()) != NULL) {
- if (strcmp(fs->fs_vfstype, "ffs"))
- continue;
- if (filesys && strcmp(fs->fs_spec, filesys) != 0 &&
- strcmp(fs->fs_file, filesys) != 0)
+ struct statvfs *fst;
+ int nfst, i;
+ struct quotause *qup, *quptail = NULL;
+ struct quotause *quphead = NULL;
+
+ nfst = getmntinfo(&fst, MNT_WAIT);
+ if (nfst == 0)
+ errx(2, "no filesystems mounted!");
+
+ for (i = 0; i < nfst; i++) {
+ if (strcmp(fst[i].f_fstypename, "ffs") != 0 ||
+ (fst[i].f_flag & ST_QUOTA) == 0)
continue;
- if (!hasquota(fs, quotatype, &qfpathname))
+ if (filesys && strcmp(fst[i].f_mntonname, filesys) != 0 &&
+ strcmp(fst[i].f_mntfromname, filesys) != 0)
continue;
- qupsize = sizeof(*qup) + strlen(qfpathname);
- if ((qup = (struct quotause *)malloc(qupsize)) == NULL)
- errx(2, "out of memory");
- if (quotactl(fs->fs_file, qcmd, id, &qup->dqblk) != 0) {
- if (errno == EOPNOTSUPP && !warned) {
- warned++;
- warnx(
- "Quotas are not compiled into this kernel");
- sleep(3);
- }
- if ((fd = open(qfpathname, O_RDONLY)) < 0) {
- fd = open(qfpathname, O_RDWR|O_CREAT, 0640);
- if (fd < 0 && errno != ENOENT) {
- warnx("open `%s'", qfpathname);
- free(qup);
- continue;
- }
- warnx("Creating quota file %s", qfpathname);
- sleep(3);
- (void) fchown(fd, getuid(),
- getentry(quotagroup, GRPQUOTA));
- (void) fchmod(fd, 0640);
- }
- (void)lseek(fd, (off_t)(id * sizeof(struct dqblk)),
- SEEK_SET);
- switch (read(fd, &qup->dqblk, sizeof(struct dqblk))) {
- case 0: /* EOF */
- /*
- * Convert implicit 0 quota (EOF)
- * into an explicit one (zero'ed dqblk)
- */
- memset((caddr_t)&qup->dqblk, 0,
- sizeof(struct dqblk));
- break;
-
- case sizeof(struct dqblk): /* OK */
- break;
+ qup = getprivs2(id, quotatype, fst[i].f_mntonname, defaultq);
+ if (qup == NULL)
+ return NULL;
+ if (quphead == NULL)
+ quphead = qup;
+ else
+ quptail->next = qup;
+ quptail = qup;
+ qup->next = 0;
+ }
- default: /* ERROR */
- warn("read error in `%s'", qfpathname);
- close(fd);
- free(qup);
- continue;
- }
- close(fd);
- }
- strcpy(qup->qfname, qfpathname);
- strcpy(qup->fsname, fs->fs_file);
+ if (filesys) {
+ if (defaultq)
+ errx(1, "no default quota for version 1");
+ /* if we get there, filesys is not mounted. try the old way */
+ qup = getprivs1(id, quotatype, filesys);
if (quphead == NULL)
quphead = qup;
else
@@ -371,37 +387,204 @@
quptail = qup;
qup->next = 0;
}
+ return quphead;
+}
+
+struct quotause *
+getprivs2(long id, int quotatype, const char *filesys, int defaultq)
+{
+ struct quotause *qup;
+ if ((qup = (struct quotause *)malloc(sizeof(*qup))) == NULL)
+ errx(2, "out of memory");
+ qup->qfname = NULL;
+ strcpy(qup->fsname, filesys);
+ qup->flags |= QUOTA2;
+ if (defaultq)
+ qup->flags |= DEFAULT;
+ if (!getvfsquota(filesys, &qup->q2e, id, quotatype, defaultq, Dflag)) {
+ /* no entry, get default entry */
+ if (!getvfsquota(filesys, &qup->q2e, id, quotatype, 1, Dflag))
+ return NULL;
+ }
+ return qup;
+}
+
+struct quotause *
+getprivs1(long id, int quotatype, const char *filesys)
+{
+ struct fstab *fs;
+ char *qfpathname;
+ struct quotause *qup;
+ struct dqblk dqblk;
+ int fd;
+
+ setfsent();
+ while ((fs = getfsent()) != NULL) {
+ if (strcmp(fs->fs_vfstype, "ffs"))
+ continue;
+ if (strcmp(fs->fs_spec, filesys) == 0 ||
+ strcmp(fs->fs_file, filesys) == 0)
+ break;
+ }
+ if (fs == NULL)
+ return NULL;
+
+ if (!hasquota(fs, quotatype, &qfpathname))
+ return NULL;
+ if ((qup = (struct quotause *)malloc(sizeof(*qup))) == NULL)
+ errx(2, "out of memory");
+ strcpy(qup->fsname, fs->fs_file);
+ if ((fd = open(qfpathname, O_RDONLY)) < 0) {
+ fd = open(qfpathname, O_RDWR|O_CREAT, 0640);
+ if (fd < 0 && errno != ENOENT) {
+ warnx("open `%s'", qfpathname);
+ freeq(qup);
+ return NULL;
+ }
+ warnx("Creating quota file %s", qfpathname);
+ sleep(3);
+ (void) fchown(fd, getuid(),
+ getentry(quotagroup, GRPQUOTA));
+ (void) fchmod(fd, 0640);
+ }
+ (void)lseek(fd, (off_t)(id * sizeof(struct dqblk)),
+ SEEK_SET);
+ switch (read(fd, &dqblk, sizeof(struct dqblk))) {
+ case 0: /* EOF */
+ /*
+ * Convert implicit 0 quota (EOF)
+ * into an explicit one (zero'ed dqblk)
+ */
+ memset((caddr_t)&dqblk, 0,
+ sizeof(struct dqblk));
+ break;
+
+ case sizeof(struct dqblk): /* OK */
+ break;
+
+ default: /* ERROR */
+ warn("read error in `%s'", qfpathname);
+ close(fd);
+ freeq(qup);
+ return NULL;
+ }
+ close(fd);
+ qup->qfname = qfpathname;
endfsent();
- return (quphead);
+ dqblk2q2e(&dqblk, &qup->q2e);
+ return (qup);
}
/*
* Store the requested quota information.
*/
void
-putprivs(id, quotatype, quplist)
- long id;
- int quotatype;
- struct quotause *quplist;
+putprivs(long id, int quotatype, struct quotause *quplist)
{
struct quotause *qup;
- int qcmd, fd;
- qcmd = QCMD(Q_SETQUOTA, quotatype);
- for (qup = quplist; qup; qup = qup->next) {
- if (quotactl(qup->fsname, qcmd, id, &qup->dqblk) == 0)
- continue;
- if ((fd = open(qup->qfname, O_WRONLY)) < 0) {
- warnx("open `%s'", qup->qfname);
- } else {
- (void)lseek(fd,
- (off_t)(id * (long)sizeof (struct dqblk)),
- SEEK_SET);
- if (write(fd, &qup->dqblk, sizeof (struct dqblk)) !=
- sizeof (struct dqblk))
- warnx("writing `%s'", qup->qfname);
- close(fd);
- }
+ for (qup = quplist; qup; qup = qup->next) {
+ if (qup->flags & QUOTA2)
+ putprivs2(id, quotatype, qup);
+ else
+ putprivs1(id, quotatype, qup);
+ }
+}
+
+void
+putprivs2(long id, int quotatype, struct quotause *qup)
+{
+
+ prop_dictionary_t dict, data, cmd;
+ prop_array_t cmds, datas;
+ struct plistref pref;
+ int error;
+ int8_t error8;
+
+ qup->q2e.q2e_uid = id;
+ data = q2etoprop(&qup->q2e, (qup->flags & DEFAULT) ? 1 : 0);
+
+ if (data == NULL)
+ err(1, "q2etoprop(id)");
+
+ dict = quota2_prop_create();
+ cmds = prop_array_create();
+ datas = prop_array_create();
+
+ if (dict == NULL || cmds == NULL || datas == NULL) {
+ errx(1, "can't allocate proplist");
+ }
+
+ if (!prop_array_add_and_rel(datas, data))
+ err(1, "prop_array_add(data)");
+
+ if (!quota2_prop_add_command(cmds, "set",
+ qfextension[quotatype], datas))
+ err(1, "prop_add_command");
+ if (!prop_dictionary_set(dict, "commands", cmds))
+ err(1, "prop_dictionary_set(command)");
+ if (Dflag)
+ printf("message to kernel:\n%s\n",
+ prop_dictionary_externalize(dict));
+
+ if (!prop_dictionary_send_syscall(dict, &pref))
+ err(1, "prop_dictionary_send_syscall");
+ prop_object_release(dict);
+
+ if (quotactl(qup->fsname, &pref) != 0)
+ err(1, "quotactl");
+
+ if ((error = prop_dictionary_recv_syscall(&pref, &dict)) != 0) {
+ errx(1, "prop_dictionary_recv_syscall: %s\n",
+ strerror(error));
+ }
+
+ if (Dflag)
+ printf("reply from kernel:\n%s\n",
+ prop_dictionary_externalize(dict));
+
+ if ((error = quota2_get_cmds(dict, &cmds)) != 0) {
+ errx(1, "quota2_get_cmds: %s\n",
+ strerror(error));
+ }
+ /* only one command, no need to iter */
+ cmd = prop_array_get(cmds, 0);
+ if (cmd == NULL)
+ err(1, "prop_array_get(cmd)");
+
+ if (!prop_dictionary_get_int8(cmd, "return", &error8))
+ err(1, "prop_get(return)");
+
+ if (error8) {
+ if (qup->flags & DEFAULT)
+ fprintf(stderr, "set default %s quota: %s\n",
+ qfextension[quotatype], strerror(error8));
+ else
+ fprintf(stderr, "set %s quota for %ld: %s\n",
+ qfextension[quotatype], id, strerror(error8));
+ }
+ prop_object_release(dict);
+}
+
+void
+putprivs1(long id, int quotatype, struct quotause *qup)
+{
+ struct dqblk dqblk;
+ int fd;
+
+ q2e2dqblk(&qup->q2e, &dqblk);
+ assert((qup->flags & DEFAULT) == 0);
+
+ if ((fd = open(qup->qfname, O_WRONLY)) < 0) {
+ warnx("open `%s'", qup->qfname);
+ } else {
+ (void)lseek(fd,
+ (off_t)(id * (long)sizeof (struct dqblk)),
+ SEEK_SET);
+ if (write(fd, &dqblk, sizeof (struct dqblk)) !=
+ sizeof (struct dqblk))
+ warnx("writing `%s'", qup->qfname);
+ close(fd);
}
}
@@ -470,16 +653,29 @@
(void)lseek(outfd, (off_t)0, SEEK_SET);
if ((fd = fdopen(dup(outfd), "w")) == NULL)
errx(1, "fdopen `%s'", tmpfil);
- fprintf(fd, "Quotas for %s %s:\n", qfextension[quotatype], name);
+ if (quplist->flags & DEFAULT) {
+ fprintf(fd, "Default %s quotas:\n", qfextension[quotatype]);
+ } else {
+ fprintf(fd, "Quotas for %s %s:\n",
+ qfextension[quotatype], name);
+ }
for (qup = quplist; qup; qup = qup->next) {
- fprintf(fd, "%s: %s %d, limits (soft = %d, hard = %d)\n",
+ fprintf(fd, "%s: %s %s, limits (soft = %s, hard = %s)\n",
qup->fsname, "blocks in use:",
- (int)(dbtob((u_quad_t)qup->dqblk.dqb_curblocks) / 1024),
- (int)(dbtob((u_quad_t)qup->dqblk.dqb_bsoftlimit) / 1024),
- (int)(dbtob((u_quad_t)qup->dqblk.dqb_bhardlimit) / 1024));
- fprintf(fd, "%s %d, limits (soft = %d, hard = %d)\n",
- "\tinodes in use:", qup->dqblk.dqb_curinodes,
- qup->dqblk.dqb_isoftlimit, qup->dqblk.dqb_ihardlimit);
+ intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur,
+ HN_NOSPACE | HN_B | HN_PRIV_UNLIMITED, Hflag),
+ intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit,
+ HN_NOSPACE | HN_B | HN_PRIV_UNLIMITED, Hflag),
+ intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit,
+ HN_NOSPACE | HN_B | HN_PRIV_UNLIMITED, Hflag));
+ fprintf(fd, "%s %s, limits (soft = %s, hard = %s)\n",
+ "\tinodes in use:",
+ intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_cur,
+ HN_NOSPACE | HN_PRIV_UNLIMITED, Hflag),
+ intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_softlimit,
+ HN_NOSPACE | HN_PRIV_UNLIMITED, Hflag),
+ intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit,
+ HN_NOSPACE | HN_PRIV_UNLIMITED, Hflag));
}
fclose(fd);
return (1);
@@ -497,8 +693,10 @@
FILE *fd;
int cnt;
char *cp;
- struct dqblk dqblk;
- char *fsp, line1[BUFSIZ], line2[BUFSIZ];
+ char *fsp;
+ static char line1[BUFSIZ], line2[BUFSIZ];
+ static char scurb[BUFSIZ], scuri[BUFSIZ], ssoft[BUFSIZ], shard[BUFSIZ];
+ uint64_t softb, hardb, softi, hardi;
(void)lseek(infd, (off_t)0, SEEK_SET);
fd = fdopen(dup(infd), "r");
@@ -513,71 +711,106 @@
while (fgets(line1, sizeof (line1), fd) != NULL &&
fgets(line2, sizeof (line2), fd) != NULL) {
if ((fsp = strtok(line1, " \t:")) == NULL) {
- warnx("%s: bad format", line1);
+ warnx("%s: 4 bad format", line1);
goto out;
}
if ((cp = strtok((char *)0, "\n")) == NULL) {
- warnx("%s: %s: bad format", fsp,
+ warnx("%s: %s: 5 bad format", fsp,
&fsp[strlen(fsp) + 1]);
goto out;
}
+#define last_char(str) ((str)[strlen(str) - 1])
cnt = sscanf(cp,
- " blocks in use: %d, limits (soft = %d, hard = %d)",
- &dqblk.dqb_curblocks, &dqblk.dqb_bsoftlimit,
- &dqblk.dqb_bhardlimit);
+ " blocks in use: %s limits (soft = %s hard = %s\n",
+ scurb, ssoft, shard);
if (cnt != 3) {
- warnx("%s:%s: bad format", fsp, cp);
+ warnx("%s:%s: 6 bad format %d", fsp, cp, cnt);
+ goto out;
+ }
+ /* drop last char which is ',' or ')' */
+ if (last_char(scurb) != ',' || last_char(ssoft) != ',' ||
+ last_char(shard) != ')') {
+ warnx("%s:%s: 61 bad format %d", fsp, cp, cnt);
+ goto out;
+ }
+ last_char(scurb) = '\0';
+ last_char(ssoft) = '\0';
+ last_char(shard) = '\0';
+
+ if (intrd(ssoft, &softb, HN_B) != 0) {
+ warnx("%s:%s: bad number", fsp, ssoft);
+ goto out;
+ }
+ if (intrd(shard, &hardb, HN_B) != 0) {
+ warnx("%s:%s: bad number", fsp, shard);
goto out;
}
- dqblk.dqb_curblocks = btodb((u_quad_t)
- dqblk.dqb_curblocks * 1024);
- dqblk.dqb_bsoftlimit = btodb((u_quad_t)
- dqblk.dqb_bsoftlimit * 1024);
- dqblk.dqb_bhardlimit = btodb((u_quad_t)
- dqblk.dqb_bhardlimit * 1024);
if ((cp = strtok(line2, "\n")) == NULL) {
- warnx("%s: %s: bad format", fsp, line2);
+ warnx("%s: %s: 7 bad format", fsp, line2);
goto out;
}
cnt = sscanf(cp,
- "\tinodes in use: %d, limits (soft = %d, hard = %d)",
- &dqblk.dqb_curinodes, &dqblk.dqb_isoftlimit,
- &dqblk.dqb_ihardlimit);
+ "\tinodes in use: %s limits (soft = %s hard = %s\n",
+ scuri, ssoft, shard);
if (cnt != 3) {
- warnx("%s: %s: bad format", fsp, line2);
+ warnx("%s: %s: 8 bad format", fsp, line2);
+ goto out;
+ }
+ /* drop last char which is ',' or ')' */
+ if (last_char(scuri) != ',' || last_char(ssoft) != ',' ||
+ last_char(shard) != ')') {
+ warnx("%s:%s: 81 bad format %d", fsp, cp, cnt);
+ goto out;
+ }
+ last_char(scuri) = '\0';
+ last_char(ssoft) = '\0';
+ last_char(shard) = '\0';
+ if (intrd(ssoft, &softi, 0) != 0) {
+ warnx("%s:%s: bad number", fsp, ssoft);
+ goto out;
+ }
+ if (intrd(shard, &hardi, 0) != 0) {
+ warnx("%s:%s: bad number", fsp, shard);
goto out;
}
for (qup = quplist; qup; qup = qup->next) {
if (strcmp(fsp, qup->fsname))
continue;
+ printf("%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
+ softb, hardb, softi, hardi);
+ if (strcmp(intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur,
+ HN_NOSPACE | HN_B | HN_PRIV_UNLIMITED, Hflag),
+ scurb) != 0 ||
+ strcmp(intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_cur,
+ HN_NOSPACE | HN_PRIV_UNLIMITED, Hflag),
+ scuri) != 0) {
+ warnx("%s: cannot change current allocation",
+ fsp);
+ break;
+ }
/*
* Cause time limit to be reset when the quota
* is next used if previously had no soft limit
* or were under it, but now have a soft limit
* and are over it.
*/
- if (dqblk.dqb_bsoftlimit &&
- qup->dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit &&
- (qup->dqblk.dqb_bsoftlimit == 0 ||
- qup->dqblk.dqb_curblocks <
- qup->dqblk.dqb_bsoftlimit))
- qup->dqblk.dqb_btime = 0;
- if (dqblk.dqb_isoftlimit &&
- qup->dqblk.dqb_curinodes >= dqblk.dqb_isoftlimit &&
- (qup->dqblk.dqb_isoftlimit == 0 ||
- qup->dqblk.dqb_curinodes <
- qup->dqblk.dqb_isoftlimit))
- qup->dqblk.dqb_itime = 0;
- qup->dqblk.dqb_bsoftlimit = dqblk.dqb_bsoftlimit;
- qup->dqblk.dqb_bhardlimit = dqblk.dqb_bhardlimit;
- qup->dqblk.dqb_isoftlimit = dqblk.dqb_isoftlimit;
- qup->dqblk.dqb_ihardlimit = dqblk.dqb_ihardlimit;
+ if (qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur &&
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur >= softb &&
+ (qup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit == 0 ||
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur <
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit))
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_time = 0;
+ if (qup->q2e.q2e_val[Q2V_FILE].q2v_cur &&
+ qup->q2e.q2e_val[Q2V_FILE].q2v_cur >= softi &&
+ (qup->q2e.q2e_val[Q2V_FILE].q2v_softlimit == 0 ||
+ qup->q2e.q2e_val[Q2V_FILE].q2v_cur <
+ qup->q2e.q2e_val[Q2V_FILE].q2v_softlimit))
+ qup->q2e.q2e_val[Q2V_FILE].q2v_time = 0;
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit = softb;
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit = hardb;
+ qup->q2e.q2e_val[Q2V_FILE].q2v_softlimit = softi;
+ qup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit = hardi;
qup->flags |= FOUND;
- if (dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks &&
- dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes)
- break;
- warnx("%s: cannot change current allocation", fsp);
- break;
}
}
out:
@@ -590,10 +823,10 @@
qup->flags &= ~FOUND;
continue;
}
- qup->dqblk.dqb_bsoftlimit = 0;
- qup->dqblk.dqb_bhardlimit = 0;
- qup->dqblk.dqb_isoftlimit = 0;
- qup->dqblk.dqb_ihardlimit = 0;
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_softlimit = UQUAD_MAX;
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit = UQUAD_MAX;
+ qup->q2e.q2e_val[Q2V_FILE].q2v_softlimit = UQUAD_MAX;
+ qup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit = UQUAD_MAX;
}
return (1);
}
@@ -619,9 +852,9 @@
qfextension[quotatype]);
for (qup = quplist; qup; qup = qup->next) {
fprintf(fd, "%s: block grace period: %s, ",
- qup->fsname, cvtstoa(qup->dqblk.dqb_btime));
+ qup->fsname, cvtstoa(qup->q2e.q2e_val[Q2V_BLOCK].q2v_time));
fprintf(fd, "file grace period: %s\n",
- cvtstoa(qup->dqblk.dqb_itime));
+ cvtstoa(qup->q2e.q2e_val[Q2V_FILE].q2v_time));
}
fclose(fd);
return (1);
@@ -656,11 +889,11 @@
(void) fgets(line1, sizeof (line1), fd);
while (fgets(line1, sizeof (line1), fd) != NULL) {
if ((fsp = strtok(line1, " \t:")) == NULL) {
- warnx("%s: bad format", line1);
+ warnx("%s: 1 bad format", line1);
goto bad;
}
if ((cp = strtok((char *)0, "\n")) == NULL) {
- warnx("%s: %s: bad format", fsp,
+ warnx("%s: %s: 2 bad format", fsp,
&fsp[strlen(fsp) + 1]);
goto bad;
}
@@ -668,7 +901,7 @@
" block grace period: %ld %s file grace period: %ld %s",
&lbtime, bunits, &litime, iunits);
if (cnt != 4) {
- warnx("%s:%s: bad format", fsp, cp);
+ warnx("%s:%s: 3 bad format", fsp, cp);
goto bad;
}
itime = (time_t)litime;
@@ -683,8 +916,8 @@
for (qup = quplist; qup; qup = qup->next) {
if (strcmp(fsp, qup->fsname))
continue;
- qup->dqblk.dqb_btime = bseconds;
- qup->dqblk.dqb_itime = iseconds;
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_time = bseconds;
+ qup->q2e.q2e_val[Q2V_FILE].q2v_time = iseconds;
qup->flags |= FOUND;
break;
}
@@ -699,8 +932,8 @@
qup->flags &= ~FOUND;
continue;
}
- qup->dqblk.dqb_btime = 0;
- qup->dqblk.dqb_itime = 0;
+ qup->q2e.q2e_val[Q2V_BLOCK].q2v_time = 0;
+ qup->q2e.q2e_val[Q2V_FILE].q2v_time = 0;
}
return (1);
}
@@ -756,6 +989,17 @@
}
/*
+ * Free a quotause structure.
+ */
+void
+freeq(struct quotause *qup)
+{
+ if (qup->qfname)
+ free(qup->qfname);
+ free(qup);
+}
+
+/*
* Free a list of quotause structures.
*/
void
@@ -766,7 +1010,7 @@
for (qup = quplist; qup; qup = nextqup) {
nextqup = qup->next;
- free(qup);
+ freeq(qup);
}
}
@@ -799,14 +1043,14 @@
char *opt;
char *cp;
static char initname, usrname[100], grpname[100];
- static char buf[BUFSIZ];
+ char *buf;
if (!initname) {
sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname);
sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname);
initname = 1;
}
- strcpy(buf, fs->fs_mntops);
+ buf = fs->fs_mntops;
cp = NULL;
for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
if ((cp = strchr(opt, '=')) != NULL)
@@ -816,13 +1060,21 @@
if (type == GRPQUOTA && strcmp(opt, grpname) == 0)
break;
}
- if (!opt)
+ if (!opt) {
+ *qfnamep = NULL;
return (0);
+ }
if (cp) {
- *qfnamep = cp;
+ *qfnamep = malloc(strlen(cp) + 1);
+ if (*qfnamep == NULL)
+ err(1, "malloc");
+ strcpy(*qfnamep, cp);
return (1);
}
- (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]);
- *qfnamep = buf;
+ *qfnamep = malloc(BUFSIZ);
+ if (*qfnamep == NULL)
+ err(1, "malloc");
+ (void) sprintf(*qfnamep, "%s/%s.%s", fs->fs_file, qfname,
+ qfextension[type]);
return (1);
}