Source-Changes-HG archive

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

[src/trunk]: src/sys Add QUOTACTL_IDTYPESTAT and QUOTACTL_OBJTYPESTAT for ret...



details:   https://anonhg.NetBSD.org/src/rev/d9231196a93f
branches:  trunk
changeset: 773377:d9231196a93f
user:      dholland <dholland%NetBSD.org@localhost>
date:      Wed Feb 01 05:16:56 2012 +0000

description:
Add QUOTACTL_IDTYPESTAT and QUOTACTL_OBJTYPESTAT for retrieving info
about idtypes and objtypes. This avoids compiling in the names of
the id and object types.

I overlooked this last week because the proplib syscall interface has
no way to convey this information.

Renumber the operation codes again (since we still can) to insert
the new operations into the list in a semantically sensible place.

Requires kernel version bump.

diffstat:

 sys/sys/quotactl.h      |  45 +++++++++++++++++++-------
 sys/ufs/ufs/ufs_quota.c |  84 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 115 insertions(+), 14 deletions(-)

diffs (192 lines):

diff -r dbd522026ec6 -r d9231196a93f sys/sys/quotactl.h
--- a/sys/sys/quotactl.h        Wed Feb 01 05:12:45 2012 +0000
+++ b/sys/sys/quotactl.h        Wed Feb 01 05:16:56 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quotactl.h,v 1.31 2012/01/29 19:36:14 dholland Exp $   */
+/*     $NetBSD: quotactl.h,v 1.32 2012/02/01 05:16:56 dholland Exp $   */
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -49,6 +49,17 @@
        unsigned qs_numobjtypes;
        unsigned qs_restrictions;       /* semantic restriction codes */
 };
+
+/*
+ * Structures for QUOTACTL_IDTYPESTAT and QUOTACTL_OBJTYPESTAT.
+ */
+struct quotaidtypestat {
+       char qis_name[QUOTA_NAMELEN];
+};
+struct quotaobjtypestat {
+       char qos_name[QUOTA_NAMELEN];
+       int qos_isbytes;
+};
                         
 /*
  * Semi-opaque structure for cursors. This holds the cursor state in
@@ -66,17 +77,19 @@
 
 /* Command codes. */
 #define QUOTACTL_STAT          0
-#define QUOTACTL_GET           1
-#define QUOTACTL_PUT           2
-#define QUOTACTL_DELETE                3
-#define QUOTACTL_CURSOROPEN    4
-#define QUOTACTL_CURSORCLOSE   5
-#define QUOTACTL_CURSORSKIPIDTYPE 6
-#define QUOTACTL_CURSORGET     7
-#define QUOTACTL_CURSORATEND   8
-#define QUOTACTL_CURSORREWIND  9
-#define QUOTACTL_QUOTAON       10
-#define QUOTACTL_QUOTAOFF      11
+#define QUOTACTL_IDTYPESTAT    1
+#define QUOTACTL_OBJTYPESTAT   2
+#define QUOTACTL_GET           3
+#define QUOTACTL_PUT           4
+#define QUOTACTL_DELETE                5
+#define QUOTACTL_CURSOROPEN    6
+#define QUOTACTL_CURSORCLOSE   7
+#define QUOTACTL_CURSORSKIPIDTYPE 8
+#define QUOTACTL_CURSORGET     9
+#define QUOTACTL_CURSORATEND   10
+#define QUOTACTL_CURSORREWIND  11
+#define QUOTACTL_QUOTAON       12
+#define QUOTACTL_QUOTAOFF      13
 
 /* Argument encoding. */
 struct vfs_quotactl_args {
@@ -86,6 +99,14 @@
                        struct quotastat *qc_ret;
                } stat;
                struct {
+                       int qc_idtype;
+                       struct quotaidtypestat *qc_info;
+               } idtypestat;
+               struct {
+                       int qc_objtype;
+                       struct quotaobjtypestat *qc_info;
+               } objtypestat;
+               struct {
                        const struct quotakey *qc_key;
                        struct quotaval *qc_ret;
                } get;
