Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libquota Implement the libquota cursor interface, using ...
details: https://anonhg.NetBSD.org/src/rev/03e49cd77e97
branches: trunk
changeset: 772608:03e49cd77e97
user: dholland <dholland%NetBSD.org@localhost>
date: Mon Jan 09 15:40:10 2012 +0000
description:
Implement the libquota cursor interface, using proplib code from repquota.
diffstat:
lib/libquota/quota_cursor.c | 56 +++-
lib/libquota/quota_proplib.c | 469 ++++++++++++++++++++++++++++++++++++++----
lib/libquota/quotapvt.h | 26 ++-
3 files changed, 481 insertions(+), 70 deletions(-)
diffs (truncated from 678 to 300 lines):
diff -r 68341f685e7e -r 03e49cd77e97 lib/libquota/quota_cursor.c
--- a/lib/libquota/quota_cursor.c Mon Jan 09 15:38:59 2012 +0000
+++ b/lib/libquota/quota_cursor.c Mon Jan 09 15:40:10 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: quota_cursor.c,v 1.1 2012/01/09 15:22:38 dholland Exp $ */
+/* $NetBSD: quota_cursor.c,v 1.2 2012/01/09 15:40:10 dholland Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -29,65 +29,81 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: quota_cursor.c,v 1.1 2012/01/09 15:22:38 dholland Exp $");
+__RCSID("$NetBSD: quota_cursor.c,v 1.2 2012/01/09 15:40:10 dholland Exp $");
#include <stdlib.h>
#include <errno.h>
#include <quota.h>
+#include "quotapvt.h"
-/* ARGSUSED */
struct quotacursor *
quota_opencursor(struct quotahandle *qh)
{
- errno = ENOSYS;
- return NULL;
+ struct quotacursor *qc;
+ int serrno;
+
+ if (qh->qh_isnfs) {
+ errno = EOPNOTSUPP;
+ return NULL;
+ }
+
+ qc = malloc(sizeof(*qc));
+ if (qc == NULL) {
+ return NULL;
+ }
+
+ qc->qc_qh = qh;
+ qc->u.qc_proplib = __quota_proplib_cursor_create();
+
+ if (qc->u.qc_proplib == NULL) {
+ serrno = errno;
+ free(qc);
+ errno = serrno;
+ return NULL;
+ }
+ return qc;
}
-/* ARGSUSED */
void
quotacursor_close(struct quotacursor *qc)
{
+ __quota_proplib_cursor_destroy(qc->u.qc_proplib);
+ free(qc);
}
-/* ARGSUSED */
int
quotacursor_skipidtype(struct quotacursor *qc, unsigned idtype)
{
- errno = ENOSYS;
- return -1;
+ return __quota_proplib_cursor_skipidtype(qc->u.qc_proplib, idtype);
}
-/* ARGSUSED */
int
quotacursor_get(struct quotacursor *qc,
struct quotakey *qk_ret, struct quotaval *qv_ret)
{
- errno = ENOSYS;
- return -1;
+ return __quota_proplib_cursor_get(qc->qc_qh, qc->u.qc_proplib,
+ qk_ret, qv_ret);
}
-/* ARGSUSED */
int
quotacursor_getn(struct quotacursor *qc,
struct quotakey *keys, struct quotaval *vals,
unsigned maxnum)
{
- errno = ENOSYS;
- return -1;
+ return __quota_proplib_cursor_getn(qc->qc_qh, qc->u.qc_proplib,
+ keys, vals, maxnum);
}
-/* ARGSUSED */
int
quotacursor_atend(struct quotacursor *qc)
{
- return 0;
+ return __quota_proplib_cursor_atend(qc->qc_qh,
+ qc->u.qc_proplib);
}
-/* ARGSUSED */
int
quotacursor_rewind(struct quotacursor *qc)
{
- errno = ENOSYS;
- return -1;
+ return __quota_proplib_cursor_rewind(qc->u.qc_proplib);
}
diff -r 68341f685e7e -r 03e49cd77e97 lib/libquota/quota_proplib.c
--- a/lib/libquota/quota_proplib.c Mon Jan 09 15:38:59 2012 +0000
+++ b/lib/libquota/quota_proplib.c Mon Jan 09 15:40:10 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: quota_proplib.c,v 1.3 2012/01/09 15:34:34 dholland Exp $ */
+/* $NetBSD: quota_proplib.c,v 1.4 2012/01/09 15:40:10 dholland Exp $ */
/*-
* Copyright (c) 2011 Manuel Bouyer
* All rights reserved.
@@ -26,9 +26,11 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: quota_proplib.c,v 1.3 2012/01/09 15:34:34 dholland Exp $");
+__RCSID("$NetBSD: quota_proplib.c,v 1.4 2012/01/09 15:40:10 dholland Exp $");
+#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include <errno.h>
#include <err.h>
@@ -38,6 +40,21 @@
#include <quota/quotaprop.h>
#include <quota/quota.h>
+struct proplib_quotacursor {
+ prop_array_t users;
+ prop_array_t groups;
+
+ unsigned numusers;
+ unsigned numgroups;
+
+ unsigned haveusers;
+ unsigned havegroups;
+
+ unsigned didusers;
+ unsigned pos;
+ unsigned didblocks;
+};
+
static int
__quota_proplib_getversion(struct quotahandle *qh, int8_t *version_ret)
{
@@ -163,6 +180,63 @@
return "unknown";
}
+static int
+__quota_proplib_extractval(int objtype, prop_dictionary_t data,
+ struct quotaval *qv)
+{
+ uint64_t vals[UFS_QUOTA_NENTRIES];
+ uint64_t *valptrs[1];
+ int limitcode;
+
+ /*
+ * So, the way proptoquota64 works is that you pass it an
+ * array of pointers to uint64. Each of these pointers is
+ * supposed to point to 5 (UFS_QUOTA_NENTRIES) uint64s. This
+ * array of pointers is the second argument. The third and
+ * forth argument are the names of the five values to extract,
+ * and UFS_QUOTA_NENTRIES. The last two arguments are the
+ * names assocated with the pointers (QUOTATYPE_LDICT_BLOCK,
+ * QUOTADICT_LTYPE_FILE) and the number of pointers. Most of
+ * the existing code was unsafely casting struct quotaval
+ * (formerly struct ufs_quota_entry) to (uint64_t *) and using
+ * that as the block of 5 uint64s. I refuse to countenance
+ * that. Also, most of that code extracts both block and file
+ * limits at once (last arguments are ufs_quota_limit_names
+ * and UFS_QUOTA_NLIMITS) but I only need one.
+ */
+
+ switch (objtype) {
+ case QUOTA_OBJTYPE_BLOCKS:
+ limitcode = QUOTA_LIMIT_BLOCK;
+ break;
+ case QUOTA_OBJTYPE_FILES:
+ limitcode = QUOTA_LIMIT_FILE;
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ valptrs[0] = vals;
+ errno = proptoquota64(data, valptrs,
+ ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
+ &ufs_quota_limit_names[limitcode], 1);
+ if (errno) {
+ return -1;
+ }
+
+ /*
+ * there are no symbolic constants for these indexes! XXX
+ */
+ qv->qv_hardlimit = vals[0];
+ qv->qv_softlimit = vals[1];
+ qv->qv_usage = vals[2];
+ qv->qv_expiretime = vals[3];
+ qv->qv_grace = vals[4];
+
+ return 0;
+}
+
int
__quota_proplib_get(struct quotahandle *qh, const struct quotakey *qk,
struct quotaval *qv)
@@ -173,9 +247,6 @@
int8_t error8;
const char *idstr;
const char *cmdstr;
- uint64_t vals[UFS_QUOTA_NENTRIES];
- uint64_t *valptrs[1];
- int limitcode;
int serrno;
switch (qk->qk_idtype) {
@@ -385,56 +456,356 @@
return -1;
}
- /*
- * So, the way proptoquota64 works is that you pass it an
- * array of pointers to uint64. Each of these pointers is
- * supposed to point to 5 (UFS_QUOTA_NENTRIES) uint64s. This
- * array of pointers is the second argument. The third and
- * forth argument are the names of the five values to extract,
- * and UFS_QUOTA_NENTRIES. The last two arguments are the
- * names assocated with the pointers (QUOTATYPE_LDICT_BLOCK,
- * QUOTADICT_LTYPE_FILE) and the number of pointers. Most of
- * the existing code was unsafely casting struct quotaval
- * (formerly struct ufs_quota_entry) to (uint64_t *) and using
- * that as the block of 5 uint64s. I refuse to countenance
- * that. Also, most of that code extracts both block and file
- * limits at once (last arguments are ufs_quota_limit_names
- * and UFS_QUOTA_NLIMITS) but I only need one.
- */
-
- switch (qk->qk_objtype) {
- case QUOTA_OBJTYPE_BLOCKS:
- limitcode = QUOTA_LIMIT_BLOCK;
- break;
- case QUOTA_OBJTYPE_FILES:
- limitcode = QUOTA_LIMIT_FILE;
- break;
- default:
- prop_object_release(dict);
- errno = EINVAL;
- return -1;
- }
-
- valptrs[0] = vals;
- errno = proptoquota64(data, valptrs,
- ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
- &ufs_quota_limit_names[limitcode], 1);
- if (errno) {
+ if (__quota_proplib_extractval(qk->qk_objtype, data, qv)) {
serrno = errno;
prop_object_release(dict);
errno = serrno;
return -1;
}
+
prop_object_release(dict);
- /*
- * there are no symbolic constants for these indexes! XXX
- */
- qv->qv_hardlimit = vals[0];
- qv->qv_softlimit = vals[1];
- qv->qv_usage = vals[2];
- qv->qv_expiretime = vals[3];
- qv->qv_grace = vals[4];
-
return 0;
}
+
+static int
+__quota_proplib_getall(struct quotahandle *qh, int idtype, prop_array_t *ret)
+{
+ prop_dictionary_t dict, cmd;
+ prop_array_t cmds, datas;
+ struct plistref pref;
+ int8_t error8;
+
+ /*
+ * XXX this should not crash out on error. But this is what
+ * the code this came from did... probably because it can just
+ * leak memory instead of needing the proper cleanup code.
Home |
Main Index |
Thread Index |
Old Index