Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/quota - merge more code.



details:   https://anonhg.NetBSD.org/src/rev/1148ea744962
branches:  trunk
changeset: 762973:1148ea744962
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 06 22:36:07 2011 +0000

description:
- merge more code.
- simplify struct access.

diffstat:

 usr.bin/quota/Makefile      |    4 +-
 usr.bin/quota/getvfsquota.c |    9 +-
 usr.bin/quota/printquota.c  |   18 ++---
 usr.bin/quota/printquota.h  |    7 +-
 usr.bin/quota/quota.c       |   71 ++++++++-----------------
 usr.bin/quota/quotautil.c   |  119 ++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/quota/quotautil.h   |    7 ++
 7 files changed, 166 insertions(+), 69 deletions(-)

diffs (truncated from 434 to 300 lines):

diff -r c66a30061cc9 -r 1148ea744962 usr.bin/quota/Makefile
--- a/usr.bin/quota/Makefile    Sun Mar 06 22:33:55 2011 +0000
+++ b/usr.bin/quota/Makefile    Sun Mar 06 22:36:07 2011 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.8 2011/03/06 20:47:59 christos Exp $      
+#      $NetBSD: Makefile,v 1.9 2011/03/06 22:36:07 christos Exp $      
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
 
 WARNS ?= 4
 .include <bsd.own.mk>
 PROG=  quota
-SRCS=  quota.c printquota.c getvfsquota.c
+SRCS=  quota.c printquota.c getvfsquota.c quotautil.c
 
 CPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
 DPADD= ${LIBRPCSVC} ${LIBPROP}
diff -r c66a30061cc9 -r 1148ea744962 usr.bin/quota/getvfsquota.c
--- a/usr.bin/quota/getvfsquota.c       Sun Mar 06 22:33:55 2011 +0000
+++ b/usr.bin/quota/getvfsquota.c       Sun Mar 06 22:36:07 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getvfsquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $ */
+/*     $NetBSD: getvfsquota.c,v 1.4 2011/03/06 22:36:07 christos Exp $ */
 
 /*-
   * Copyright (c) 2011 Manuel Bouyer
@@ -29,7 +29,7 @@
   */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: getvfsquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $");
+__RCSID("$NetBSD: getvfsquota.c,v 1.4 2011/03/06 22:36:07 christos Exp $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -42,9 +42,8 @@
 #include <ufs/ufs/quota2_prop.h>
 #include <sys/quota.h>
 
-#include <getvfsquota.h>
-
-const char *qfextension[] = INITQFNAMES;
+#include "getvfsquota.h"
+#include "quotautil.h"
 
 /* retrieve quotas from vfs, for the given user id */
 int
diff -r c66a30061cc9 -r 1148ea744962 usr.bin/quota/printquota.c
--- a/usr.bin/quota/printquota.c        Sun Mar 06 22:33:55 2011 +0000
+++ b/usr.bin/quota/printquota.c        Sun Mar 06 22:36:07 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: printquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $ */
+/*     $NetBSD: printquota.c,v 1.4 2011/03/06 22:36:07 christos 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.3 2011/03/06 20:47:59 christos Exp $");
+__RCSID("$NetBSD: printquota.c,v 1.4 2011/03/06 22:36:07 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,7 +59,7 @@
 #include <limits.h>
 #include <inttypes.h>
 
-#include <printquota.h>
+#include "printquota.h"
 
 /*
  * convert 64bit value to a printable string
@@ -138,13 +138,12 @@
        return buf;
 }
 
-#if 0
 /*
  * Calculate the grace period and return a precise string for it,
  * either in seconds or in format xWyDzHtMuS
  */
 const char *
-timepprt(char *buf, size_t len, time_t seconds, int hflag, int space)
+timepprt(char *buf, size_t len, time_t seconds, int hflag)
 {
        ssize_t i = 0;
 
@@ -158,7 +157,7 @@
                seconds = seconds % WEEK;
        }
 
-       if (remain < 3 || seconds == 0)
+       if (len - i < 3 || seconds == 0)
                return buf;
 
        if ((seconds / DAY) > 0) {
@@ -166,7 +165,7 @@
                seconds = seconds % DAY;
        }
 
-       if (remain < 4 || seconds == 0)
+       if (len - i < 4 || seconds == 0)
                return buf;
 
        if ((seconds / HOUR) > 0) {
@@ -174,7 +173,7 @@
                seconds = seconds % HOUR;
        }
 
-       if (remain < 4 || seconds == 0)
+       if (len - i < 4 || seconds == 0)
                return buf;
 
        if ((seconds / MINUTE) > 0) {
@@ -183,7 +182,7 @@
                seconds = seconds % MINUTE;
        }
 
-       if (remain < 4 || seconds == 0)
+       if (len - i < 4 || seconds == 0)
                return buf;
 
        (void)snprintf(buf + i, len - i, "%" PRId64 "S", seconds);
@@ -272,4 +271,3 @@
                *val = btodb(*val);
        return ret;
 }