diff -r dbd522026ec6 -r d9231196a93f sys/ufs/ufs/ufs_quota.c
--- a/sys/ufs/ufs/ufs_quota.c   Wed Feb 01 05:12:45 2012 +0000
+++ b/sys/ufs/ufs/ufs_quota.c   Wed Feb 01 05:16:56 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_quota.c,v 1.105 2012/01/29 11:59:14 para Exp $     */
+/*     $NetBSD: ufs_quota.c,v 1.106 2012/02/01 05:16:56 dholland 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.105 2012/01/29 11:59:14 para Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.106 2012/02/01 05:16:56 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -72,6 +72,10 @@
 
 static int quota_handle_cmd_stat(struct mount *, struct lwp *,
     struct vfs_quotactl_args *args);
+static int quota_handle_cmd_idtypestat(struct mount *, struct lwp *,
+    struct vfs_quotactl_args *args);
+static int quota_handle_cmd_objtypestat(struct mount *, struct lwp *,
+    struct vfs_quotactl_args *args);
 static int quota_handle_cmd_get(struct mount *, struct lwp *,
     struct vfs_quotactl_args *args);
 static int quota_handle_cmd_put(struct mount *, struct lwp *,
@@ -172,6 +176,12 @@
            case QUOTACTL_STAT:
                error = quota_handle_cmd_stat(mp, l, args);
                break;
+           case QUOTACTL_IDTYPESTAT:
+               error = quota_handle_cmd_idtypestat(mp, l, args);
+               break;
+           case QUOTACTL_OBJTYPESTAT:
+               error = quota_handle_cmd_objtypestat(mp, l, args);
+               break;
            case QUOTACTL_QUOTAON:
                error = quota_handle_cmd_quotaon(mp, l, args);
                break;
@@ -250,6 +260,76 @@
        return 0;
 }
 
+static int 
+quota_handle_cmd_idtypestat(struct mount *mp, struct lwp *l, 
+    struct vfs_quotactl_args *args)
+{
+       struct ufsmount *ump = VFSTOUFS(mp);
+       int idtype;
+       struct quotaidtypestat *info;
+       const char *name;
+
+       KASSERT(args->qc_op == QUOTACTL_IDTYPESTAT);
+       idtype = args->u.idtypestat.qc_idtype;
+       info = args->u.idtypestat.qc_info;
+
+       if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
+               return EOPNOTSUPP;
+
+       /*
+        * These are the same for both QUOTA and QUOTA2.
+        */
+       switch (idtype) {
+           case QUOTA_IDTYPE_USER:
+               name = "user";
+               break;
+           case QUOTA_IDTYPE_GROUP:
+               name = "group";
+               break;
+           default:
+               return EINVAL;
+       }
+       strlcpy(info->qis_name, name, sizeof(info->qis_name));
+       return 0;
+}
+
+static int 
+quota_handle_cmd_objtypestat(struct mount *mp, struct lwp *l, 
+    struct vfs_quotactl_args *args)
+{
+       struct ufsmount *ump = VFSTOUFS(mp);
+       int objtype;
+       struct quotaobjtypestat *info;
+       const char *name;
+       int isbytes;
+
+       KASSERT(args->qc_op == QUOTACTL_OBJTYPESTAT);
+       objtype = args->u.objtypestat.qc_objtype;
+       info = args->u.objtypestat.qc_info;
+
+       if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
+               return EOPNOTSUPP;
+
+       /*
+        * These are the same for both QUOTA and QUOTA2.
+        */
+       switch (objtype) {
+           case QUOTA_OBJTYPE_BLOCKS:
+               name = "block";
+               isbytes = 1;
+               break;
+           case QUOTA_OBJTYPE_FILES:
+               name = "file";
+               isbytes = 0;
+               break;
+           default:
+               return EINVAL;
+       }
+       strlcpy(info->qos_name, name, sizeof(info->qos_name));
+       info->qos_isbytes = isbytes;
+       return 0;
+}
+
 /* XXX shouldn't all this be in kauth ? */
 static int
 quota_get_auth(struct mount *mp, struct lwp *l, uid_t id) {



Home | Main Index | Thread Index | Old Index