Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/quotactl Make it build in userlevel and hook it in.



details:   https://anonhg.NetBSD.org/src/rev/75dcee8b6743
branches:  trunk
changeset: 773309:75dcee8b6743
user:      dholland <dholland%NetBSD.org@localhost>
date:      Mon Jan 30 19:28:11 2012 +0000

description:
Make it build in userlevel and hook it in.

diffstat:

 usr.sbin/quotactl/Makefile              |    4 +-
 usr.sbin/quotactl/proplib-interpreter.c |  270 ++++++++++++++-----------------
 usr.sbin/quotactl/proplib-interpreter.h |    2 +
 usr.sbin/quotactl/quotactl.c            |   39 +++-
 4 files changed, 153 insertions(+), 162 deletions(-)

diffs (truncated from 675 to 300 lines):

diff -r 3bceac78676f -r 75dcee8b6743 usr.sbin/quotactl/Makefile
--- a/usr.sbin/quotactl/Makefile        Mon Jan 30 19:23:49 2012 +0000
+++ b/usr.sbin/quotactl/Makefile        Mon Jan 30 19:28:11 2012 +0000
@@ -1,9 +1,9 @@
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
-#      $NetBSD: Makefile,v 1.3 2011/03/25 10:30:35 bouyer Exp $
+#      $NetBSD: Makefile,v 1.4 2012/01/30 19:28:11 dholland Exp $
 
 .include <bsd.own.mk>
 PROG=  quotactl
-SRCS=  quotactl.c
+SRCS=  quotactl.c proplib-interpreter.c
 MAN=   quotactl.8
 
 DPADD= ${LIBQUOTA} ${LIBRPCSVC} ${LIBPROP}
diff -r 3bceac78676f -r 75dcee8b6743 usr.sbin/quotactl/proplib-interpreter.c
--- a/usr.sbin/quotactl/proplib-interpreter.c   Mon Jan 30 19:23:49 2012 +0000
+++ b/usr.sbin/quotactl/proplib-interpreter.c   Mon Jan 30 19:28:11 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proplib-interpreter.c,v 1.1 2012/01/30 19:23:49 dholland Exp $ */
+/*     $NetBSD: proplib-interpreter.c,v 1.2 2012/01/30 19:28:11 dholland Exp $ */
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -84,42 +84,40 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: proplib-interpreter.c,v 1.1 2012/01/30 19:23:49 dholland Exp $");
+__RCSID("$NetBSD: proplib-interpreter.c,v 1.2 2012/01/30 19:28:11 dholland Exp $");
 
-#include <sys/kmem.h>
-#include <sys/mount.h>
-#include <sys/quota.h>
-#include <sys/quotactl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <err.h>
+#include <assert.h>
+
+#include <quota.h>
 #include <quota/quotaprop.h>
 
+#include "proplib-interpreter.h"
+
 static int
