Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/repquota Begin cleaning up repquota.



details:   https://anonhg.NetBSD.org/src/rev/07b75dc8784d
branches:  trunk
changeset: 772606:07b75dc8784d
user:      dholland <dholland%NetBSD.org@localhost>
date:      Mon Jan 09 15:38:20 2012 +0000

description:
Begin cleaning up repquota.

diffstat:

 usr.sbin/repquota/repquota.c |  139 +++++++++++++++++++++---------------------
 1 files changed, 69 insertions(+), 70 deletions(-)

diffs (truncated from 386 to 300 lines):

diff -r 03e500eb6b25 -r 07b75dc8784d usr.sbin/repquota/repquota.c
--- a/usr.sbin/repquota/repquota.c      Mon Jan 09 15:37:34 2012 +0000
+++ b/usr.sbin/repquota/repquota.c      Mon Jan 09 15:38:20 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: repquota.c,v 1.33 2011/11/25 16:55:06 dholland Exp $   */
+/*     $NetBSD: repquota.c,v 1.34 2012/01/09 15:38:20 dholland Exp $   */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)repquota.c 8.2 (Berkeley) 11/22/94";
 #else
-__RCSID("$NetBSD: repquota.c,v 1.33 2011/11/25 16:55:06 dholland Exp $");
+__RCSID("$NetBSD: repquota.c,v 1.34 2012/01/09 15:38:20 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -64,10 +64,9 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <quota/quotaprop.h>
 #include <quota/quota.h>
 #include <ufs/ufs/quota1.h>
-#include <sys/quota.h>
+#include <quota.h>
 
 #include "printquota.h"
 #include "quotautil.h"
@@ -158,18 +157,18 @@
                        continue;
                if (aflag) {
                        if (gflag)
-                               errs += repquota(&fst[i], QUOTA_CLASS_GROUP);
+                               errs += repquota(&fst[i], QUOTA_IDTYPE_GROUP);
                        if (uflag)
-                               errs += repquota(&fst[i], QUOTA_CLASS_USER);
+                               errs += repquota(&fst[i], QUOTA_IDTYPE_USER);
                        continue;
                }
                if ((argnum = oneof(fst[i].f_mntonname, argv, argc)) >= 0 ||
                    (argnum = oneof(fst[i].f_mntfromname, argv, argc)) >= 0) {
                        done |= 1U << argnum;
                        if (gflag)
-                               errs += repquota(&fst[i], QUOTA_CLASS_GROUP);
+                               errs += repquota(&fst[i], QUOTA_IDTYPE_GROUP);
                        if (uflag)
-                               errs += repquota(&fst[i], QUOTA_CLASS_USER);
+                               errs += repquota(&fst[i], QUOTA_IDTYPE_USER);
                }
        }
        if (xflag)
@@ -191,15 +190,15 @@
 }
 
 static int
-repquota(const struct statvfs *vfs, int class)
+repquota(const struct statvfs *vfs, int idtype)
 {
-       if (repquota2(vfs, class) != 0)
-               return repquota1(vfs, class);
+       if (repquota2(vfs, idtype) != 0)
+               return repquota1(vfs, idtype);
        return 0;
 }
 
 static int
-repquota2(const struct statvfs *vfs, int class)
+repquota2(const struct statvfs *vfs, int idtype)
 {
        prop_dictionary_t dict, data, cmd;
        prop_array_t cmds, datas;
@@ -219,10 +218,10 @@
        if (dict == NULL || cmds == NULL || datas == NULL)
                errx(1, "can't allocate proplist");
        if (!quota_prop_add_command(cmds, "getall",
-           ufs_quota_class_names[class], datas))
+           ufs_quota_class_names[idtype], datas))
                err(1, "prop_add_command");
        if (!quota_prop_add_command(cmds, "get version",
-           ufs_quota_class_names[class], prop_array_create()))
+           ufs_quota_class_names[idtype], prop_array_create()))
                err(1, "prop_add_command");
        if (!prop_dictionary_set(dict, "commands", cmds))
                err(1, "prop_dictionary_set(command)");
@@ -263,7 +262,7 @@
                        if (error8 != EOPNOTSUPP) {
                                errno = error8;
                                warn("get %s quotas",
-                                   ufs_quota_class_names[class]);
+                                   ufs_quota_class_names[idtype]);
                        }
                        return error8;
                }
@@ -284,9 +283,9 @@
                if (dataiter == NULL)
                        err(1, "prop_array_iterator");
 
