Move proplib frobbing for QUOTACTL_GETVERSION to FS-independent code. Note: this change requires a kernel version bump.diff -r1.5 -r1.6 src/sys/kern/vfs_quotactl.c
(dholland)
--- src/sys/kern/vfs_quotactl.c 2012/01/29 06:36:06 1.5
+++ src/sys/kern/vfs_quotactl.c 2012/01/29 06:36:50 1.6
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: vfs_quotactl.c,v 1.5 2012/01/29 06:36:06 dholland Exp $ */ | 1 | /* $NetBSD: vfs_quotactl.c,v 1.6 2012/01/29 06:36:50 dholland Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1991, 1993, 1994 | 4 | * Copyright (c) 1991, 1993, 1994 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * (c) UNIX System Laboratories, Inc. | 6 | * (c) UNIX System Laboratories, Inc. | |
7 | * All or some portions of this file are derived from material licensed | 7 | * All or some portions of this file are derived from material licensed | |
8 | * to the University of California by American Telephone and Telegraph | 8 | * to the University of California by American Telephone and Telegraph | |
9 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with | 9 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with | |
10 | * the permission of UNIX System Laboratories, Inc. | 10 | * the permission of UNIX System Laboratories, Inc. | |
11 | * | 11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | 12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | 13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | 14 | * are met: | |
@@ -70,44 +70,81 @@ | @@ -70,44 +70,81 @@ | |||
70 | * | 70 | * | |
71 | * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95 | 71 | * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95 | |
72 | * From NetBSD: ufs_quota.c,v 1.70 2011/03/24 17:05:46 bouyer Exp | 72 | * From NetBSD: ufs_quota.c,v 1.70 2011/03/24 17:05:46 bouyer Exp | |
73 | */ | 73 | */ | |
74 | 74 | |||
75 | /* | 75 | /* | |
76 | * Note that both of the copyrights above are moderately spurious; | 76 | * Note that both of the copyrights above are moderately spurious; | |
77 | * this code should almost certainly have the Copyright 2010 Manuel | 77 | * this code should almost certainly have the Copyright 2010 Manuel | |
78 | * Bouyer notice and license found in e.g. sys/ufs/ufs/quota2_subr.c. | 78 | * Bouyer notice and license found in e.g. sys/ufs/ufs/quota2_subr.c. | |
79 | * However, they're what was on the files this code was sliced out of. | 79 | * However, they're what was on the files this code was sliced out of. | |
80 | */ | 80 | */ | |
81 | 81 | |||
82 | #include <sys/cdefs.h> | 82 | #include <sys/cdefs.h> | |
83 | __KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.5 2012/01/29 06:36:06 dholland Exp $"); | 83 | __KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.6 2012/01/29 06:36:50 dholland Exp $"); | |
84 | 84 | |||
85 | #include <sys/mount.h> | 85 | #include <sys/mount.h> | |
86 | #include <sys/quotactl.h> | 86 | #include <sys/quotactl.h> | |
87 | #include <quota/quotaprop.h> | 87 | #include <quota/quotaprop.h> | |
88 | 88 | |||
89 | static int | 89 | static int | |
90 | vfs_quotactl_getversion(struct mount *mp, | 90 | vfs_quotactl_getversion(struct mount *mp, | |
91 | prop_dictionary_t cmddict, int q2type, | 91 | prop_dictionary_t cmddict, int q2type, | |
92 | prop_array_t datas) | 92 | prop_array_t datas) | |
93 | { | 93 | { | |
94 | prop_array_t replies; | |||
95 | prop_dictionary_t data; | |||
96 | int q2version; | |||
94 | struct vfs_quotactl_args args; | 97 | struct vfs_quotactl_args args; | |
98 | int error; | |||
95 | 99 | |||
96 | args.qc_type = QCT_PROPLIB; | 100 | KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY); | |
97 | args.u.proplib.qc_cmddict = cmddict; | 101 | KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY); | |
98 | args.u.proplib.qc_q2type = q2type; | 102 | ||
99 | args.u.proplib.qc_datas = datas; | 103 | args.qc_type = QCT_GETVERSION; | |
100 | return VFS_QUOTACTL(mp, QUOTACTL_GETVERSION, &args); | 104 | args.u.getversion.qc_version_ret = &q2version; | |
105 | error = VFS_QUOTACTL(mp, QUOTACTL_GETVERSION, &args); | |||
106 | if (error) { | |||
107 | return error; | |||
108 | } | |||
109 | ||||
110 | data = prop_dictionary_create(); | |||
111 | if (data == NULL) { | |||
112 | return ENOMEM; | |||
113 | } | |||
114 | ||||
115 | if (!prop_dictionary_set_int8(data, "version", q2version)) { | |||
116 | prop_object_release(data); | |||
117 | return ENOMEM; | |||
118 | } | |||
119 | ||||
120 | replies = prop_array_create(); | |||
121 | if (replies == NULL) { | |||
122 | prop_object_release(data); | |||
123 | return ENOMEM; | |||
124 | } | |||
125 | ||||
126 | if (!prop_array_add_and_rel(replies, data)) { | |||
127 | prop_object_release(data); | |||
128 | prop_object_release(replies); | |||
129 | return ENOMEM; | |||
130 | } | |||
131 | ||||
132 | if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) { | |||
133 | prop_object_release(replies); | |||
134 | return ENOMEM; | |||
135 | } | |||
136 | ||||
137 | return error; | |||
101 | } | 138 | } | |
102 | 139 | |||
103 | static int | 140 | static int | |
104 | vfs_quotactl_quotaon(struct mount *mp, | 141 | vfs_quotactl_quotaon(struct mount *mp, | |
105 | prop_dictionary_t cmddict, int q2type, | 142 | prop_dictionary_t cmddict, int q2type, | |
106 | prop_array_t datas) | 143 | prop_array_t datas) | |
107 | { | 144 | { | |
108 | struct vfs_quotactl_args args; | 145 | struct vfs_quotactl_args args; | |
109 | 146 | |||
110 | args.qc_type = QCT_PROPLIB; | 147 | args.qc_type = QCT_PROPLIB; | |
111 | args.u.proplib.qc_cmddict = cmddict; | 148 | args.u.proplib.qc_cmddict = cmddict; | |
112 | args.u.proplib.qc_q2type = q2type; | 149 | args.u.proplib.qc_q2type = q2type; | |
113 | args.u.proplib.qc_datas = datas; | 150 | args.u.proplib.qc_datas = datas; |
--- src/sys/sys/quotactl.h 2012/01/29 06:36:06 1.3
+++ src/sys/sys/quotactl.h 2012/01/29 06:36:50 1.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: quotactl.h,v 1.3 2012/01/29 06:36:06 dholland Exp $ */ | 1 | /* $NetBSD: quotactl.h,v 1.4 2012/01/29 06:36:50 dholland Exp $ */ | |
2 | /*- | 2 | /*- | |
3 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | 3 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | |
4 | * All rights reserved. | 4 | * All rights reserved. | |
5 | * | 5 | * | |
6 | * This code is derived from software contributed to The NetBSD Foundation | 6 | * This code is derived from software contributed to The NetBSD Foundation | |
7 | * by David A. Holland. | 7 | * by David A. Holland. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -38,27 +38,31 @@ | @@ -38,27 +38,31 @@ | |||
38 | */ | 38 | */ | |
39 | 39 | |||
40 | /* Command codes. */ | 40 | /* Command codes. */ | |
41 | #define QUOTACTL_GETVERSION 0 | 41 | #define QUOTACTL_GETVERSION 0 | |
42 | #define QUOTACTL_QUOTAON 1 | 42 | #define QUOTACTL_QUOTAON 1 | |
43 | #define QUOTACTL_QUOTAOFF 2 | 43 | #define QUOTACTL_QUOTAOFF 2 | |
44 | #define QUOTACTL_GET 3 | 44 | #define QUOTACTL_GET 3 | |
45 | #define QUOTACTL_SET 4 | 45 | #define QUOTACTL_SET 4 | |
46 | #define QUOTACTL_GETALL 5 | 46 | #define QUOTACTL_GETALL 5 | |
47 | #define QUOTACTL_CLEAR 6 | 47 | #define QUOTACTL_CLEAR 6 | |
48 | 48 | |||
49 | /* Argument encoding. */ | 49 | /* Argument encoding. */ | |
50 | enum vfs_quotactl_argtypes { | 50 | enum vfs_quotactl_argtypes { | |
51 | QCT_PROPLIB, /* getversion, quotaon/off, get, set, getall, clear */ | 51 | QCT_PROPLIB, /* quotaon/off, get, set, getall, clear */ | |
52 | QCT_GETVERSION, /* getversion */ | |||
52 | }; | 53 | }; | |
53 | struct vfs_quotactl_args { | 54 | struct vfs_quotactl_args { | |
54 | enum vfs_quotactl_argtypes qc_type; | 55 | enum vfs_quotactl_argtypes qc_type; | |
55 | union { | 56 | union { | |
56 | struct { | 57 | struct { | |
57 | prop_dictionary_t qc_cmddict; | 58 | prop_dictionary_t qc_cmddict; | |
58 | int qc_q2type; | 59 | int qc_q2type; | |
59 | prop_array_t qc_datas; | 60 | prop_array_t qc_datas; | |
60 | } proplib; | 61 | } proplib; | |
62 | struct { | |||
63 | int *qc_version_ret; | |||
64 | } getversion; | |||
61 | } u; | 65 | } u; | |
62 | }; | 66 | }; | |
63 | 67 | |||
64 | #endif /* _SYS_QUOTACTL_H_ */ | 68 | #endif /* _SYS_QUOTACTL_H_ */ |
--- src/sys/ufs/ufs/ufs_quota.c 2012/01/29 06:36:07 1.72
+++ src/sys/ufs/ufs/ufs_quota.c 2012/01/29 06:36:51 1.73
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ufs_quota.c,v 1.72 2012/01/29 06:36:07 dholland Exp $ */ | 1 | /* $NetBSD: ufs_quota.c,v 1.73 2012/01/29 06:36:51 dholland Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1982, 1986, 1990, 1993, 1995 | 4 | * Copyright (c) 1982, 1986, 1990, 1993, 1995 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Robert Elz at The University of Melbourne. | 8 | * Robert Elz at The University of Melbourne. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | * | 33 | * | |
34 | * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95 | 34 | * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95 | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | __KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.72 2012/01/29 06:36:07 dholland Exp $"); | 38 | __KERNEL_RCSID(0, "$NetBSD: ufs_quota.c,v 1.73 2012/01/29 06:36:51 dholland Exp $"); | |
39 | 39 | |||
40 | #if defined(_KERNEL_OPT) | 40 | #if defined(_KERNEL_OPT) | |
41 | #include "opt_quota.h" | 41 | #include "opt_quota.h" | |
42 | #endif | 42 | #endif | |
43 | #include <sys/param.h> | 43 | #include <sys/param.h> | |
44 | #include <sys/kernel.h> | 44 | #include <sys/kernel.h> | |
45 | #include <sys/systm.h> | 45 | #include <sys/systm.h> | |
46 | #include <sys/namei.h> | 46 | #include <sys/namei.h> | |
47 | #include <sys/file.h> | 47 | #include <sys/file.h> | |
48 | #include <sys/proc.h> | 48 | #include <sys/proc.h> | |
49 | #include <sys/vnode.h> | 49 | #include <sys/vnode.h> | |
50 | #include <sys/mount.h> | 50 | #include <sys/mount.h> | |
51 | #include <sys/kauth.h> | 51 | #include <sys/kauth.h> | |
@@ -183,75 +183,47 @@ quota_handle_cmd(struct mount *mp, struc | @@ -183,75 +183,47 @@ quota_handle_cmd(struct mount *mp, struc | |||
183 | break; | 183 | break; | |
184 | default: | 184 | default: | |
185 | panic("Invalid quotactl operation %d\n", op); | 185 | panic("Invalid quotactl operation %d\n", op); | |
186 | } | 186 | } | |
187 | 187 | |||
188 | return error; | 188 | return error; | |
189 | } | 189 | } | |
190 | 190 | |||
191 | static int | 191 | static int | |
192 | quota_handle_cmd_get_version(struct mount *mp, struct lwp *l, | 192 | quota_handle_cmd_get_version(struct mount *mp, struct lwp *l, | |
193 | struct vfs_quotactl_args *args) | 193 | struct vfs_quotactl_args *args) | |
194 | { | 194 | { | |
195 | struct ufsmount *ump = VFSTOUFS(mp); | 195 | struct ufsmount *ump = VFSTOUFS(mp); | |
196 | prop_array_t replies; | 196 | int *version_ret; | |
197 | prop_dictionary_t data; | |||
198 | int error = 0; | |||
199 | prop_dictionary_t cmddict; | |||
200 | prop_array_t datas; | |||
201 | 197 | |||
202 | KASSERT(args->qc_type == QCT_PROPLIB); | 198 | KASSERT(args->qc_type == QCT_GETVERSION); | |
203 | cmddict = args->u.proplib.qc_cmddict; | 199 | version_ret = args->u.getversion.qc_version_ret; | |
204 | /* qc_q2type not used */ | |||
205 | datas = args->u.proplib.qc_datas; | |||
206 | ||||
207 | KASSERT(prop_object_type(cmddict) == PROP_TYPE_DICTIONARY); | |||
208 | KASSERT(prop_object_type(datas) == PROP_TYPE_ARRAY); | |||
209 | 200 | |||
210 | if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0) | 201 | if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0) | |
211 | return EOPNOTSUPP; | 202 | return EOPNOTSUPP; | |
212 | 203 | |||
213 | replies = prop_array_create(); | |||
214 | if (replies == NULL) | |||
215 | return ENOMEM; | |||
216 | ||||
217 | data = prop_dictionary_create(); | |||
218 | if (data == NULL) { | |||
219 | prop_object_release(replies); | |||
220 | return ENOMEM; | |||
221 | } | |||
222 | ||||
223 | #ifdef QUOTA | 204 | #ifdef QUOTA | |
224 | if (ump->um_flags & UFS_QUOTA) { | 205 | if (ump->um_flags & UFS_QUOTA) { | |
225 | if (!prop_dictionary_set_int8(data, "version", 1)) | 206 | *version_ret = 1; | |
226 | error = ENOMEM; | |||
227 | } else | 207 | } else | |
228 | #endif | 208 | #endif | |
229 | #ifdef QUOTA2 | 209 | #ifdef QUOTA2 | |
230 | if (ump->um_flags & UFS_QUOTA2) { | 210 | if (ump->um_flags & UFS_QUOTA2) { | |
231 | if (!prop_dictionary_set_int8(data, "version", 2)) | 211 | *version_ret = 2; | |
232 | error = ENOMEM; | |||
233 | } else | 212 | } else | |
234 | #endif | 213 | #endif | |
235 | error = 0; | 214 | return EOPNOTSUPP; | |
236 | if (error) | 215 | ||
237 | prop_object_release(data); | 216 | return 0; | |
238 | else if (!prop_array_add_and_rel(replies, data)) | |||
239 | error = ENOMEM; | |||
240 | if (error) | |||
241 | prop_object_release(replies); | |||
242 | else if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) | |||
243 | error = ENOMEM; | |||
244 | return error; | |||
245 | } | 217 | } | |
246 | 218 | |||
247 | /* XXX shouldn't all this be in kauth ? */ | 219 | /* XXX shouldn't all this be in kauth ? */ | |
248 | static int | 220 | static int | |
249 | quota_get_auth(struct mount *mp, struct lwp *l, uid_t id) { | 221 | quota_get_auth(struct mount *mp, struct lwp *l, uid_t id) { | |
250 | /* The user can always query about his own quota. */ | 222 | /* The user can always query about his own quota. */ | |
251 | if (id == kauth_cred_getuid(l->l_cred)) | 223 | if (id == kauth_cred_getuid(l->l_cred)) | |
252 | return 0; | 224 | return 0; | |
253 | return kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA, | 225 | return kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA, | |
254 | KAUTH_REQ_SYSTEM_FS_QUOTA_GET, mp, KAUTH_ARG(id), NULL); | 226 | KAUTH_REQ_SYSTEM_FS_QUOTA_GET, mp, KAUTH_ARG(id), NULL); | |
255 | } | 227 | } | |
256 | 228 | |||
257 | static int | 229 | static int |