-vfs_quotactl_getversion(struct mount *mp,
+vfs_quotactl_getversion(struct quotahandle *qh,
                        prop_dictionary_t cmddict, int q2type,
                        prop_array_t datas)
 {
        prop_array_t replies;
        prop_dictionary_t data;
-       struct quotastat stat;
+       unsigned restrictions;
        int q2version;
-       struct vfs_quotactl_args args;
-       int error;
 
-       KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
-       KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
+       assert(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
+       assert(prop_object_type(datas) == PROP_TYPE_ARRAY);
 
-       args.qc_op = QUOTACTL_STAT;
-       args.u.stat.qc_ret = &stat;
-       error = VFS_QUOTACTL(mp, &args);
-       if (error) {
-               return error;
-       }
+       restrictions = quota_getrestrictions(qh);
 
        /*
         * Set q2version based on the stat results. Currently there
         * are two valid values for q2version, 1 and 2, which we pick
         * based on whether quotacheck is required.
         */
-       if (stat.qs_restrictions & QUOTA_RESTRICT_NEEDSQUOTACHECK) {
+       if (restrictions & QUOTA_RESTRICT_NEEDSQUOTACHECK) {
                q2version = 1;
        } else {
                q2version = 2;
@@ -152,20 +150,19 @@
                return ENOMEM;
        }
 
-       return error;
+       return 0;
 }
 
 static int
-vfs_quotactl_quotaon(struct mount *mp,
+vfs_quotactl_quotaon(struct quotahandle *qh,
                     prop_dictionary_t cmddict, int q2type,
                     prop_array_t datas)
 {
        prop_dictionary_t data;
        const char *qfile;
-       struct vfs_quotactl_args args;
 
-       KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
-       KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
+       assert(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
+       assert(prop_object_type(datas) == PROP_TYPE_ARRAY);
 
        if (prop_array_count(datas) != 1)
                return EINVAL;
@@ -177,28 +174,30 @@
            &qfile))
                return EINVAL;
 
-       args.qc_op = QUOTACTL_QUOTAON;
-       args.u.quotaon.qc_idtype = q2type;
-       args.u.quotaon.qc_quotafile = qfile;
-       return VFS_QUOTACTL(mp, &args);
+       /* libquota knows the filename; cannot set it from here */
+       (void)qfile;
+
+       if (quota_quotaon(qh, q2type)) {
+               return errno;
+       }
+       return 0;
 }
 
 static int
-vfs_quotactl_quotaoff(struct mount *mp,
+vfs_quotactl_quotaoff(struct quotahandle *qh,
                        prop_dictionary_t cmddict, int q2type,
                        prop_array_t datas)
 {
-       struct vfs_quotactl_args args;
-
-       KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
-       KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
+       assert(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
+       assert(prop_object_type(datas) == PROP_TYPE_ARRAY);
 
        if (prop_array_count(datas) != 0)
                return EINVAL;
 
-       args.qc_op = QUOTACTL_QUOTAOFF;
-       args.u.quotaoff.qc_idtype = q2type;
-       return VFS_QUOTACTL(mp, &args);
+       if (quota_quotaoff(qh, q2type)) {
+               return errno;
+       }
+       return 0;
 }
 
 static int
@@ -238,7 +237,7 @@
 }
 
 static int
-vfs_quotactl_get(struct mount *mp,
+vfs_quotactl_get(struct quotahandle *qh,
                        prop_dictionary_t cmddict, int idtype,
                        prop_array_t datas)
 {
@@ -247,13 +246,12 @@
        prop_array_t replies;
        uint32_t id;
        const char *idstr;
-       struct vfs_quotactl_args args;
        struct quotakey qk;
        struct quotaval blocks, files;
        int error;
 
-       KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
-       KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
+       assert(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
+       assert(prop_object_type(datas) == PROP_TYPE_ARRAY);
 
        replies = prop_array_create();
        if (replies == NULL) {
@@ -284,34 +282,32 @@
 
                qk.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
 
-               args.qc_op = QUOTACTL_GET;
-               args.u.get.qc_key = &qk;
-               args.u.get.qc_ret = &blocks;
-               error = VFS_QUOTACTL(mp, &args);
-               if (error == EPERM) {
-                       /* XXX does this make sense? */
-                       continue;
-               } else if (error == ENOENT) {
-                       /* XXX does *this* make sense? */
-                       continue;
-               } else if (error) {
-                       goto fail;
+               if (quota_get(qh, &qk, &blocks)) {
+                       if (errno == EPERM) {
+                               /* XXX does this make sense? */
+                               continue;
+                       } else if (errno == ENOENT) {
+                               /* XXX does *this* make sense? */
+                               continue;
+                       } else {
+                               error = errno;
+                               goto fail;
+                       }
                }
 
                qk.qk_objtype = QUOTA_OBJTYPE_FILES;
 
-               args.qc_op = QUOTACTL_GET;
-               args.u.get.qc_key = &qk;
-               args.u.get.qc_ret = &files;
-               error = VFS_QUOTACTL(mp, &args);
-               if (error == EPERM) {
-                       /* XXX does this make sense? */
-                       continue;
-               } else if (error == ENOENT) {
-                       /* XXX does *this* make sense? */
-                       continue;
-               } else if (error) {
-                       goto fail;
+               if (quota_get(qh, &qk, &files)) {
+                       if (errno == EPERM) {
+                               /* XXX does this make sense? */
+                               continue;
+                       } else if (errno == ENOENT) {
+                               /* XXX does *this* make sense? */
+                               continue;
+                       } else {
+                               error = errno;
+                               goto fail;
+                       }
                }
 
                error = vfs_quotactl_get_addreply(&qk, &blocks, &files,
@@ -386,7 +382,7 @@
 }
 
 static int
-vfs_quotactl_put(struct mount *mp,
+vfs_quotactl_put(struct quotahandle *qh,
                        prop_dictionary_t cmddict, int q2type,
                        prop_array_t datas)
 {
@@ -398,11 +394,10 @@
        const char *idstr;
        struct quotakey qk;
        struct quotaval blocks, files;
-       struct vfs_quotactl_args args;
        int error;
 
-       KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
-       KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY);
+       assert(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY);
+       assert(prop_object_type(datas) == PROP_TYPE_ARRAY);
 
        replies = prop_array_create();
        if (replies == NULL)
@@ -416,7 +411,7 @@
 
        while ((data = prop_object_iterator_next(iter)) != NULL) {
 
-               KASSERT(prop_object_type(data) == PROP_TYPE_DICTIONARY);
+               assert(prop_object_type(data) == PROP_TYPE_DICTIONARY);
 
                if (!prop_dictionary_get_uint32(data, "id", &id)) {
                        if (!prop_dictionary_get_cstring_nocopy(data, "id",
@@ -439,11 +434,8 @@
                qk.qk_id = defaultq ? QUOTA_DEFAULTID : id;
                qk.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
 
-               args.qc_op = QUOTACTL_PUT;
-               args.u.put.qc_key = &qk;
-               args.u.put.qc_val = &blocks;
-               error = VFS_QUOTACTL(mp, &args);
-               if (error) {
+               if (quota_put(qh, &qk, &blocks)) {
+                       error = errno;
                        goto err;
                }
 
@@ -451,11 +443,8 @@
                qk.qk_id = defaultq ? QUOTA_DEFAULTID : id;
                qk.qk_objtype = QUOTA_OBJTYPE_FILES;
 
-               args.qc_op = QUOTACTL_PUT;
-               args.u.put.qc_key = &qk;
-               args.u.put.qc_val = &files;
-               error = VFS_QUOTACTL(mp, &args);
-               if (error) {
+               if (quota_put(qh, &qk, &files)) {
+                       error = errno;
                        goto err;
                }
        }
@@ -554,17 +543,17 @@
 }
 
 static int
-vfs_quotactl_getall(struct mount *mp,
+vfs_quotactl_getall(struct quotahandle *qh,
                        prop_dictionary_t cmddict, int q2type,



Home | Main Index | Thread Index | Old Index