-               valid[class] = 0;
+               valid[idtype] = 0;
                while ((data = prop_object_iterator_next(dataiter)) != NULL) {
-                       valid[class] = 1;
+                       valid[idtype] = 1;
                        strid = NULL;
                        if (!prop_dictionary_get_uint32(data, "id", &id)) {
                                if (!prop_dictionary_get_cstring_nocopy(data,
@@ -297,10 +296,10 @@
                                            "wrong id string %s in quota entry",
                                            strid);
                                }
-                               qvp = defaultqv[class];
+                               qvp = defaultqv[idtype];
                        } else {
-                               if ((fup = lookup(id, class)) == 0)
-                                       fup = addid(id, class, (char *)0);
+                               if ((fup = lookup(id, idtype)) == 0)
+                                       fup = addid(id, idtype, (char *)0);
                                qvp = fup->fu_qv;
                        }
                        values[QUOTA_LIMIT_BLOCK] =
@@ -318,13 +317,13 @@
        }
        prop_object_iterator_release(cmditer);
        prop_object_release(dict);
-       if (xflag == 0 && valid[class])
-               printquotas(class, vfs, version);
+       if (xflag == 0 && valid[idtype])
+               printquotas(idtype, vfs, version);
        return 0;
 }
 
 static int
-repquota1(const struct statvfs *vfs, int class)
+repquota1(const struct statvfs *vfs, int idtype)
 {
        char qfpathname[MAXPATHLEN];
        struct fstab *fs;
@@ -333,7 +332,7 @@
        uint32_t id;
        struct dqblk dqbuf;
        time_t bgrace = MAX_DQ_TIME, igrace = MAX_DQ_TIME;
-       int type = ufsclass2qtype(class);
+       int type = ufsclass2qtype(idtype);
 
        setfsent();
        while ((fs = getfsent()) != NULL) {
@@ -367,27 +366,27 @@
                    dqbuf.dqb_bsoftlimit == 0 && dqbuf.dqb_bhardlimit == 0 &&
                    dqbuf.dqb_isoftlimit == 0 && dqbuf.dqb_ihardlimit == 0)
                        continue;
-               if ((fup = lookup(id, class)) == 0)
-                       fup = addid(id, class, (char *)0);
+               if ((fup = lookup(id, idtype)) == 0)
+                       fup = addid(id, idtype, (char *)0);
                dqblk_to_quotaval(&dqbuf, fup->fu_qv);
                fup->fu_qv[QUOTA_LIMIT_BLOCK].qv_grace = bgrace;
                fup->fu_qv[QUOTA_LIMIT_FILE].qv_grace = igrace;
        }
-       defaultqv[class][QUOTA_LIMIT_BLOCK].qv_grace = bgrace;
-       defaultqv[class][QUOTA_LIMIT_FILE].qv_grace = igrace;
-       defaultqv[class][QUOTA_LIMIT_BLOCK].qv_softlimit = 
-           defaultqv[class][QUOTA_LIMIT_BLOCK].qv_hardlimit = 
-           defaultqv[class][QUOTA_LIMIT_FILE].qv_softlimit = 
-           defaultqv[class][QUOTA_LIMIT_FILE].qv_hardlimit = UQUAD_MAX;
+       defaultqv[idtype][QUOTA_LIMIT_BLOCK].qv_grace = bgrace;
+       defaultqv[idtype][QUOTA_LIMIT_FILE].qv_grace = igrace;
+       defaultqv[idtype][QUOTA_LIMIT_BLOCK].qv_softlimit = 
+           defaultqv[idtype][QUOTA_LIMIT_BLOCK].qv_hardlimit = 
+           defaultqv[idtype][QUOTA_LIMIT_FILE].qv_softlimit = 
+           defaultqv[idtype][QUOTA_LIMIT_FILE].qv_hardlimit = QUOTA_NOLIMIT;
        fclose(qf);
-       valid[class] = 1;
+       valid[idtype] = 1;
        if (xflag == 0)
-               printquotas(class, vfs, 1);
+               printquotas(idtype, vfs, 1);
        return 0;
 }
 
 static void
