vfs_quotactl.c revision 1.4 1 1.4 dholland /* $NetBSD: vfs_quotactl.c,v 1.4 2012/01/29 06:34:57 dholland Exp $ */
2 1.3 dholland
3 1.3 dholland /*
4 1.3 dholland * Copyright (c) 1991, 1993, 1994
5 1.3 dholland * The Regents of the University of California. All rights reserved.
6 1.3 dholland * (c) UNIX System Laboratories, Inc.
7 1.3 dholland * All or some portions of this file are derived from material licensed
8 1.3 dholland * to the University of California by American Telephone and Telegraph
9 1.3 dholland * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.3 dholland * the permission of UNIX System Laboratories, Inc.
11 1.3 dholland *
12 1.3 dholland * Redistribution and use in source and binary forms, with or without
13 1.3 dholland * modification, are permitted provided that the following conditions
14 1.3 dholland * are met:
15 1.3 dholland * 1. Redistributions of source code must retain the above copyright
16 1.3 dholland * notice, this list of conditions and the following disclaimer.
17 1.3 dholland * 2. Redistributions in binary form must reproduce the above copyright
18 1.3 dholland * notice, this list of conditions and the following disclaimer in the
19 1.3 dholland * documentation and/or other materials provided with the distribution.
20 1.3 dholland * 3. Neither the name of the University nor the names of its contributors
21 1.3 dholland * may be used to endorse or promote products derived from this software
22 1.3 dholland * without specific prior written permission.
23 1.3 dholland *
24 1.3 dholland * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.3 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.3 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.3 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.3 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.3 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.3 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.3 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.3 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.3 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.3 dholland * SUCH DAMAGE.
35 1.3 dholland *
36 1.3 dholland * @(#)ufs_vfsops.c 8.8 (Berkeley) 5/20/95
37 1.3 dholland * From NetBSD: ufs_vfsops.c,v 1.42 2011/03/24 17:05:46 bouyer Exp
38 1.3 dholland */
39 1.1 dholland
40 1.1 dholland /*
41 1.1 dholland * Copyright (c) 1982, 1986, 1990, 1993, 1995
42 1.1 dholland * The Regents of the University of California. All rights reserved.
43 1.1 dholland *
44 1.1 dholland * This code is derived from software contributed to Berkeley by
45 1.1 dholland * Robert Elz at The University of Melbourne.
46 1.1 dholland *
47 1.1 dholland * Redistribution and use in source and binary forms, with or without
48 1.1 dholland * modification, are permitted provided that the following conditions
49 1.1 dholland * are met:
50 1.1 dholland * 1. Redistributions of source code must retain the above copyright
51 1.1 dholland * notice, this list of conditions and the following disclaimer.
52 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright
53 1.1 dholland * notice, this list of conditions and the following disclaimer in the
54 1.1 dholland * documentation and/or other materials provided with the distribution.
55 1.1 dholland * 3. Neither the name of the University nor the names of its contributors
56 1.1 dholland * may be used to endorse or promote products derived from this software
57 1.1 dholland * without specific prior written permission.
58 1.1 dholland *
59 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 dholland * SUCH DAMAGE.
70 1.1 dholland *
71 1.1 dholland * @(#)ufs_quota.c 8.5 (Berkeley) 5/20/95
72 1.3 dholland * From NetBSD: ufs_quota.c,v 1.70 2011/03/24 17:05:46 bouyer Exp
73 1.3 dholland */
74 1.3 dholland
75 1.3 dholland /*
76 1.3 dholland * Note that both of the copyrights above are moderately spurious;
77 1.3 dholland * this code should almost certainly have the Copyright 2010 Manuel
78 1.3 dholland * Bouyer notice and license found in e.g. sys/ufs/ufs/quota2_subr.c.
79 1.3 dholland * However, they're what was on the files this code was sliced out of.
80 1.1 dholland */
81 1.1 dholland
82 1.1 dholland #include <sys/cdefs.h>
83 1.4 dholland __KERNEL_RCSID(0, "$NetBSD: vfs_quotactl.c,v 1.4 2012/01/29 06:34:57 dholland Exp $");
84 1.1 dholland
85 1.2 dholland #include <sys/mount.h>
86 1.4 dholland #include <sys/quotactl.h>
87 1.3 dholland #include <quota/quotaprop.h>
88 1.2 dholland
89 1.4 dholland static int
90 1.4 dholland vfs_quotactl_cmd(struct mount *mp, prop_dictionary_t cmddict)
91 1.4 dholland {
92 1.4 dholland int error;
93 1.4 dholland const char *cmd, *type;
94 1.4 dholland int op;
95 1.4 dholland prop_array_t datas;
96 1.4 dholland int q2type;
97 1.4 dholland
98 1.4 dholland if (!prop_dictionary_get_cstring_nocopy(cmddict, "command", &cmd))
99 1.4 dholland return EINVAL;
100 1.4 dholland if (!prop_dictionary_get_cstring_nocopy(cmddict, "type", &type))
101 1.4 dholland return EINVAL;
102 1.4 dholland
103 1.4 dholland if (!strcmp(type, QUOTADICT_CLASS_USER)) {
104 1.4 dholland q2type = QUOTA_CLASS_USER;
105 1.4 dholland } else if (!strcmp(type, QUOTADICT_CLASS_GROUP)) {
106 1.4 dholland q2type = QUOTA_CLASS_GROUP;
107 1.4 dholland } else {
108 1.4 dholland /* XXX this is a bad errno for this case */
109 1.4 dholland return EOPNOTSUPP;
110 1.4 dholland }
111 1.4 dholland
112 1.4 dholland datas = prop_dictionary_get(cmddict, "data");
113 1.4 dholland if (datas == NULL || prop_object_type(datas) != PROP_TYPE_ARRAY)
114 1.4 dholland return EINVAL;
115 1.4 dholland
116 1.4 dholland prop_object_retain(datas);
117 1.4 dholland prop_dictionary_remove(cmddict, "data"); /* prepare for return */
118 1.4 dholland
119 1.4 dholland if (strcmp(cmd, "get version") == 0) {
120 1.4 dholland op = QUOTACTL_GETVERSION;
121 1.4 dholland } else if (strcmp(cmd, "quotaon") == 0) {
122 1.4 dholland op = QUOTACTL_QUOTAON;
123 1.4 dholland } else if (strcmp(cmd, "quotaoff") == 0) {
124 1.4 dholland op = QUOTACTL_QUOTAOFF;
125 1.4 dholland } else if (strcmp(cmd, "get") == 0) {
126 1.4 dholland op = QUOTACTL_GET;
127 1.4 dholland } else if (strcmp(cmd, "set") == 0) {
128 1.4 dholland op = QUOTACTL_SET;
129 1.4 dholland } else if (strcmp(cmd, "getall") == 0) {
130 1.4 dholland op = QUOTACTL_GETALL;
131 1.4 dholland } else if (strcmp(cmd, "clear") == 0) {
132 1.4 dholland op = QUOTACTL_CLEAR;
133 1.4 dholland } else {
134 1.4 dholland /* XXX this a bad errno for this case */
135 1.4 dholland error = EOPNOTSUPP;
136 1.4 dholland goto fail;
137 1.4 dholland }
138 1.4 dholland
139 1.4 dholland error = VFS_QUOTACTL(mp, op, cmddict, q2type, datas);
140 1.4 dholland
141 1.4 dholland fail:
142 1.4 dholland error = (prop_dictionary_set_int8(cmddict, "return",
143 1.4 dholland error) ? 0 : ENOMEM);
144 1.4 dholland prop_object_release(datas);
145 1.4 dholland
146 1.4 dholland return error;
147 1.4 dholland }
148 1.4 dholland
149 1.2 dholland int
150 1.2 dholland vfs_quotactl(struct mount *mp, prop_dictionary_t dict)
151 1.2 dholland {
152 1.3 dholland prop_dictionary_t cmddict;
153 1.3 dholland prop_array_t commands;
154 1.3 dholland prop_object_iterator_t iter;
155 1.3 dholland int error;
156 1.3 dholland
157 1.3 dholland error = quota_get_cmds(dict, &commands);
158 1.3 dholland if (error) {
159 1.3 dholland return error;
160 1.3 dholland }
161 1.3 dholland
162 1.3 dholland iter = prop_array_iterator(commands);
163 1.3 dholland if (iter == NULL) {
164 1.3 dholland return ENOMEM;
165 1.3 dholland }
166 1.3 dholland
167 1.3 dholland while ((cmddict = prop_object_iterator_next(iter)) != NULL) {
168 1.3 dholland if (prop_object_type(cmddict) != PROP_TYPE_DICTIONARY) {
169 1.3 dholland /* XXX shouldn't this be an error? */
170 1.3 dholland continue;
171 1.3 dholland }
172 1.4 dholland error = vfs_quotactl_cmd(mp, cmddict);
173 1.3 dholland if (error) {
174 1.3 dholland break;
175 1.3 dholland }
176 1.3 dholland }
177 1.3 dholland prop_object_iterator_release(iter);
178 1.3 dholland return error;
179 1.2 dholland }
180