Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-quota2]: src Allow edquota to edit per-user grace times on quota2...



details:   https://anonhg.NetBSD.org/src/rev/8e1f2f6ab157
branches:  bouyer-quota2
changeset: 761096:8e1f2f6ab157
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sun Jan 30 22:49:31 2011 +0000

description:
Allow edquota to edit per-user grace times on quota2 (or the default, global
grace times on quota1). Use re-use -t to specify the grace time on command
line; editing the grace time on quota1 is done with -d now.

diffstat:

 usr.bin/quota/printquota.c |   65 ++++++++++++++++--
 usr.bin/quota/printquota.h |    7 +-
 usr.sbin/edquota/edquota.c |  156 ++++++++++++++++++++++++++++++++------------
 3 files changed, 175 insertions(+), 53 deletions(-)

diffs (truncated from 465 to 300 lines):

diff -r 7e7cc8ea4119 -r 8e1f2f6ab157 usr.bin/quota/printquota.c
--- a/usr.bin/quota/printquota.c        Sun Jan 30 21:37:39 2011 +0000
+++ b/usr.bin/quota/printquota.c        Sun Jan 30 22:49:31 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: printquota.c,v 1.1.2.6 2011/01/30 21:37:39 bouyer Exp $ */
+/*     $NetBSD: printquota.c,v 1.1.2.7 2011/01/30 22:49:31 bouyer Exp $ */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)quota.c    8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: printquota.c,v 1.1.2.6 2011/01/30 21:37:39 bouyer Exp $");
+__RCSID("$NetBSD: printquota.c,v 1.1.2.7 2011/01/30 22:49:31 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -148,17 +148,19 @@
 }
 
 /*
- * Calculate the grace period and return a precise string for it.
+ * Calculate the grace period and return a precise string for it,
+ * either in seconds or in format xWyDzHtMuS
  */
 const char *