-printquotas(int class, const struct statvfs *vfs, int version)
+printquotas(int idtype, const struct statvfs *vfs, int version)
 {
        static int multiple = 0;
        uint32_t id;
@@ -399,27 +398,27 @@
        time_t now;
        char b0[2][20], b1[20], b2[20], b3[20];
 
-       switch(class) {
-       case  QUOTA_CLASS_GROUP:
+       switch (idtype) {
+       case QUOTA_IDTYPE_GROUP:
                {
                struct group *gr;
                setgrent();
                while ((gr = getgrent()) != 0)
-                       (void)addid(gr->gr_gid, QUOTA_CLASS_GROUP, gr->gr_name);
+                       (void)addid(gr->gr_gid, idtype, gr->gr_name);
                endgrent();
                break;
                }
-       case QUOTA_CLASS_USER:
+       case QUOTA_IDTYPE_USER:
                {
                struct passwd *pw;
                setpwent();
                while ((pw = getpwent()) != 0)
-                       (void)addid(pw->pw_uid, QUOTA_CLASS_USER, pw->pw_name);
+                       (void)addid(pw->pw_uid, idtype, pw->pw_name);
                endpwent();
                break;
                }
        default:
-               errx(1, "unknown quota class %d", class);
+               errx(1, "Unknown quota ID type %d", idtype);
        }
 
        time(&now);
@@ -428,15 +427,15 @@
                printf("\n");
        if (vflag)
                printf("*** Report for %s quotas on %s (%s, version %d)\n",
-                   ufs_quota_class_names[class], vfs->f_mntonname,
+                   ufs_quota_class_names[idtype], vfs->f_mntonname,
                    vfs->f_mntfromname, version);
        printf("                        Block limits               "
            "File limits\n");
-       printf(class == QUOTA_CLASS_USER ? "User " : "Group");
+       printf(idtype == QUOTA_IDTYPE_USER ? "User " : "Group");
        printf("            used     soft     hard  grace      used"
            "soft    hard  grace\n");
-       for (id = 0; id <= highid[class]; id++) {
-               fup = qremove(id, class);
+       for (id = 0; id <= highid[idtype]; id++) {
+               fup = qremove(id, idtype);
                q = fup->fu_qv;
                if (fup == 0)
                        continue;
@@ -495,7 +494,7 @@
        struct fileusage *fup;
        prop_dictionary_t dict, data;
        prop_array_t cmds, datas;
-       int class;
+       int idtype;
        uint64_t *valuesp[QUOTA_NLIMITS];
 
        dict = quota_prop_create();
@@ -506,16 +505,16 @@
        }
 
 
-       for (class = 0; class < QUOTA_NCLASS; class++) {
-               if (valid[class] == 0)
+       for (idtype = 0; idtype < QUOTA_NCLASS; idtype++) {
+               if (valid[idtype] == 0)
                        continue;
                datas = prop_array_create();
                if (datas == NULL)
                        errx(1, "can't allocate proplist");
                valuesp[QUOTA_LIMIT_BLOCK] =
-                   &defaultqv[class][QUOTA_LIMIT_BLOCK].qv_hardlimit;
+                   &defaultqv[idtype][QUOTA_LIMIT_BLOCK].qv_hardlimit;
                valuesp[QUOTA_LIMIT_FILE] =
-                   &defaultqv[class][QUOTA_LIMIT_FILE].qv_hardlimit;
+                   &defaultqv[idtype][QUOTA_LIMIT_FILE].qv_hardlimit;
                data = quota64toprop(0, 1, valuesp,
                    ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
                    ufs_quota_limit_names, QUOTA_NLIMITS);
@@ -524,8 +523,8 @@
                if (!prop_array_add_and_rel(datas, data))
                        err(1, "prop_array_add(data)");
 
-               for (id = 0; id <= highid[class]; id++) {
-                       fup = qremove(id, class);
+               for (id = 0; id <= highid[idtype]; id++) {
+                       fup = qremove(id, idtype);
                        if (fup == 0)
                                continue;
                        valuesp[QUOTA_LIMIT_BLOCK] =
@@ -543,7 +542,7 @@
                }
 
                if (!quota_prop_add_command(cmds, "set",
-                   ufs_quota_class_names[class], datas))
+                   ufs_quota_class_names[idtype], datas))
                        err(1, "prop_add_command");
        }
 
@@ -557,27 +556,27 @@
 /*
  * Routines to manage the file usage table.
  *
- * Lookup an id of a specific class.
+ * Lookup an id of a specific id type.
  */
 struct fileusage *
-lookup(uint32_t id, int class)
+lookup(uint32_t id, int idtype)



Home | Main Index | Thread Index | Old Index