Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/quotactl Needs its own copy of quotaprop.[ch] too.



details:   https://anonhg.NetBSD.org/src/rev/f5837d255062
branches:  trunk
changeset: 773310:f5837d255062
user:      dholland <dholland%NetBSD.org@localhost>
date:      Mon Jan 30 19:31:31 2012 +0000

description:
Needs its own copy of quotaprop.[ch] too.

diffstat:

 usr.sbin/quotactl/Makefile              |    4 +-
 usr.sbin/quotactl/proplib-interpreter.c |    6 +-
 usr.sbin/quotactl/quotactl.c            |    7 +-
 usr.sbin/quotactl/quotaprop.c           |  214 ++++++++++++++++++++++++++++++++
 usr.sbin/quotactl/quotaprop.h           |   93 +++++++++++++
 5 files changed, 315 insertions(+), 9 deletions(-)

diffs (truncated from 386 to 300 lines):

diff -r 75dcee8b6743 -r f5837d255062 usr.sbin/quotactl/Makefile
--- a/usr.sbin/quotactl/Makefile        Mon Jan 30 19:28:11 2012 +0000
+++ b/usr.sbin/quotactl/Makefile        Mon Jan 30 19:31:31 2012 +0000
@@ -1,9 +1,9 @@
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
-#      $NetBSD: Makefile,v 1.4 2012/01/30 19:28:11 dholland Exp $
+#      $NetBSD: Makefile,v 1.5 2012/01/30 19:31:31 dholland Exp $
 
 .include <bsd.own.mk>
 PROG=  quotactl
-SRCS=  quotactl.c proplib-interpreter.c
+SRCS=  quotactl.c proplib-interpreter.c quotaprop.c
 MAN=   quotactl.8
 
 DPADD= ${LIBQUOTA} ${LIBRPCSVC} ${LIBPROP}
