Module Name:    src
Committed By:   dholland
Date:           Wed Feb  1 05:16:56 UTC 2012

Modified Files:
        src/sys/sys: quotactl.h
        src/sys/ufs/ufs: ufs_quota.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/sys/quotactl.h
cvs rdiff -u -r1.105 -r1.106 src/sys/ufs/ufs/ufs_quota.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/quotactl.h
diff -u src/sys/sys/quotactl.h:1.31 src/sys/sys/quotactl.h:1.32
--- src/sys/sys/quotactl.h:1.31	Sun Jan 29 19:36:14 2012
+++ src/sys/sys/quotactl.h	Wed Feb  1 05:16:56 2012
@@ -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 @@ struct quotastat {
 	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 @@ struct quotakcursor {
 
 /* 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 vfs_quotactl_args {
 			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;

Index: src/sys/ufs/ufs/ufs_quota.c
diff -u src/sys/ufs/ufs/ufs_quota.c:1.105 src/sys/ufs/ufs/ufs_quota.c:1.106
--- src/sys/ufs/ufs/ufs_quota.c:1.105	Sun Jan 29 11:59:14 2012
+++ src/sys/ufs/ufs/ufs_quota.c	Wed Feb  1 05:16:56 2012
@@ -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 pool_cache_t dquot_cache;
 
 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 @@ quota_handle_cmd(struct mount *mp, struc
 	    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 @@ quota_handle_cmd_stat(struct mount *mp, 
 	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) {

Reply via email to