Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/bouyer-quota2]: src Implement "get version" quotactl command, which retu...
details: https://anonhg.NetBSD.org/src/rev/a41688400e91
branches: bouyer-quota2
changeset: 761092:a41688400e91
user: bouyer <bouyer%NetBSD.org@localhost>
date: Sun Jan 30 19:38:45 2011 +0000
description:
Implement "get version" quotactl command, which return the filesystem's
enabled quota versiob (1 for legacy, 2 for new).
For quota2, make quota and repquota print the user's allowed grace period
if -v is given and not overquota (if overquota, the remaining time is
printed instead, as usual).
diffstat:
sys/ufs/ufs/ufs_quota.c | 56 ++++++++++++++-
usr.bin/quota/getvfsquota.c | 101 ++++++++++++++++----------
usr.bin/quota/getvfsquota.h | 5 +-
usr.bin/quota/printquota.c | 9 +-
usr.bin/quota/printquota.h | 4 +-
usr.bin/quota/quota.c | 39 ++++++++--
usr.sbin/edquota/edquota.c | 24 ++++--
usr.sbin/repquota/repquota.c | 161 +++++++++++++++++++++++++++---------------
8 files changed, 272 insertions(+), 127 deletions(-)
diffs (truncated from 725 to 300 lines):
diff -r bd2fd3a0f94a -r a41688400e91 sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c Sun Jan 30 14:28:33 2011 +0000
+++ b/sys/ufs/ufs/ufs_quota.c Sun Jan 30 19:38:45 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_quota.c,v 1.68.4.4 2011/01/30 00:25:19 bouyer Exp $ */
+/* $NetBSD: ufs_quota.c,v 1.68.4.5 2011/01/30 19:38:46 bouyer Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993, 1995
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.4 2011/01/30 00:25:19 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.68.4.5 2011/01/30 19:38:46 bouyer Exp $");
#if defined(_KERNEL_OPT)
#include "opt_quota.h"
@@ -60,6 +60,8 @@
kmutex_t dqlock;
kcondvar_t dqcv;
+static int quota_handle_cmd_get_version(struct mount *, struct lwp *,
+ prop_dictionary_t, prop_array_t);
static int quota_handle_cmd_get(struct mount *, struct lwp *,
prop_dictionary_t, int, prop_array_t);
static int quota_handle_cmd_set(struct mount *, struct lwp *,
@@ -151,6 +153,10 @@
prop_object_retain(datas);
prop_dictionary_remove(cmddict, "data"); /* prepare for return */
+ if (strcmp(cmd, "get version") == 0) {
+ error = quota_handle_cmd_get_version(mp, l, cmddict, datas);
+ goto end;
+ }
if (strcmp(cmd, "get") == 0) {
error = quota_handle_cmd_get(mp, l, cmddict, q2type, datas);
goto end;
@@ -171,6 +177,52 @@
return error;
}
+static int
+quota_handle_cmd_get_version(struct mount *mp, struct lwp *l,
+ prop_dictionary_t cmddict, prop_array_t datas)
+{
+ struct ufsmount *ump = VFSTOUFS(mp);
+ prop_array_t replies;
+ prop_dictionary_t data;
+ int error = 0;
+
+ if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
+ return EOPNOTSUPP;
+
+ replies = prop_array_create();
+ if (replies == NULL)
+ return ENOMEM;
+
+ data = prop_dictionary_create();
+ if (data == NULL) {
+ prop_object_release(replies);
+ return ENOMEM;
+ }
+
+#ifdef QUOTA
+ if (ump->um_flags & UFS_QUOTA) {
+ if (!prop_dictionary_set_int8(data, "version", 1))
+ error = ENOMEM;
+ } else
+#endif
+#ifdef QUOTA2
+ if (ump->um_flags & UFS_QUOTA2) {
+ if (!prop_dictionary_set_int8(data, "version", 2))
+ error = ENOMEM;
+ } else
+#endif
+ error = 0;
+ if (error)
+ prop_object_release(data);
+ else if (!prop_array_add_and_rel(replies, data))
+ error = ENOMEM;
+ if (error)
+ prop_object_release(replies);
+ else if (!prop_dictionary_set_and_rel(cmddict, "data", replies))
+ error = ENOMEM;
+ return error;
+}
+
/* XXX shouldn't all this be in kauth ? */
static int
quota_get_auth(struct mount *mp, struct lwp *l, uid_t id) {
diff -r bd2fd3a0f94a -r a41688400e91 usr.bin/quota/getvfsquota.c
--- a/usr.bin/quota/getvfsquota.c Sun Jan 30 14:28:33 2011 +0000
+++ b/usr.bin/quota/getvfsquota.c Sun Jan 30 19:38:45 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getvfsquota.c,v 1.1.2.1 2011/01/28 22:15:36 bouyer Exp $ */
+/* $NetBSD: getvfsquota.c,v 1.1.2.2 2011/01/30 19:38:45 bouyer Exp $ */
/*-
* Copyright (c) 2011 Manuel Bouyer
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: getvfsquota.c,v 1.1.2.1 2011/01/28 22:15:36 bouyer Exp $");
+__RCSID("$NetBSD: getvfsquota.c,v 1.1.2.2 2011/01/30 19:38:45 bouyer Exp $");
#include <stdio.h>
#include <stdlib.h>
@@ -48,15 +48,17 @@
/* 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)
+getvfsquota(const char *mp, struct quota2_entry *q2e, int8_t *versp,
+ long id, int type, int defaultq, int debug)
{
prop_dictionary_t dict, data, cmd;
prop_array_t cmds, datas;
+ prop_object_iterator_t iter;
struct plistref pref;
int error;
int8_t error8;
bool ret;
+ int retval = 0;
dict = quota2_prop_create();
cmds = prop_array_create();
@@ -78,6 +80,9 @@
prop_object_release(data);
if (!quota2_prop_add_command(cmds, "get", qfextension[type], datas))
err(1, "prop_add_command");
+ if (!quota2_prop_add_command(cmds, "get version", qfextension[type],
+ prop_array_create()))
+ err(1, "prop_add_command");
if (!prop_dictionary_set(dict, "commands", cmds))
err(1, "prop_dictionary_set(command)");
if (debug)
@@ -102,46 +107,64 @@
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)");
+ iter = prop_array_iterator(cmds);
+ if (iter == NULL)
+ err(1, "prop_array_iterator(cmds)");
- if (!prop_dictionary_get_int8(cmd, "return", &error8))
- err(1, "prop_get(return)");
+ while ((cmd = prop_object_iterator_next(iter)) != NULL) {
+ const char *cmdstr;
+ if (!prop_dictionary_get_cstring_nocopy(cmd, "command",
+ &cmdstr))
+ err(1, "prop_get(command)");
+ 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));
+ 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);
}
- prop_object_release(dict);
- return (0);
- }
- datas = prop_dictionary_get(cmd, "data");
- if (datas == NULL)
- err(1, "prop_dict_get(datas)");
+ 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)");
+ if (strcmp("get version", cmdstr) == 0) {
+ data = prop_array_get(datas, 0);
+ if (data == NULL)
+ err(1, "prop_array_get(version)");
+ if (!prop_dictionary_get_int8(data, "version", versp))
+ err(1, "prop_get_int8(version)");
+ continue;
+ }
+ if (strcmp("get", cmdstr) != 0)
+ err(1, "unknown command %s in reply", cmdstr);
+
+ /* only one data, no need to iter */
+ if (prop_array_count(datas) > 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));
+ error = quota2_dict_get_q2e_usage(data, q2e);
+ if (error) {
+ errx(1, "quota2_dict_get_q2e_usage: %s\n",
+ strerror(error));
+ }
+ retval = 1;
+ }
}
prop_object_release(dict);
- return (1);
+ return retval;
}
diff -r bd2fd3a0f94a -r a41688400e91 usr.bin/quota/getvfsquota.h
--- a/usr.bin/quota/getvfsquota.h Sun Jan 30 14:28:33 2011 +0000
+++ b/usr.bin/quota/getvfsquota.h Sun Jan 30 19:38:45 2011 +0000
@@ -1,5 +1,6 @@
-/* $NetBSD: getvfsquota.h,v 1.1.2.1 2011/01/28 22:15:36 bouyer Exp $ */
+/* $NetBSD: getvfsquota.h,v 1.1.2.2 2011/01/30 19:38:45 bouyer Exp $ */
-int getvfsquota(const char *, struct quota2_entry *, long, int, int, int);
+int getvfsquota(const char *, struct quota2_entry *, int8_t *,
+ long, int, int, int);
extern const char *qfextension[];
diff -r bd2fd3a0f94a -r a41688400e91 usr.bin/quota/printquota.c
--- a/usr.bin/quota/printquota.c Sun Jan 30 14:28:33 2011 +0000
+++ b/usr.bin/quota/printquota.c Sun Jan 30 19:38:45 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: printquota.c,v 1.1.2.3 2011/01/30 00:21:08 bouyer Exp $ */
+/* $NetBSD: printquota.c,v 1.1.2.4 2011/01/30 19:38:45 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: printquota.c,v 1.1.2.3 2011/01/30 00:21:08 bouyer Exp $");
+__RCSID("$NetBSD: printquota.c,v 1.1.2.4 2011/01/30 19:38:45 bouyer Exp $");
#endif
#endif /* not lint */
@@ -100,14 +100,11 @@
* Calculate the grace period and return a printable string for it.
*/
const char *
-timeprt(time_t seconds)
+timeprt(time_t now, time_t seconds)
{
time_t hours, minutes;
static char buf[20];
- static time_t now;
- if (now == 0)
- time(&now);
if (now > seconds)
return ("none");
seconds -= now;
diff -r bd2fd3a0f94a -r a41688400e91 usr.bin/quota/printquota.h
--- a/usr.bin/quota/printquota.h Sun Jan 30 14:28:33 2011 +0000
+++ b/usr.bin/quota/printquota.h Sun Jan 30 19:38:45 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: printquota.h,v 1.1.2.3 2011/01/29 17:42:37 bouyer Exp $ */
+/* $NetBSD: printquota.h,v 1.1.2.4 2011/01/30 19:38:45 bouyer Exp $ */
const char *intprt(uint64_t, u_int, int);
#define HN_PRIV_UNLIMITED 0x80000000 /* print "unlimited" instead of "-" */
-const char *timeprt(time_t);
+const char *timeprt(time_t, time_t);
int intrd(char *str, uint64_t *val, u_int);
diff -r bd2fd3a0f94a -r a41688400e91 usr.bin/quota/quota.c
--- a/usr.bin/quota/quota.c Sun Jan 30 14:28:33 2011 +0000
Home |
Main Index |
Thread Index |
Old Index