Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/bouyer-quota2]: src Rename getufsquota to getvfsquota, and abstract in i...
details: https://anonhg.NetBSD.org/src/rev/dfb6974212cd
branches: bouyer-quota2
changeset: 761075:dfb6974212cd
user: bouyer <bouyer%NetBSD.org@localhost>
date: Fri Jan 28 22:15:36 2011 +0000
description:
Rename getufsquota to getvfsquota, and abstract in its own file.
diffstat:
tests/fs/ffs/clients/Makefile | 11 +-
usr.bin/quota/Makefile | 4 +-
usr.bin/quota/getvfsquota.c | 147 ++++++++++++++++++++++++++++++++++++++++++
usr.bin/quota/getvfsquota.h | 5 +
usr.bin/quota/printquota.h | 2 +-
usr.bin/quota/quota.c | 117 +-------------------------------
6 files changed, 167 insertions(+), 119 deletions(-)
diffs (truncated from 385 to 300 lines):
diff -r 0c310357d7ec -r dfb6974212cd tests/fs/ffs/clients/Makefile
--- a/tests/fs/ffs/clients/Makefile Fri Jan 28 18:38:07 2011 +0000
+++ b/tests/fs/ffs/clients/Makefile Fri Jan 28 22:15:36 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.2.1 2011/01/28 18:38:08 bouyer Exp $
+# $NetBSD: Makefile,v 1.1.2.2 2011/01/28 22:15:36 bouyer Exp $
#
.include <bsd.own.mk>
@@ -9,10 +9,11 @@
PROGS= rump_quota rump_repquota
.PATH: ${NETBSDSRCDIR}/usr.bin/quota
-SRCS.rump_quota= quota.c printquota.c quota_rumpops.c
+SRCS.rump_quota= quota.c printquota.c getvfsquota.c quota_rumpops.c
SRCS.rump_repquota= printquota.c quota_rumpops.c
-CPPFLAGS.quota.c+= -I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
-CPPFLAGS.printquota.c+= -I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
+CPPFLAGS.quota.c+= -I${NETBSDSRCDIR}/usr.bin/quota
+CPPFLAGS.printquota.c+= -I${NETBSDSRCDIR}/usr.bin/quota
+CPPFLAGS.getvfsquota.c+=-I${NETBSDSRCDIR}/usr.bin/quota -I${NETBSDSRCDIR}/sys
.PATH: ${NETBSDSRCDIR}/usr.sbin/repquota
SRCS.rump_repquota+= repquota.c
@@ -20,7 +21,7 @@
.PATH: ${NETBSDSRCDIR}/sys/ufs/ufs
SRCS.rump_quota+= quota2_prop.c
-SRCS.rump_repquota+= quota2_prop.c
+SRCS.rump_repquota+= quota2_prop.c quota1_subr.c
CPPFLAGS.quota2_prop.c+=-I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
DPADD.rump_quota= ${LIBRPCSVC} ${LIBPROP} ${LIBRUMPCLIENT}
diff -r 0c310357d7ec -r dfb6974212cd usr.bin/quota/Makefile
--- a/usr.bin/quota/Makefile Fri Jan 28 18:38:07 2011 +0000
+++ b/usr.bin/quota/Makefile Fri Jan 28 22:15:36 2011 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.6.64.2 2011/01/21 16:58:06 bouyer Exp $
+# $NetBSD: Makefile,v 1.6.64.3 2011/01/28 22:15:36 bouyer Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
.include <bsd.own.mk>
PROG= quota
-SRCS= quota.c printquota.c
+SRCS= quota.c printquota.c getvfsquota.c
CPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
DPADD= ${LIBRPCSVC} ${LIBPROP}
diff -r 0c310357d7ec -r dfb6974212cd usr.bin/quota/getvfsquota.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/quota/getvfsquota.c Fri Jan 28 22:15:36 2011 +0000
@@ -0,0 +1,147 @@
+/* $NetBSD: getvfsquota.c,v 1.1.2.1 2011/01/28 22:15:36 bouyer Exp $ */
+
+/*-
+ * Copyright (c) 2011 Manuel Bouyer
+ * All rights reserved.
+ * This software is distributed under the following condiions
+ * compliant with the NetBSD foundation policy.
+ *
+ * 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/cdefs.h>
+__RCSID("$NetBSD: getvfsquota.c,v 1.1.2.1 2011/01/28 22:15:36 bouyer Exp $");
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <err.h>
+#include <string.h>
+
+#include <sys/types.h>
+
+#include <ufs/ufs/quota2_prop.h>
+#include <sys/quota.h>
+
+#include <getvfsquota.h>
+
+const char *qfextension[] = INITQFNAMES;
+
+/* retrieve quotas from vfs, for the given user id */
+int
+getvfsquota(const char *mp, struct quota2_entry *q2e, long id, int type,
+ int defaultq, int debug)
+{
+ prop_dictionary_t dict, data, cmd;
+ prop_array_t cmds, datas;
+ struct plistref pref;
+ int error;
+ int8_t error8;
+ bool ret;
+
+ dict = quota2_prop_create();
+ cmds = prop_array_create();
+ datas = prop_array_create();
+ data = prop_dictionary_create();
+
+ if (dict == NULL || cmds == NULL || datas == NULL || data == NULL)
+ errx(1, "can't allocate proplist");
+
+ if (defaultq)
+ ret = prop_dictionary_set_cstring(data, "id", "default");
+ else
+ ret = prop_dictionary_set_uint32(data, "id", id);
+ if (!ret)
+ err(1, "prop_dictionary_set(id)");
+
+ if (!prop_array_add(datas, data))
+ err(1, "prop_array_add(data)");
+ prop_object_release(data);
+ if (!quota2_prop_add_command(cmds, "get", qfextension[type], datas))
+ err(1, "prop_add_command");
+ if (!prop_dictionary_set(dict, "commands", cmds))
+ err(1, "prop_dictionary_set(command)");
+ if (debug)
+ printf("message to kernel:\n%s\n",
+ prop_dictionary_externalize(dict));
+
+ if (!prop_dictionary_send_syscall(dict, &pref))
+ err(1, "prop_dictionary_send_syscall");
+ prop_object_release(dict);
+
+ if (quotactl(mp, &pref) != 0)
+ err(1, "quotactl");
+
+ if ((error = prop_dictionary_recv_syscall(&pref, &dict)) != 0) {
+ errx(1, "prop_dictionary_recv_syscall: %s\n",
+ strerror(error));
+ }
+ if (debug)
+ printf("reply from kernel:\n%s\n",
+ prop_dictionary_externalize(dict));
+ if ((error = quota2_get_cmds(dict, &cmds)) != 0) {
+ errx(1, "quota2_get_cmds: %s\n",
+ strerror(error));
+ }
+ /* only one command, no need to iter */
+ cmd = prop_array_get(cmds, 0);
+ if (cmd == NULL)
+ err(1, "prop_array_get(cmd)");
+
+ if (!prop_dictionary_get_int8(cmd, "return", &error8))
+ err(1, "prop_get(return)");
+
+ if (error8) {
+ if (error8 != ENOENT && error8 != ENODEV) {
+ if (defaultq)
+ fprintf(stderr, "get default %s quota: %s\n",
+ qfextension[type], strerror(error8));
+ else
+ fprintf(stderr, "get %s quota for %ld: %s\n",
+ qfextension[type], id, strerror(error8));
+ }
+ prop_object_release(dict);
+ return (0);
+ }
+ datas = prop_dictionary_get(cmd, "data");
+ if (datas == NULL)
+ err(1, "prop_dict_get(datas)");
+
+ /* only one data, no need to iter */
+ if (prop_array_count(datas) == 0) {
+ /* no quota for this user/group */
+ prop_object_release(dict);
+ return (0);
+ }
+
+ data = prop_array_get(datas, 0);
+ if (data == NULL)
+ err(1, "prop_array_get(data)");
+
+ error = quota2_dict_get_q2e_usage(data, q2e);
+ if (error) {
+ errx(1, "quota2_dict_get_q2e_usage: %s\n",
+ strerror(error));
+ }
+ prop_object_release(dict);
+ return (1);
+}
diff -r 0c310357d7ec -r dfb6974212cd usr.bin/quota/getvfsquota.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/quota/getvfsquota.h Fri Jan 28 22:15:36 2011 +0000
@@ -0,0 +1,5 @@
+/* $NetBSD: getvfsquota.h,v 1.1.2.1 2011/01/28 22:15:36 bouyer Exp $ */
+
+int getvfsquota(const char *, struct quota2_entry *, long, int, int, int);
+
+extern const char *qfextension[];
diff -r 0c310357d7ec -r dfb6974212cd usr.bin/quota/printquota.h
--- a/usr.bin/quota/printquota.h Fri Jan 28 18:38:07 2011 +0000
+++ b/usr.bin/quota/printquota.h Fri Jan 28 22:15:36 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: printquota.h,v 1.1.2.1 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: printquota.h,v 1.1.2.2 2011/01/28 22:15:36 bouyer Exp $ */
const char *intprt(uint64_t, int, int);
const char *timeprt(time_t);
diff -r 0c310357d7ec -r dfb6974212cd usr.bin/quota/quota.c
--- a/usr.bin/quota/quota.c Fri Jan 28 18:38:07 2011 +0000
+++ b/usr.bin/quota/quota.c Fri Jan 28 22:15:36 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: quota.c,v 1.33.2.2 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: quota.c,v 1.33.2.3 2011/01/28 22:15:36 bouyer Exp $ */
/*
* Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)quota.c 8.4 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: quota.c,v 1.33.2.2 2011/01/21 16:58:06 bouyer Exp $");
+__RCSID("$NetBSD: quota.c,v 1.33.2.3 2011/01/28 22:15:36 bouyer Exp $");
#endif
#endif /* not lint */
@@ -56,9 +56,6 @@
#include <sys/mount.h>
#include <sys/socket.h>
-#include <ufs/ufs/quota2_prop.h>
-#include <sys/quota.h>
-
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -72,11 +69,14 @@
#include <time.h>
#include <unistd.h>
+#include <ufs/ufs/quota2.h>
+
#include <rpc/rpc.h>
#include <rpc/pmap_prot.h>
#include <rpcsvc/rquota.h>
#include <printquota.h>
+#include <getvfsquota.h>
struct quotause {
struct quotause *next;
@@ -100,10 +100,6 @@
void showusrname(const char *);
void usage(void);
-extern const char *qfextension[];
-
-int getufsquota(const char *, struct quota2_entry *, long, int, int, int);
-
int qflag = 0;
int vflag = 0;
int hflag = 0;
@@ -489,7 +485,7 @@
} else if (strncmp(fst[i].f_fstypename, "ffs",
sizeof(fst[i].f_fstypename)) == 0 &&
(fst[i].f_flag & ST_QUOTA) != 0) {
- if (getufsquota(fst[i].f_mntonname, &qup->q2e,
+ if (getvfsquota(fst[i].f_mntonname, &qup->q2e,
id, quotatype, dflag, Dflag) == 0)
continue;
} else
@@ -658,104 +654,3 @@
} while ((c = *s++) != 0);
return (1);
}
-
-const char *qfextension[] = INITQFNAMES;
-
-int
-getufsquota(const char *mp, struct quota2_entry *q2e, long id, int type,
- int defaultq, int debug)
-{
- prop_dictionary_t dict, data, cmd;
- prop_array_t cmds, datas;
- struct plistref pref;
- int error;
- int8_t error8;
- bool ret;
-
- dict = quota2_prop_create();
- cmds = prop_array_create();
Home |
Main Index |
Thread Index |
Old Index