Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/bouyer-quota2]: src/usr.sbin/edquota Convert to new quotactl()
details: https://anonhg.NetBSD.org/src/rev/e0a01eaaea20
branches: bouyer-quota2
changeset: 761083:e0a01eaaea20
user: bouyer <bouyer%NetBSD.org@localhost>
date: Sun Jan 30 00:26:03 2011 +0000
description:
Convert to new quotactl()
diffstat:
usr.sbin/edquota/Makefile | 13 +-
usr.sbin/edquota/edquota.c | 670 ++++++++++++++++++++++++++++++--------------
2 files changed, 473 insertions(+), 210 deletions(-)
diffs (truncated from 954 to 300 lines):
diff -r f74c0a860b23 -r e0a01eaaea20 usr.sbin/edquota/Makefile
--- a/usr.sbin/edquota/Makefile Sun Jan 30 00:25:19 2011 +0000
+++ b/usr.sbin/edquota/Makefile Sun Jan 30 00:26:03 2011 +0000
@@ -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>
diff -r f74c0a860b23 -r e0a01eaaea20 usr.sbin/edquota/edquota.c
--- a/usr.sbin/edquota/edquota.c Sun Jan 30 00:25:19 2011 +0000
+++ b/usr.sbin/edquota/edquota.c Sun Jan 30 00:26:03 2011 +0000
@@ -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;
+ struct statvfs *fst;
+ int nfst, i;
+ struct quotause *qup, *quptail = NULL;
+ struct quotause *quphead = NULL;
- setfsent();
Home |
Main Index |
Thread Index |
Old Index