-#endif
diff -r c66a30061cc9 -r 1148ea744962 usr.bin/quota/printquota.h
--- a/usr.bin/quota/printquota.h        Sun Mar 06 22:33:55 2011 +0000
+++ b/usr.bin/quota/printquota.h        Sun Mar 06 22:36:07 2011 +0000
@@ -1,10 +1,7 @@
-/*     $NetBSD: printquota.h,v 1.3 2011/03/06 20:47:59 christos Exp $ */
+/*     $NetBSD: printquota.h,v 1.4 2011/03/06 22:36:07 christos Exp $ */
 
 const char *intprt(char *, size_t, uint64_t, int, int);
 const char *timeprt(char *, size_t, time_t, time_t);
-#if 0
-const char *timepprt(time_t, int, int);
+const char *timepprt(char *, size_t, time_t, int);
 int timeprd(const char *, time_t *);
 int intrd(char *str, uint64_t *val, u_int);
-#endif
-
diff -r c66a30061cc9 -r 1148ea744962 usr.bin/quota/quota.c
--- a/usr.bin/quota/quota.c     Sun Mar 06 22:33:55 2011 +0000
+++ b/usr.bin/quota/quota.c     Sun Mar 06 22:36:07 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quota.c,v 1.35 2011/03/06 20:47:59 christos Exp $      */
+/*     $NetBSD: quota.c,v 1.36 2011/03/06 22:36:07 christos 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: quota.c,v 1.35 2011/03/06 20:47:59 christos Exp $");
+__RCSID("$NetBSD: quota.c,v 1.36 2011/03/06 22:36:07 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -76,8 +76,9 @@
 #include <rpc/pmap_prot.h>
 #include <rpcsvc/rquota.h>
 
-#include <printquota.h>
-#include <getvfsquota.h>
+#include "printquota.h"
+#include "quotautil.h"
+#include "getvfsquota.h"
 
 struct quotause {
        struct  quotause *next;
@@ -88,7 +89,6 @@
 #define        FOUND   0x01
 #define        QUOTA2  0x02
 
-static int     alldigits(const char *);
 static int     callaurpc(const char *, rpcprog_t, rpcvers_t, rpcproc_t,
     xdrproc_t, void *, xdrproc_t, void *);
 static int     getnfsquota(struct statvfs *, struct quotause *, uint32_t, int);
@@ -335,14 +335,14 @@
        quplist = getprivs(id, type);
        for (qup = quplist; qup; qup = qup->next) {
                int ql_stat;
+               struct quota2_val *q = qup->q2e.q2e_val;
                if (!vflag &&
-                   qup->q2e.q2e_val[QL_BLOCK].q2v_softlimit == UQUAD_MAX &&
-                   qup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit == UQUAD_MAX &&
-                   qup->q2e.q2e_val[QL_FILE].q2v_softlimit == UQUAD_MAX &&
-                   qup->q2e.q2e_val[QL_FILE].q2v_hardlimit == UQUAD_MAX)
+                   q[QL_BLOCK].q2v_softlimit == UQUAD_MAX &&
+                   q[QL_BLOCK].q2v_hardlimit == UQUAD_MAX &&
+                   q[QL_FILE].q2v_softlimit == UQUAD_MAX &&
+                   q[QL_FILE].q2v_hardlimit == UQUAD_MAX)
                        continue;
-               ql_stat = quota2_check_limit(&qup->q2e.q2e_val[QL_FILE],
-                   1, now);
+               ql_stat = quota2_check_limit(&q[QL_FILE], 1, now);
                switch(QL_STATUS(ql_stat)) {
                case QL_S_DENY_HARD:
                        msgi = "File limit reached on";
@@ -356,8 +356,7 @@
                default:
                        msgi = NULL;
                }
-               ql_stat = quota2_check_limit(&qup->q2e.q2e_val[QL_BLOCK],
-                   1, now);
+               ql_stat = quota2_check_limit(&q[QL_BLOCK], 1, now);
                switch(QL_STATUS(ql_stat)) {
                case QL_S_DENY_HARD:
                        msgb = "Block limit reached on";
@@ -381,9 +380,8 @@
                                printf("\t%s %s\n", msgb, qup->fsname);
                        continue;
                }
-               if (vflag || dflag || msgi || msgb ||
-                   qup->q2e.q2e_val[QL_BLOCK].q2v_cur ||
-                   qup->q2e.q2e_val[QL_FILE].q2v_cur) {
+               if (vflag || dflag || msgi || msgb || q[QL_BLOCK].q2v_cur ||
+                   q[QL_FILE].q2v_cur) {
                        if (lines++ == 0)
                                heading(type, id, name, "");
                        nam = qup->fsname;
@@ -393,46 +391,38 @@
                        } 
                        if (msgb)
                                timemsg = timeprt(b0, 9, now,
-                                   qup->q2e.q2e_val[QL_BLOCK].q2v_time);
+                                   q[QL_BLOCK].q2v_time);
                        else if ((qup->flags & QUOTA2) != 0 && vflag)
                                timemsg = timeprt(b0, 9, 0,
-                                   qup->q2e.q2e_val[QL_BLOCK].q2v_grace);
+                                   q[QL_BLOCK].q2v_grace);
                        else
                                timemsg = "";
                                
                        printf("%12s%9s%c%8s%9s%8s",
                            nam,
-                           intprt(b1, 9,
-                           qup->q2e.q2e_val[QL_BLOCK].q2v_cur,
+                           intprt(b1, 9, q[QL_BLOCK].q2v_cur,
                            HN_B, hflag),
                            (msgb == NULL) ? ' ' : '*',
-                           intprt(b2, 9,
-                           qup->q2e.q2e_val[QL_BLOCK].q2v_softlimit,
+                           intprt(b2, 9, q[QL_BLOCK].q2v_softlimit,
                            HN_B, hflag),
-                           intprt(b3, 9,
-                           qup->q2e.q2e_val[QL_BLOCK].q2v_hardlimit,
+                           intprt(b3, 9, q[QL_BLOCK].q2v_hardlimit,
                            HN_B, hflag),
                            timemsg);
 
                        if (msgi)
                                timemsg = timeprt(b0, 9, now, 
-                                   qup->q2e.q2e_val[QL_FILE].q2v_time);
+                                   q[QL_FILE].q2v_time);
                        else if ((qup->flags & QUOTA2) != 0 && vflag)
                                timemsg = timeprt(b0, 9, 0,
-                                   qup->q2e.q2e_val[QL_FILE].q2v_grace);
+                                   q[QL_FILE].q2v_grace);
                        else
                                timemsg = "";
                                
                        printf("%8s%c%7s%8s%8s\n",
-                           intprt(b1, 8,
-                           qup->q2e.q2e_val[QL_FILE].q2v_cur, 0, hflag),
+                           intprt(b1, 8, q[QL_FILE].q2v_cur, 0, hflag),
                            (msgi == NULL) ? ' ' : '*',
-                           intprt(b2, 8,
-                           qup->q2e.q2e_val[QL_FILE].q2v_softlimit,
-                           0, hflag),
-                           intprt(b3, 8,
-                           qup->q2e.q2e_val[QL_FILE].q2v_hardlimit,
-                           0, hflag),
+                           intprt(b2, 8, q[QL_FILE].q2v_softlimit, 0, hflag),
+                           intprt(b3, 8, q[QL_FILE].q2v_hardlimit, 0, hflag),
                            timemsg);
                        continue;
                }
@@ -648,16 +638,3 @@
  
        return (int) clnt_stat;
 }
-
-static int
-alldigits(const char *s)
-{
-       unsigned char c;
-
-       c = *s++;
-       do {
-               if (!isdigit(c))
-                       return 0;
-       } while ((c = *s++) != 0);
-       return 1;
-}



Home | Main Index | Thread Index | Old Index