-timepprt(time_t now, time_t seconds, int space)
+timepprt(time_t seconds, int hflag, int space)
 {
        static char buf[20], *append;
        int i, remain = space + 1;
 
-       if (now > seconds)
-               return ("none");
-       seconds -= now;
+       if (hflag == 0) {
+               snprintf(buf, remain, "%" PRId64, seconds);
+               return buf;
+       }
 
        append = &buf[0];
        if ((seconds / WEEK) > 0) {
@@ -199,6 +201,55 @@
 }
 
 /*
+ * convert a string of the form xWyDzHtMuS, or plain decimal, to 
+ * a time in seconds
+ */
+int
+timeprd(const char *str, time_t *valp)
+{
+       char buf[20];
+       char *cur, *next, *end;
+       time_t val= 0;
+
+       strncpy(buf, str, sizeof(buf));
+       next = buf;
+       cur = strsep(&next, "Ww");
+       if (next != NULL) {
+               val = strtoumax(cur, &end, 10) * WEEK;  
+               if (end[0] != '\0')
+                       return EINVAL;
+       } else
+               next = cur;
+       cur = strsep(&next, "Dd");
+       if (next != NULL) {
+               val += strtoumax(cur, &end, 10) * DAY;  
+               if (end[0] != '\0')
+                       return EINVAL;
+       } else
+               next = cur;
+       cur = strsep(&next, "Hh");
+       if (next != NULL) {
+               val += strtoumax(cur, &end, 10) * HOUR; 
+               if (end[0] != '\0')
+                       return EINVAL;
+       } else
+               next = cur;
+       cur = strsep(&next, "Mm");
+       if (next != NULL) {
+               val += strtoumax(cur, &end, 10) * MINUTE;       
+               if (end[0] != '\0')
+                       return EINVAL;
+       } else
+               next = cur;
+       cur = strsep(&next, "Ss");
+       val += strtoumax(cur, &end, 10);
+       if (end[0] != '\0')
+               return EINVAL;
+       *valp = val;
+       return 0;
+}
+
+/*
  * convert a string to a uint64 value
  */
 int
diff -r 7e7cc8ea4119 -r 8e1f2f6ab157 usr.bin/quota/printquota.h
--- a/usr.bin/quota/printquota.h        Sun Jan 30 21:37:39 2011 +0000
+++ b/usr.bin/quota/printquota.h        Sun Jan 30 22:49:31 2011 +0000
@@ -1,7 +1,8 @@
-/*     $NetBSD: printquota.h,v 1.1.2.6 2011/01/30 21:37:39 bouyer Exp $ */
+/*     $NetBSD: printquota.h,v 1.1.2.7 2011/01/30 22:49:32 bouyer Exp $ */
 
 const char *intprt(uint64_t, u_int, int, int);
-const char *timeprt(time_t, time_t, int space);
-const char *timepprt(time_t, time_t, int space);
+const char *timeprt(time_t, time_t, int);
+const char *timepprt(time_t, int, int);
+int timeprd(const char *, time_t *);
 int intrd(char *str, uint64_t *val, u_int);
 
diff -r 7e7cc8ea4119 -r 8e1f2f6ab157 usr.sbin/edquota/edquota.c
--- a/usr.sbin/edquota/edquota.c        Sun Jan 30 21:37:39 2011 +0000
+++ b/usr.sbin/edquota/edquota.c        Sun Jan 30 22:49:31 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: edquota.c,v 1.29.16.4 2011/01/30 20:54:22 bouyer Exp $ */
+/*      $NetBSD: edquota.c,v 1.29.16.5 2011/01/30 22:49:32 bouyer Exp $ */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,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.16.4 2011/01/30 20:54:22 bouyer Exp $");
+__RCSID("$NetBSD: edquota.c,v 1.29.16.5 2011/01/30 22:49:32 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -130,10 +130,10 @@
        long id, protoid;
        int quotatype, tmpfd;
        char *protoname;
-       char *soft = NULL, *hard = NULL;
+       char *soft = NULL, *hard = NULL, *grace = NULL;
        char *fs = NULL;
        int ch;
-       int tflag = 0, pflag = 0;
+       int pflag = 0;
 
        if (argc < 2)
                usage();
@@ -141,7 +141,7 @@
                errx(1, "permission denied");
        protoname = NULL;
        quotatype = USRQUOTA;
-       while ((ch = getopt(argc, argv, "DHdugtp:s:h:f:")) != -1) {
+       while ((ch = getopt(argc, argv, "DHdugp:s:h:t:f:")) != -1) {
                switch(ch) {
                case 'D':
                        Dflag++;
@@ -162,15 +162,15 @@
                case 'u':
                        quotatype = USRQUOTA;
                        break;
-               case 't':
-                       tflag++;
-                       break;
                case 's':
                        soft = optarg;
                        break;
                case 'h':
                        hard = optarg;
                        break;
+               case 't':
+                       grace = optarg;
+                       break;
                case 'f':
                        fs = optarg;
                        break;
@@ -182,7 +182,7 @@
        argv += optind;
 
        if (pflag) {
-               if (soft || hard || dflag)
+               if (soft || hard || grace || dflag)
                        usage();
                if ((protoid = getentry(protoname, quotatype)) == -1)
                        exit(1);
@@ -198,12 +198,11 @@
                }
                exit(0);
        }
-       if (soft || hard) {
+       if (soft || hard || grace) {
                struct quotause *lqup;
                u_int64_t softb, hardb, softi, hardi;
+               time_t  graceb, gracei;
                char *str;
-               if (tflag)
-                       usage();
                if (soft) {
                        str = strsep(&soft, "/");
                        if (str[0] == '\0' || soft == NULL || soft[0] == '\0')
@@ -224,6 +223,16 @@
                        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, quotatype, fs, 1);
                        for (lqup = curprivs; lqup; lqup = lqup->next) {
@@ -235,6 +244,10 @@
                                        lqup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit = hardb;
                                        lqup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit = hardi;
                                }
+                               if (grace) {
+                                       lqup->q2e.q2e_val[Q2V_BLOCK].q2v_grace = graceb;
+                                       lqup->q2e.q2e_val[Q2V_FILE].q2v_grace = gracei;
+                               }
                        }
                        putprivs(0, quotatype, curprivs);
                        freeprivs(curprivs);
@@ -263,6 +276,10 @@
                                        lqup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit = hardb;
                                        lqup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit = hardi;
                                }
+                               if (grace) {
+                                       lqup->q2e.q2e_val[Q2V_BLOCK].q2v_grace = graceb;
+                                       lqup->q2e.q2e_val[Q2V_FILE].q2v_grace = gracei;
+                               }
                        }
                        putprivs(id, quotatype, curprivs);
                        freeprivs(curprivs);
@@ -271,7 +288,7 @@
        }
        tmpfd = mkstemp(tmpfil);
        fchown(tmpfd, getuid(), getgid());
-       if (tflag) {
+       if (0 /* XXX */) {
                if (soft || hard)
                        usage();
                protoprivs = getprivs(0, quotatype, fs, 0);
@@ -311,10 +328,8 @@
            "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"
+           "  edquota [-D] [-u] [-f filesystem] [-s b#/i#] [-h b#/i#] [-t t#/t#] \\\n\t[-d] username ...\n"
+           "  edquota [-D] -g [-f filesystem] [-s b#/i#] [-h b#/i#] [-t t#/t#] \\\n\t[-d] groupname ...\n"
            );
        exit(1);
 }
@@ -679,7 +694,7 @@
                    qfextension[quotatype], name);
        }
        for (qup = quplist; qup; qup = qup->next) {
-               fprintf(fd, "%s: %s %s, limits (soft = %s, hard = %s)\n",
+               fprintf(fd, "%s: %s %s, limits (soft = %s, hard = %s",
                    qup->fsname, "blocks in use:",
                    intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_cur,
                        HN_NOSPACE | HN_B, Hflag, 20),
@@ -687,7 +702,13 @@
                        HN_NOSPACE | HN_B, Hflag, 20),
                    intprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_hardlimit,
                        HN_NOSPACE | HN_B, Hflag, 20));
-               fprintf(fd, "%s %s, limits (soft = %s, hard = %s)\n",
+               if (qup->flags & (QUOTA2|DEFAULT)) {
+                   fprintf(fd, ", grace = %s",
+                       timepprt(qup->q2e.q2e_val[Q2V_BLOCK].q2v_grace,
+                           Hflag, 20));
+               }
+               fprintf(fd, ")\n");
+               fprintf(fd, "%s %s, limits (soft = %s, hard = %s",
                    "\tinodes in use:",
                    intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_cur,
                        HN_NOSPACE, Hflag, 20),
@@ -695,6 +716,12 @@
                        HN_NOSPACE, Hflag, 20),
                    intprt(qup->q2e.q2e_val[Q2V_FILE].q2v_hardlimit,
                         HN_NOSPACE, Hflag, 20));
+               if (qup->flags & (QUOTA2|DEFAULT)) {
+                   fprintf(fd, ", grace = %s",
+                       timepprt(qup->q2e.q2e_val[Q2V_FILE].q2v_grace,
+                           Hflag, 20));
+               }
+               fprintf(fd, ")\n");
        }
        fclose(fd);
        return (1);
@@ -715,7 +742,9 @@
        char *fsp;
        static char line1[BUFSIZ], line2[BUFSIZ];
        static char scurb[BUFSIZ], scuri[BUFSIZ], ssoft[BUFSIZ], shard[BUFSIZ];
+       static char stime[BUFSIZ];



Home | Main Index | Thread Index | Old Index