Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/quotactl Add a copy of the proplib interpreter here...



details:   https://anonhg.NetBSD.org/src/rev/3bceac78676f
branches:  trunk
changeset: 773308:3bceac78676f
user:      dholland <dholland%NetBSD.org@localhost>
date:      Mon Jan 30 19:23:49 2012 +0000

description:
Add a copy of the proplib interpreter here so this program will
continue to work after it's removed from the kernel. This copy is
unchanged from sys/kern/vfs_quotactl.c except that I've preserved a
cop of the old rcsid.

diffstat:

 usr.sbin/quotactl/proplib-interpreter.c |  908 ++++++++++++++++++++++++++++++++
 1 files changed, 908 insertions(+), 0 deletions(-)

diffs (truncated from 912 to 300 lines):

diff -r 894cdff15315 -r 3bceac78676f usr.sbin/quotactl/proplib-interpreter.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/quotactl/proplib-interpreter.c   Mon Jan 30 19:23:49 2012 +0000
@@ -0,0 +1,908 @@
+/*     $NetBSD: proplib-interpreter.c,v 1.1 2012/01/30 19:23:49 dholland Exp $ */
+
+/*
+ * Copyright (c) 1991, 1993, 1994
+ *     The Regents of the University of California.  All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ufs_vfsops.c        8.8 (Berkeley) 5/20/95
+ *     From NetBSD: ufs_vfsops.c,v 1.42 2011/03/24 17:05:46 bouyer Exp
+ */
+
+/*
+ * Copyright (c) 1982, 1986, 1990, 1993, 1995
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Robert Elz at The University of Melbourne.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95
+ *     From NetBSD: ufs_quota.c,v 1.70 2011/03/24 17:05:46 bouyer Exp
+ */
+
+/*
+ *     From NetBSD: vfs_quotactl.c,v 1.36 2012/01/29 07:21:59 dholland Exp
+ */
+
+/*
+ * Note that both of the copyrights above are moderately spurious;
+ * this code should almost certainly have the Copyright 2010 Manuel
+ * Bouyer notice and license found in e.g. sys/ufs/ufs/quota2_subr.c.
+ * However, they're what was on the files this code was sliced out of.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: proplib-interpreter.c,v 1.1 2012/01/30 19:23:49 dholland Exp $");
+
+#include <sys/kmem.h>
+#include <sys/mount.h>
+#include <sys/quota.h>
+#include <sys/quotactl.h>
+#include <quota/quotaprop.h>
+
+static int
+vfs_quotactl_getversion(struct mount *mp,
+                       prop_dictionary_t cmddict, int q2type,
+                       prop_array_t datas)
+{
+       prop_array_t replies;
+       prop_dictionary_t data;
+       struct quotastat stat;
+       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);
+
+       args.qc_op = QUOTACTL_STAT;
+       args.u.stat.qc_ret = &stat;
+       error = VFS_QUOTACTL(mp, &args);
+       if (error) {
+               return error;
+       }
+
+       /*
+        * 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) {
+               q2version = 1;
+       } else {
+               q2version = 2;
+       }
+
+       data = prop_dictionary_create();
+       if (data == NULL) {
+               return ENOMEM;
+       }
+
+       if (!prop_dictionary_set_int8(data, "version", q2version)) {
+               prop_object_release(data);
+               return ENOMEM;
+       }
+
+       replies = prop_array_create();
+       if (replies == NULL) {
+               prop_object_release(data);
+               return ENOMEM;
+       }
+
+       if (!prop_array_add_and_rel(replies, data)) {
+               prop_object_release(data);
+               prop_object_release(replies);
+               return ENOMEM;
+       }
+
+       if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
+               prop_object_release(replies);
+               return ENOMEM;
+       }
+
+       return error;
+}
+
+static int
+vfs_quotactl_quotaon(struct mount *mp,
+                    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);
+
+       if (prop_array_count(datas) != 1)
+               return EINVAL;
+
+       data = prop_array_get(datas, 0);
+       if (data == NULL)
+               return ENOMEM;
+       if (!prop_dictionary_get_cstring_nocopy(data, "quotafile",
+           &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);
+}
+
+static int
+vfs_quotactl_quotaoff(struct mount *mp,
+                       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);
+
+       if (prop_array_count(datas) != 0)
+               return EINVAL;
+
+       args.qc_op = QUOTACTL_QUOTAOFF;
+       args.u.quotaoff.qc_idtype = q2type;
+       return VFS_QUOTACTL(mp, &args);
+}
+
+static int
+vfs_quotactl_get_addreply(const struct quotakey *qk,
+                         const struct quotaval *blocks,
+                         const struct quotaval *files,
+                         prop_array_t replies)
+{
+       prop_dictionary_t dict;
+       id_t id;
+       int defaultq;
+       uint64_t *valuesp[QUOTA_NLIMITS];
+
+       /* XXX illegal casts */
+       valuesp[QUOTA_LIMIT_BLOCK] = (void *)(intptr_t)&blocks->qv_hardlimit;
+       valuesp[QUOTA_LIMIT_FILE] =  (void *)(intptr_t)&files->qv_hardlimit;
+
+       if (qk->qk_id == QUOTA_DEFAULTID) {
+               id = 0;
+               defaultq = 1;
+       } else {
+               id = qk->qk_id;
+               defaultq = 0;
+       }
+
+       dict = quota64toprop(id, defaultq, valuesp,
+           ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
+           ufs_quota_limit_names, QUOTA_NLIMITS);
+       if (dict == NULL)
+               return ENOMEM;
+       if (!prop_array_add_and_rel(replies, dict)) {
+               prop_object_release(dict);
+               return ENOMEM;
+       }
+
+       return 0;
+}
+
+static int
+vfs_quotactl_get(struct mount *mp,
+                       prop_dictionary_t cmddict, int idtype,
+                       prop_array_t datas)
+{
+       prop_object_iterator_t iter;
+       prop_dictionary_t data;
+       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);
+
+       replies = prop_array_create();
+       if (replies == NULL) {
+               return ENOMEM;
+       }
+
+       iter = prop_array_iterator(datas);
+       if (iter == NULL) {
+               prop_object_release(replies);
+               return ENOMEM;
+       }
+
+       while ((data = prop_object_iterator_next(iter)) != NULL) {
+               qk.qk_idtype = idtype;
+
+               if (!prop_dictionary_get_uint32(data, "id", &id)) {
+                       if (!prop_dictionary_get_cstring_nocopy(data, "id",
+                           &idstr))
+                               continue;
+                       if (strcmp(idstr, "default")) {
+                               error = EINVAL;
+                               goto fail;
+                       }
+                       qk.qk_id = QUOTA_DEFAULTID;
+               } else {
+                       qk.qk_id = id;
+               }
+
+               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;



Home | Main Index | Thread Index | Old Index