diff -r 75dcee8b6743 -r f5837d255062 usr.sbin/quotactl/proplib-interpreter.c
--- a/usr.sbin/quotactl/proplib-interpreter.c   Mon Jan 30 19:28:11 2012 +0000
+++ b/usr.sbin/quotactl/proplib-interpreter.c   Mon Jan 30 19:31:31 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proplib-interpreter.c,v 1.2 2012/01/30 19:28:11 dholland Exp $ */
+/*     $NetBSD: proplib-interpreter.c,v 1.3 2012/01/30 19:31:31 dholland Exp $ */
 
 /*
  * Copyright (c) 1991, 1993, 1994
@@ -84,7 +84,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: proplib-interpreter.c,v 1.2 2012/01/30 19:28:11 dholland Exp $");
+__RCSID("$NetBSD: proplib-interpreter.c,v 1.3 2012/01/30 19:31:31 dholland Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -93,8 +93,8 @@
 #include <assert.h>
 
 #include <quota.h>
-#include <quota/quotaprop.h>
 
+#include "quotaprop.h"
 #include "proplib-interpreter.h"
 
 static int
diff -r 75dcee8b6743 -r f5837d255062 usr.sbin/quotactl/quotactl.c
--- a/usr.sbin/quotactl/quotactl.c      Mon Jan 30 19:28:11 2012 +0000
+++ b/usr.sbin/quotactl/quotactl.c      Mon Jan 30 19:31:31 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: quotactl.c,v 1.6 2012/01/30 19:28:11 dholland Exp $ */
+/* $NetBSD: quotactl.c,v 1.7 2012/01/30 19:31:31 dholland Exp $ */
 /*-
   * Copyright (c) 2011 Manuel Bouyer
   * All rights reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: quotactl.c,v 1.6 2012/01/30 19:28:11 dholland Exp $");
+__RCSID("$NetBSD: quotactl.c,v 1.7 2012/01/30 19:31:31 dholland Exp $");
 #endif /* not lint */
 
 /*
@@ -46,8 +46,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <quota/quotaprop.h>
-
+#include "quotaprop.h"
 #include "proplib-interpreter.h"
 
 __dead static void usage(void);
diff -r 75dcee8b6743 -r f5837d255062 usr.sbin/quotactl/quotaprop.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/quotactl/quotaprop.c     Mon Jan 30 19:31:31 2012 +0000
@@ -0,0 +1,214 @@
+/* $NetBSD: quotaprop.c,v 1.1 2012/01/30 19:31:31 dholland Exp $ */
+/*-
+  * Copyright (c) 2011 Manuel Bouyer
+  * All rights reserved.
+  *
+  * 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.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+  */
+
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/inttypes.h>
+#include <sys/errno.h>
+
+#include "quotaprop.h"
+
+/*
+ * update values from value[] using dict entries whose key is stored
+ * in name[]. Unknown keys are ignored. If update is false,
+ * a key in name[] but not in dict is an error.
+ * name[] may have NULL pointers to skip a value[]
+ */
+int
+quotaprop_dict_get_uint64(prop_dictionary_t dict, uint64_t value[],
+    const char *name[], int nvalues, bool update)
+{
+       int i;
+       uint64_t v;
+
+       for (i = 0; i < nvalues; i++) {
+               if (name[i] == NULL)
+                       continue;
+               if (!prop_dictionary_get_uint64(dict, name[i], &v)) {
+                       if (!update)
+                               return EINVAL;
+               }
+               value[i] = v;
+       }
+       return 0;
+}
+
+/*
+ * convert a quota entry dictionary to in-memory array of uint64_t's
+ */
+int
+proptoquota64(prop_dictionary_t data, uint64_t *values[], const char *valname[],
+    int nvalues, const char *limname[], int nlimits)
+{
+       int i, error;
+       prop_dictionary_t val;
+
+       for (i = 0; i < nlimits; i++) {
+               if (limname[i] == NULL)
+                       continue;
+               if (!prop_dictionary_get_dict(data, limname[i], &val))
+                       return EINVAL;
+               error = quotaprop_dict_get_uint64(val, values[i],
+                   valname, nvalues, false);
+               if (error)
+                       return error;
+       }
+       return 0;
+}
+
+int
+quota_get_cmds(prop_dictionary_t qdict, prop_array_t *cmds)
+{
+       prop_number_t pn;
+       prop_object_t o;
+
+       pn = prop_dictionary_get(qdict, "interface version");
+       if (pn == NULL)
+               return EINVAL;
+       if (prop_number_integer_value(pn) != 1)
+               return EINVAL;
+
+       o = prop_dictionary_get(qdict, "commands");
+       if (o == NULL)
+               return ENOMEM;
+        if(prop_object_type(o) != PROP_TYPE_ARRAY)
+               return EINVAL;
+       *cmds = o;
+       return 0;
+}
+
+
+prop_dictionary_t
+quota_prop_create(void)
+{
+       prop_dictionary_t dict = prop_dictionary_create();
+
+       if (dict == NULL)
+               return NULL;
+
+       if (!prop_dictionary_set_uint8(dict, "interface version", 1)) {
+               goto err;
+       }
+       return dict;
+err:
+       prop_object_release(dict);
+       return NULL;
+}
+
+bool
+quota_prop_add_command(prop_array_t arrcmd, const char *cmd, const char *type,
+    prop_array_t data)
+{
+       prop_dictionary_t dict;
+
+       dict = prop_dictionary_create();
+       if (dict == NULL) {
+               return false;
+       }
+       if (!prop_dictionary_set_cstring(dict, "type", type)) {
+               goto err;
+       }
+       if (!prop_dictionary_set_cstring(dict, "command", cmd)) {
+               goto err;
+       }
+       if (!prop_dictionary_set_and_rel(dict, "data", data)) {
+               goto err;
+       }
+       if (!prop_array_add(arrcmd, dict)) {
+               goto err;
+       }
+       prop_object_release(dict);
+       return true;
+err:
+       prop_object_release(dict);
+       return false;
+}
+
+/* construct a dictionary using array of values and corresponding keys */
+prop_dictionary_t
+limits64toprop(uint64_t value[], const char *name[], int nvalues)
+{
+       int i;
+       prop_dictionary_t dict1 = prop_dictionary_create();
+       if (dict1 == NULL)
+               return NULL;
+
+       for (i = 0;  i < nvalues; i++) {
+               if (name[i] == NULL)
+                       continue;
+               if (!prop_dictionary_set_uint64(dict1, name[i], value[i])) {
+                       prop_object_release(dict1);
+                       return NULL;
+               }
+       }
+       return dict1;
+}
+
+/*
+ * construct a quota entry using provided array of values, array of values
+ * names
+ */
+prop_dictionary_t
+quota64toprop(uid_t uid, int def, uint64_t *values[], const char *valname[],
+    int nvalues, const char *limname[], int nlimits)
+{
+       prop_dictionary_t dict1 = prop_dictionary_create();
+       prop_dictionary_t dict2;
+       int i;
+
+       if (dict1 == NULL)
+               return NULL;
+       if (def) {
+               if (!prop_dictionary_set_cstring_nocopy(dict1, "id",
+                   "default")) {
+                       goto err;
+               }
+       } else {
+               if (!prop_dictionary_set_uint32(dict1, "id", uid)) {
+                       goto err;
+               }
+       }
+       for (i = 0; i < nlimits; i++) {
+               if (limname[i] == NULL)
+                       continue;
+               dict2 = limits64toprop(values[i], valname, nvalues);
+               if (dict2 == NULL)
+                       goto err;
+               if (!prop_dictionary_set_and_rel(dict1, limname[i],
+                   dict2))
+                       goto err;
+       }
+
+       return dict1;
+err:
+       prop_object_release(dict1);
+       return NULL;
+}
+
+const char *ufs_quota_entry_names[] = UFS_QUOTA_ENTRY_NAMES;
+const char *ufs_quota_limit_names[] = QUOTA_LIMIT_NAMES;
+const char *ufs_quota_class_names[] = QUOTA_CLASS_NAMES;
diff -r 75dcee8b6743 -r f5837d255062 usr.sbin/quotactl/quotaprop.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/quotactl/quotaprop.h     Mon Jan 30 19:31:31 2012 +0000
@@ -0,0 +1,93 @@
+/* $NetBSD: quotaprop.h,v 1.1 2012/01/30 19:31:31 dholland Exp $ */
+/*-
+  * Copyright (c) 2010 Manuel Bouyer
+  * All rights reserved.
+  *
+  * Redistribution and use in source and binary forms, with or without
+  * modification, are permitted provided that the following conditions



Home | Main Index | Thread Index | Old Index