Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/edquota tsort contents of file.
details: https://anonhg.NetBSD.org/src/rev/e9813d81cc72
branches: trunk
changeset: 767170:e9813d81cc72
user: dholland <dholland%NetBSD.org@localhost>
date: Sun Jul 10 07:31:48 2011 +0000
description:
tsort contents of file.
diffstat:
usr.sbin/edquota/edquota.c | 859 +++++++++++++++++++++++---------------------
1 files changed, 440 insertions(+), 419 deletions(-)
diffs (truncated from 934 to 300 lines):
diff -r 57a070539c8f -r e9813d81cc72 usr.sbin/edquota/edquota.c
--- a/usr.sbin/edquota/edquota.c Sun Jul 10 07:19:24 2011 +0000
+++ b/usr.sbin/edquota/edquota.c Sun Jul 10 07:31:48 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: edquota.c,v 1.33 2011/07/10 07:19:24 dholland Exp $ */
+/* $NetBSD: edquota.c,v 1.34 2011/07/10 07:31:48 dholland Exp $ */
/*
* Copyright (c) 1980, 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "from: @(#)edquota.c 8.3 (Berkeley) 4/27/95";
#else
-__RCSID("$NetBSD: edquota.c,v 1.33 2011/07/10 07:19:24 dholland Exp $");
+__RCSID("$NetBSD: edquota.c,v 1.34 2011/07/10 07:31:48 dholland Exp $");
#endif
#endif /* not lint */
@@ -119,228 +119,8 @@
#define QL_BLK QUOTA_LIMIT_BLOCK
#define QL_FL QUOTA_LIMIT_FILE
-int
-main(int argc, char *argv[])
-{
- struct quotause *qup, *protoprivs, *curprivs;
- long id, protoid;
- int quotaclass, tmpfd;
- char *protoname;
- char *soft = NULL, *hard = NULL, *grace = NULL;
- char *fs = NULL;
- int ch;
- int pflag = 0;
- int cflag = 0;
-
- if (argc < 2)
- usage();
- if (getuid())
- errx(1, "permission denied");
- protoname = NULL;
- quotaclass = QUOTA_CLASS_USER;
- while ((ch = getopt(argc, argv, "DHcdugp:s:h:t:f:")) != -1) {
- switch(ch) {
- case 'D':
- Dflag++;
- break;
- case 'H':
- Hflag++;
- break;
- case 'c':
- cflag++;
- break;
- case 'd':
- dflag++;
- break;
- case 'p':
- protoname = optarg;
- pflag++;
- break;
- case 'g':
- quotaclass = QUOTA_CLASS_GROUP;
- break;
- case 'u':
- quotaclass = QUOTA_CLASS_USER;
- break;
- case 's':
- soft = optarg;
- break;
- case 'h':
- hard = optarg;
- break;
- case 't':
- grace = optarg;
- break;
- case 'f':
- fs = optarg;
- break;
- default:
- usage();
- }
- }
- argc -= optind;
- argv += optind;
-
- if (pflag) {
- if (soft || hard || grace || dflag || cflag)
- usage();
- if ((protoid = getentry(protoname, quotaclass)) == -1)
- return 1;
- protoprivs = getprivs(protoid, quotaclass, fs, 0);
- for (qup = protoprivs; qup; qup = qup->next) {
- qup->qe[QL_BLK].ufsqe_time = 0;
- qup->qe[QL_FL].ufsqe_time = 0;
- }
- while (argc-- > 0) {
- if ((id = getentry(*argv++, quotaclass)) < 0)
- continue;
- putprivs(id, quotaclass, protoprivs);
- }
- return 0;
- }
- if (soft || hard || grace) {
- struct quotause *lqup;
- u_int64_t softb, hardb, softi, hardi;
- time_t graceb, gracei;
- char *str;
-
- if (cflag)
- usage();
- if (soft) {
- str = strsep(&soft, "/");
- if (str[0] == '\0' || soft == NULL || soft[0] == '\0')
- usage();
-
- if (intrd(str, &softb, HN_B) != 0)
- errx(1, "%s: bad number", str);
- if (intrd(soft, &softi, 0) != 0)
- errx(1, "%s: bad number", soft);
- }
- if (hard) {
- str = strsep(&hard, "/");
- if (str[0] == '\0' || hard == NULL || hard[0] == '\0')
- usage();
-
- if (intrd(str, &hardb, HN_B) != 0)
- errx(1, "%s: bad number", str);
- if (intrd(hard, &hardi, 0) != 0)
- errx(1, "%s: bad number", hard);
- }
- if (grace) {
- str = strsep(&grace, "/");
- if (str[0] == '\0' || grace == NULL || grace[0] == '\0')
- usage();
-
- if (timeprd(str, &graceb) != 0)
- errx(1, "%s: bad number", str);
- if (timeprd(grace, &gracei) != 0)
- errx(1, "%s: bad number", grace);
- }
- if (dflag) {
- curprivs = getprivs(0, quotaclass, fs, 1);
- for (lqup = curprivs; lqup; lqup = lqup->next) {
- struct ufs_quota_entry *q = lqup->qe;
- if (soft) {
- q[QL_BLK].ufsqe_softlimit = softb;
- q[QL_FL].ufsqe_softlimit = softi;
- }
- if (hard) {
- q[QL_BLK].ufsqe_hardlimit = hardb;
- q[QL_FL].ufsqe_hardlimit = hardi;
- }
- if (grace) {
- q[QL_BLK].ufsqe_grace = graceb;
- q[QL_FL].ufsqe_grace = gracei;
- }
- }
- putprivs(0, quotaclass, curprivs);
- freeprivs(curprivs);
- return 0;
- }
- for ( ; argc > 0; argc--, argv++) {
- if ((id = getentry(*argv, quotaclass)) == -1)
- continue;
- curprivs = getprivs(id, quotaclass, fs, 0);
- for (lqup = curprivs; lqup; lqup = lqup->next) {
- struct ufs_quota_entry *q = lqup->qe;
- if (soft) {
- if (softb &&
- q[QL_BLK].ufsqe_cur >= softb &&
- (q[QL_BLK].ufsqe_softlimit == 0 ||
- q[QL_BLK].ufsqe_cur <
- q[QL_BLK].ufsqe_softlimit))
- q[QL_BLK].ufsqe_time = 0;
- if (softi &&
- q[QL_FL].ufsqe_cur >= softb &&
- (q[QL_FL].ufsqe_softlimit == 0 ||
- q[QL_FL].ufsqe_cur <
- q[QL_FL].ufsqe_softlimit))
- q[QL_FL].ufsqe_time = 0;
- q[QL_BLK].ufsqe_softlimit = softb;
- q[QL_FL].ufsqe_softlimit = softi;
- }
- if (hard) {
- q[QL_BLK].ufsqe_hardlimit = hardb;
- q[QL_FL].ufsqe_hardlimit = hardi;
- }
- if (grace) {
- q[QL_BLK].ufsqe_grace = graceb;
- q[QL_FL].ufsqe_grace = gracei;
- }
- }
- putprivs(id, quotaclass, curprivs);
- freeprivs(curprivs);
- }
- return 0;
- }
- if (cflag) {
- if (dflag)
- usage();
- clearpriv(argc, argv, fs, quotaclass);
- return 0;
- }
- tmpfd = mkstemp(tmpfil);
- fchown(tmpfd, getuid(), getgid());
- if (dflag) {
- curprivs = getprivs(0, quotaclass, fs, 1);
- if (writeprivs(curprivs, tmpfd, NULL, quotaclass) &&
- editit(tmpfil) && readprivs(curprivs, tmpfd))
- putprivs(0, quotaclass, curprivs);
- freeprivs(curprivs);
- }
- for ( ; argc > 0; argc--, argv++) {
- if ((id = getentry(*argv, quotaclass)) == -1)
- continue;
- curprivs = getprivs(id, quotaclass, fs, 0);
- if (writeprivs(curprivs, tmpfd, *argv, quotaclass) == 0)
- continue;
- if (editit(tmpfil) && readprivs(curprivs, tmpfd))
- putprivs(id, quotaclass, curprivs);
- freeprivs(curprivs);
- }
- close(tmpfd);
- unlink(tmpfil);
- return 0;
-}
-
-static void
-usage(void)
-{
- const char *p = getprogname();
- fprintf(stderr,
- "Usage: %s [-D] [-H] [-u] [-p <username>] [-f <filesystem>] "
- "-d | <username> ...\n"
- "\t%s [-D] [-H] -g [-p <groupname>] [-f <filesystem>] "
- "-d | <groupname> ...\n"
- "\t%s [-D] [-u] [-f <filesystem>] [-s b#/i#] [-h b#/i#] [-t t#/t#] "
- "-d | <username> ...\n"
- "\t%s [-D] -g [-f <filesystem>] [-s b#/i#] [-h b#/i#] [-t t#/t#] "
- "-d | <groupname> ...\n"
- "\t%s [-D] [-H] [-u] -c [-f <filesystem>] username ...\n"
- "\t%s [-D] [-H] -g -c [-f <filesystem>] groupname ...\n",
- p, p, p, p, p, p);
- exit(1);
-}
+////////////////////////////////////////////////////////////
+// support code
/*
* This routine converts a name for a particular quota type to
@@ -374,79 +154,56 @@
return -1;
}
-/*
- * Collect the requested quota information.
- */
-static struct quotause *
-getprivs(long id, int quotaclass, const char *filesys, int defaultq)
-{
- struct statvfs *fst;
- int nfst, i;
- struct quotause *qup, *quptail = NULL;
- struct quotause *quphead = NULL;
-
- nfst = getmntinfo(&fst, MNT_WAIT);
- if (nfst == 0)
- errx(1, "no filesystems mounted!");
+////////////////////////////////////////////////////////////
+// quotause operations
- for (i = 0; i < nfst; i++) {
- if ((fst[i].f_flag & ST_QUOTA) == 0)
- continue;
- if (filesys && strcmp(fst[i].f_mntonname, filesys) != 0 &&
- strcmp(fst[i].f_mntfromname, filesys) != 0)
- continue;
- qup = getprivs2(id, quotaclass, fst[i].f_mntonname, defaultq);
- if (qup == NULL)
- return NULL;
- if (quphead == NULL)
- quphead = qup;
- else
- quptail->next = qup;
- quptail = qup;
- qup->next = 0;
- }
-
- if (filesys && quphead == NULL) {
- 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, quotaclass, filesys);
- if (qup == NULL)
- return NULL;
- if (quphead == NULL)
- quphead = qup;
- else
- quptail->next = qup;
- quptail = qup;
- qup->next = 0;
Home |
Main Index |
Thread Index |
Old Index