diff options
Diffstat (limited to 'fs/reiserfs/xattr_acl.c')
-rw-r--r-- | fs/reiserfs/xattr_acl.c | 641 |
1 files changed, 317 insertions, 324 deletions
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c index c312881c5f53..6703efa3c430 100644 --- a/fs/reiserfs/xattr_acl.c +++ b/fs/reiserfs/xattr_acl.c | |||
@@ -9,7 +9,8 @@ | |||
9 | #include <linux/reiserfs_acl.h> | 9 | #include <linux/reiserfs_acl.h> |
10 | #include <asm/uaccess.h> | 10 | #include <asm/uaccess.h> |
11 | 11 | ||
12 | static int reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl); | 12 | static int reiserfs_set_acl(struct inode *inode, int type, |
13 | struct posix_acl *acl); | ||
13 | 14 | ||
14 | static int | 15 | static int |
15 | xattr_set_acl(struct inode *inode, int type, const void *value, size_t size) | 16 | xattr_set_acl(struct inode *inode, int type, const void *value, size_t size) |
@@ -34,14 +35,13 @@ xattr_set_acl(struct inode *inode, int type, const void *value, size_t size) | |||
34 | } else | 35 | } else |
35 | acl = NULL; | 36 | acl = NULL; |
36 | 37 | ||
37 | error = reiserfs_set_acl (inode, type, acl); | 38 | error = reiserfs_set_acl(inode, type, acl); |
38 | 39 | ||
39 | release_and_out: | 40 | release_and_out: |
40 | posix_acl_release(acl); | 41 | posix_acl_release(acl); |
41 | return error; | 42 | return error; |
42 | } | 43 | } |
43 | 44 | ||
44 | |||
45 | static int | 45 | static int |
46 | xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) | 46 | xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) |
47 | { | 47 | { |
@@ -51,7 +51,7 @@ xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) | |||
51 | if (!reiserfs_posixacl(inode->i_sb)) | 51 | if (!reiserfs_posixacl(inode->i_sb)) |
52 | return -EOPNOTSUPP; | 52 | return -EOPNOTSUPP; |
53 | 53 | ||
54 | acl = reiserfs_get_acl (inode, type); | 54 | acl = reiserfs_get_acl(inode, type); |
55 | if (IS_ERR(acl)) | 55 | if (IS_ERR(acl)) |
56 | return PTR_ERR(acl); | 56 | return PTR_ERR(acl); |
57 | if (acl == NULL) | 57 | if (acl == NULL) |
@@ -62,12 +62,10 @@ xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) | |||
62 | return error; | 62 | return error; |
63 | } | 63 | } |
64 | 64 | ||
65 | |||
66 | /* | 65 | /* |
67 | * Convert from filesystem to in-memory representation. | 66 | * Convert from filesystem to in-memory representation. |
68 | */ | 67 | */ |
69 | static struct posix_acl * | 68 | static struct posix_acl *posix_acl_from_disk(const void *value, size_t size) |
70 | posix_acl_from_disk(const void *value, size_t size) | ||
71 | { | 69 | { |
72 | const char *end = (char *)value + size; | 70 | const char *end = (char *)value + size; |
73 | int n, count; | 71 | int n, count; |
@@ -76,8 +74,8 @@ posix_acl_from_disk(const void *value, size_t size) | |||
76 | if (!value) | 74 | if (!value) |
77 | return NULL; | 75 | return NULL; |
78 | if (size < sizeof(reiserfs_acl_header)) | 76 | if (size < sizeof(reiserfs_acl_header)) |
79 | return ERR_PTR(-EINVAL); | 77 | return ERR_PTR(-EINVAL); |
80 | if (((reiserfs_acl_header *)value)->a_version != | 78 | if (((reiserfs_acl_header *) value)->a_version != |
81 | cpu_to_le32(REISERFS_ACL_VERSION)) | 79 | cpu_to_le32(REISERFS_ACL_VERSION)) |
82 | return ERR_PTR(-EINVAL); | 80 | return ERR_PTR(-EINVAL); |
83 | value = (char *)value + sizeof(reiserfs_acl_header); | 81 | value = (char *)value + sizeof(reiserfs_acl_header); |
@@ -89,41 +87,39 @@ posix_acl_from_disk(const void *value, size_t size) | |||
89 | acl = posix_acl_alloc(count, GFP_NOFS); | 87 | acl = posix_acl_alloc(count, GFP_NOFS); |
90 | if (!acl) | 88 | if (!acl) |
91 | return ERR_PTR(-ENOMEM); | 89 | return ERR_PTR(-ENOMEM); |
92 | for (n=0; n < count; n++) { | 90 | for (n = 0; n < count; n++) { |
93 | reiserfs_acl_entry *entry = | 91 | reiserfs_acl_entry *entry = (reiserfs_acl_entry *) value; |
94 | (reiserfs_acl_entry *)value; | ||
95 | if ((char *)value + sizeof(reiserfs_acl_entry_short) > end) | 92 | if ((char *)value + sizeof(reiserfs_acl_entry_short) > end) |
96 | goto fail; | 93 | goto fail; |
97 | acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag); | 94 | acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag); |
98 | acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm); | 95 | acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm); |
99 | switch(acl->a_entries[n].e_tag) { | 96 | switch (acl->a_entries[n].e_tag) { |
100 | case ACL_USER_OBJ: | 97 | case ACL_USER_OBJ: |
101 | case ACL_GROUP_OBJ: | 98 | case ACL_GROUP_OBJ: |
102 | case ACL_MASK: | 99 | case ACL_MASK: |
103 | case ACL_OTHER: | 100 | case ACL_OTHER: |
104 | value = (char *)value + | 101 | value = (char *)value + |
105 | sizeof(reiserfs_acl_entry_short); | 102 | sizeof(reiserfs_acl_entry_short); |
106 | acl->a_entries[n].e_id = ACL_UNDEFINED_ID; | 103 | acl->a_entries[n].e_id = ACL_UNDEFINED_ID; |
107 | break; | 104 | break; |
108 | 105 | ||
109 | case ACL_USER: | 106 | case ACL_USER: |
110 | case ACL_GROUP: | 107 | case ACL_GROUP: |
111 | value = (char *)value + sizeof(reiserfs_acl_entry); | 108 | value = (char *)value + sizeof(reiserfs_acl_entry); |
112 | if ((char *)value > end) | 109 | if ((char *)value > end) |
113 | goto fail; | ||
114 | acl->a_entries[n].e_id = | ||
115 | le32_to_cpu(entry->e_id); | ||
116 | break; | ||
117 | |||
118 | default: | ||
119 | goto fail; | 110 | goto fail; |
111 | acl->a_entries[n].e_id = le32_to_cpu(entry->e_id); | ||
112 | break; | ||
113 | |||
114 | default: | ||
115 | goto fail; | ||
120 | } | 116 | } |
121 | } | 117 | } |
122 | if (value != end) | 118 | if (value != end) |
123 | goto fail; | 119 | goto fail; |
124 | return acl; | 120 | return acl; |
125 | 121 | ||
126 | fail: | 122 | fail: |
127 | posix_acl_release(acl); | 123 | posix_acl_release(acl); |
128 | return ERR_PTR(-EINVAL); | 124 | return ERR_PTR(-EINVAL); |
129 | } | 125 | } |
@@ -131,46 +127,46 @@ fail: | |||
131 | /* | 127 | /* |
132 | * Convert from in-memory to filesystem representation. | 128 | * Convert from in-memory to filesystem representation. |
133 | */ | 129 | */ |
134 | static void * | 130 | static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size) |
135 | posix_acl_to_disk(const struct posix_acl *acl, size_t *size) | ||
136 | { | 131 | { |
137 | reiserfs_acl_header *ext_acl; | 132 | reiserfs_acl_header *ext_acl; |
138 | char *e; | 133 | char *e; |
139 | int n; | 134 | int n; |
140 | 135 | ||
141 | *size = reiserfs_acl_size(acl->a_count); | 136 | *size = reiserfs_acl_size(acl->a_count); |
142 | ext_acl = (reiserfs_acl_header *)kmalloc(sizeof(reiserfs_acl_header) + | 137 | ext_acl = (reiserfs_acl_header *) kmalloc(sizeof(reiserfs_acl_header) + |
143 | acl->a_count * sizeof(reiserfs_acl_entry), GFP_NOFS); | 138 | acl->a_count * |
139 | sizeof(reiserfs_acl_entry), | ||
140 | GFP_NOFS); | ||
144 | if (!ext_acl) | 141 | if (!ext_acl) |
145 | return ERR_PTR(-ENOMEM); | 142 | return ERR_PTR(-ENOMEM); |
146 | ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION); | 143 | ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION); |
147 | e = (char *)ext_acl + sizeof(reiserfs_acl_header); | 144 | e = (char *)ext_acl + sizeof(reiserfs_acl_header); |
148 | for (n=0; n < acl->a_count; n++) { | 145 | for (n = 0; n < acl->a_count; n++) { |
149 | reiserfs_acl_entry *entry = (reiserfs_acl_entry *)e; | 146 | reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e; |
150 | entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); | 147 | entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); |
151 | entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); | 148 | entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); |
152 | switch(acl->a_entries[n].e_tag) { | 149 | switch (acl->a_entries[n].e_tag) { |
153 | case ACL_USER: | 150 | case ACL_USER: |
154 | case ACL_GROUP: | 151 | case ACL_GROUP: |
155 | entry->e_id = | 152 | entry->e_id = cpu_to_le32(acl->a_entries[n].e_id); |
156 | cpu_to_le32(acl->a_entries[n].e_id); | 153 | e += sizeof(reiserfs_acl_entry); |
157 | e += sizeof(reiserfs_acl_entry); | 154 | break; |
158 | break; | 155 | |
159 | 156 | case ACL_USER_OBJ: | |
160 | case ACL_USER_OBJ: | 157 | case ACL_GROUP_OBJ: |
161 | case ACL_GROUP_OBJ: | 158 | case ACL_MASK: |
162 | case ACL_MASK: | 159 | case ACL_OTHER: |
163 | case ACL_OTHER: | 160 | e += sizeof(reiserfs_acl_entry_short); |
164 | e += sizeof(reiserfs_acl_entry_short); | 161 | break; |
165 | break; | 162 | |
166 | 163 | default: | |
167 | default: | 164 | goto fail; |
168 | goto fail; | ||
169 | } | 165 | } |
170 | } | 166 | } |
171 | return (char *)ext_acl; | 167 | return (char *)ext_acl; |
172 | 168 | ||
173 | fail: | 169 | fail: |
174 | kfree(ext_acl); | 170 | kfree(ext_acl); |
175 | return ERR_PTR(-EINVAL); | 171 | return ERR_PTR(-EINVAL); |
176 | } | 172 | } |
@@ -181,59 +177,58 @@ fail: | |||
181 | * inode->i_sem: down | 177 | * inode->i_sem: down |
182 | * BKL held [before 2.5.x] | 178 | * BKL held [before 2.5.x] |
183 | */ | 179 | */ |
184 | struct posix_acl * | 180 | struct posix_acl *reiserfs_get_acl(struct inode *inode, int type) |
185 | reiserfs_get_acl(struct inode *inode, int type) | ||
186 | { | 181 | { |
187 | char *name, *value; | 182 | char *name, *value; |
188 | struct posix_acl *acl, **p_acl; | 183 | struct posix_acl *acl, **p_acl; |
189 | size_t size; | 184 | size_t size; |
190 | int retval; | 185 | int retval; |
191 | struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); | 186 | struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); |
192 | 187 | ||
193 | switch (type) { | 188 | switch (type) { |
194 | case ACL_TYPE_ACCESS: | 189 | case ACL_TYPE_ACCESS: |
195 | name = POSIX_ACL_XATTR_ACCESS; | 190 | name = POSIX_ACL_XATTR_ACCESS; |
196 | p_acl = &reiserfs_i->i_acl_access; | 191 | p_acl = &reiserfs_i->i_acl_access; |
197 | break; | 192 | break; |
198 | case ACL_TYPE_DEFAULT: | 193 | case ACL_TYPE_DEFAULT: |
199 | name = POSIX_ACL_XATTR_DEFAULT; | 194 | name = POSIX_ACL_XATTR_DEFAULT; |
200 | p_acl = &reiserfs_i->i_acl_default; | 195 | p_acl = &reiserfs_i->i_acl_default; |
201 | break; | 196 | break; |
202 | default: | 197 | default: |
203 | return ERR_PTR (-EINVAL); | 198 | return ERR_PTR(-EINVAL); |
204 | } | 199 | } |
205 | 200 | ||
206 | if (IS_ERR (*p_acl)) { | 201 | if (IS_ERR(*p_acl)) { |
207 | if (PTR_ERR (*p_acl) == -ENODATA) | 202 | if (PTR_ERR(*p_acl) == -ENODATA) |
208 | return NULL; | 203 | return NULL; |
209 | } else if (*p_acl != NULL) | 204 | } else if (*p_acl != NULL) |
210 | return posix_acl_dup (*p_acl); | 205 | return posix_acl_dup(*p_acl); |
211 | 206 | ||
212 | size = reiserfs_xattr_get (inode, name, NULL, 0); | 207 | size = reiserfs_xattr_get(inode, name, NULL, 0); |
213 | if ((int)size < 0) { | 208 | if ((int)size < 0) { |
214 | if (size == -ENODATA || size == -ENOSYS) { | 209 | if (size == -ENODATA || size == -ENOSYS) { |
215 | *p_acl = ERR_PTR (-ENODATA); | 210 | *p_acl = ERR_PTR(-ENODATA); |
216 | return NULL; | 211 | return NULL; |
217 | } | 212 | } |
218 | return ERR_PTR (size); | 213 | return ERR_PTR(size); |
219 | } | 214 | } |
220 | 215 | ||
221 | value = kmalloc (size, GFP_NOFS); | 216 | value = kmalloc(size, GFP_NOFS); |
222 | if (!value) | 217 | if (!value) |
223 | return ERR_PTR (-ENOMEM); | 218 | return ERR_PTR(-ENOMEM); |
224 | 219 | ||
225 | retval = reiserfs_xattr_get(inode, name, value, size); | 220 | retval = reiserfs_xattr_get(inode, name, value, size); |
226 | if (retval == -ENODATA || retval == -ENOSYS) { | 221 | if (retval == -ENODATA || retval == -ENOSYS) { |
227 | /* This shouldn't actually happen as it should have | 222 | /* This shouldn't actually happen as it should have |
228 | been caught above.. but just in case */ | 223 | been caught above.. but just in case */ |
229 | acl = NULL; | 224 | acl = NULL; |
230 | *p_acl = ERR_PTR (-ENODATA); | 225 | *p_acl = ERR_PTR(-ENODATA); |
231 | } else if (retval < 0) { | 226 | } else if (retval < 0) { |
232 | acl = ERR_PTR(retval); | 227 | acl = ERR_PTR(retval); |
233 | } else { | 228 | } else { |
234 | acl = posix_acl_from_disk(value, retval); | 229 | acl = posix_acl_from_disk(value, retval); |
235 | *p_acl = posix_acl_dup (acl); | 230 | *p_acl = posix_acl_dup(acl); |
236 | } | 231 | } |
237 | 232 | ||
238 | kfree(value); | 233 | kfree(value); |
239 | return acl; | 234 | return acl; |
@@ -248,72 +243,72 @@ reiserfs_get_acl(struct inode *inode, int type) | |||
248 | static int | 243 | static int |
249 | reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl) | 244 | reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl) |
250 | { | 245 | { |
251 | char *name; | 246 | char *name; |
252 | void *value = NULL; | 247 | void *value = NULL; |
253 | struct posix_acl **p_acl; | 248 | struct posix_acl **p_acl; |
254 | size_t size; | 249 | size_t size; |
255 | int error; | 250 | int error; |
256 | struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); | 251 | struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); |
257 | 252 | ||
258 | if (S_ISLNK(inode->i_mode)) | 253 | if (S_ISLNK(inode->i_mode)) |
259 | return -EOPNOTSUPP; | 254 | return -EOPNOTSUPP; |
260 | 255 | ||
261 | switch (type) { | 256 | switch (type) { |
262 | case ACL_TYPE_ACCESS: | 257 | case ACL_TYPE_ACCESS: |
263 | name = POSIX_ACL_XATTR_ACCESS; | 258 | name = POSIX_ACL_XATTR_ACCESS; |
264 | p_acl = &reiserfs_i->i_acl_access; | 259 | p_acl = &reiserfs_i->i_acl_access; |
265 | if (acl) { | 260 | if (acl) { |
266 | mode_t mode = inode->i_mode; | 261 | mode_t mode = inode->i_mode; |
267 | error = posix_acl_equiv_mode (acl, &mode); | 262 | error = posix_acl_equiv_mode(acl, &mode); |
268 | if (error < 0) | 263 | if (error < 0) |
269 | return error; | 264 | return error; |
270 | else { | 265 | else { |
271 | inode->i_mode = mode; | 266 | inode->i_mode = mode; |
272 | if (error == 0) | 267 | if (error == 0) |
273 | acl = NULL; | 268 | acl = NULL; |
274 | } | 269 | } |
275 | } | 270 | } |
276 | break; | 271 | break; |
277 | case ACL_TYPE_DEFAULT: | 272 | case ACL_TYPE_DEFAULT: |
278 | name = POSIX_ACL_XATTR_DEFAULT; | 273 | name = POSIX_ACL_XATTR_DEFAULT; |
279 | p_acl = &reiserfs_i->i_acl_default; | 274 | p_acl = &reiserfs_i->i_acl_default; |
280 | if (!S_ISDIR (inode->i_mode)) | 275 | if (!S_ISDIR(inode->i_mode)) |
281 | return acl ? -EACCES : 0; | 276 | return acl ? -EACCES : 0; |
282 | break; | 277 | break; |
283 | default: | 278 | default: |
284 | return -EINVAL; | 279 | return -EINVAL; |
285 | } | 280 | } |
286 | 281 | ||
287 | if (acl) { | 282 | if (acl) { |
288 | value = posix_acl_to_disk(acl, &size); | 283 | value = posix_acl_to_disk(acl, &size); |
289 | if (IS_ERR(value)) | 284 | if (IS_ERR(value)) |
290 | return (int)PTR_ERR(value); | 285 | return (int)PTR_ERR(value); |
291 | error = reiserfs_xattr_set(inode, name, value, size, 0); | 286 | error = reiserfs_xattr_set(inode, name, value, size, 0); |
292 | } else { | 287 | } else { |
293 | error = reiserfs_xattr_del (inode, name); | 288 | error = reiserfs_xattr_del(inode, name); |
294 | if (error == -ENODATA) { | 289 | if (error == -ENODATA) { |
295 | /* This may seem odd here, but it means that the ACL was set | 290 | /* This may seem odd here, but it means that the ACL was set |
296 | * with a value representable with mode bits. If there was | 291 | * with a value representable with mode bits. If there was |
297 | * an ACL before, reiserfs_xattr_del already dirtied the inode. | 292 | * an ACL before, reiserfs_xattr_del already dirtied the inode. |
298 | */ | 293 | */ |
299 | mark_inode_dirty (inode); | 294 | mark_inode_dirty(inode); |
300 | error = 0; | 295 | error = 0; |
301 | } | 296 | } |
302 | } | 297 | } |
303 | 298 | ||
304 | if (value) | 299 | if (value) |
305 | kfree(value); | 300 | kfree(value); |
306 | 301 | ||
307 | if (!error) { | 302 | if (!error) { |
308 | /* Release the old one */ | 303 | /* Release the old one */ |
309 | if (!IS_ERR (*p_acl) && *p_acl) | 304 | if (!IS_ERR(*p_acl) && *p_acl) |
310 | posix_acl_release (*p_acl); | 305 | posix_acl_release(*p_acl); |
311 | 306 | ||
312 | if (acl == NULL) | 307 | if (acl == NULL) |
313 | *p_acl = ERR_PTR (-ENODATA); | 308 | *p_acl = ERR_PTR(-ENODATA); |
314 | else | 309 | else |
315 | *p_acl = posix_acl_dup (acl); | 310 | *p_acl = posix_acl_dup(acl); |
316 | } | 311 | } |
317 | 312 | ||
318 | return error; | 313 | return error; |
319 | } | 314 | } |
@@ -321,192 +316,190 @@ reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl) | |||
321 | /* dir->i_sem: down, | 316 | /* dir->i_sem: down, |
322 | * inode is new and not released into the wild yet */ | 317 | * inode is new and not released into the wild yet */ |
323 | int | 318 | int |
324 | reiserfs_inherit_default_acl (struct inode *dir, struct dentry *dentry, struct inode *inode) | 319 | reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry, |
320 | struct inode *inode) | ||
325 | { | 321 | { |
326 | struct posix_acl *acl; | 322 | struct posix_acl *acl; |
327 | int err = 0; | 323 | int err = 0; |
328 | 324 | ||
329 | /* ACLs only get applied to files and directories */ | 325 | /* ACLs only get applied to files and directories */ |
330 | if (S_ISLNK (inode->i_mode)) | 326 | if (S_ISLNK(inode->i_mode)) |
331 | return 0; | 327 | return 0; |
332 | 328 | ||
333 | /* ACLs can only be used on "new" objects, so if it's an old object | 329 | /* ACLs can only be used on "new" objects, so if it's an old object |
334 | * there is nothing to inherit from */ | 330 | * there is nothing to inherit from */ |
335 | if (get_inode_sd_version (dir) == STAT_DATA_V1) | 331 | if (get_inode_sd_version(dir) == STAT_DATA_V1) |
336 | goto apply_umask; | 332 | goto apply_umask; |
337 | 333 | ||
338 | /* Don't apply ACLs to objects in the .reiserfs_priv tree.. This | 334 | /* Don't apply ACLs to objects in the .reiserfs_priv tree.. This |
339 | * would be useless since permissions are ignored, and a pain because | 335 | * would be useless since permissions are ignored, and a pain because |
340 | * it introduces locking cycles */ | 336 | * it introduces locking cycles */ |
341 | if (is_reiserfs_priv_object (dir)) { | 337 | if (is_reiserfs_priv_object(dir)) { |
342 | reiserfs_mark_inode_private (inode); | 338 | reiserfs_mark_inode_private(inode); |
343 | goto apply_umask; | 339 | goto apply_umask; |
344 | } | 340 | } |
345 | 341 | ||
346 | acl = reiserfs_get_acl (dir, ACL_TYPE_DEFAULT); | 342 | acl = reiserfs_get_acl(dir, ACL_TYPE_DEFAULT); |
347 | if (IS_ERR (acl)) { | 343 | if (IS_ERR(acl)) { |
348 | if (PTR_ERR (acl) == -ENODATA) | 344 | if (PTR_ERR(acl) == -ENODATA) |
349 | goto apply_umask; | 345 | goto apply_umask; |
350 | return PTR_ERR (acl); | 346 | return PTR_ERR(acl); |
351 | } | 347 | } |
352 | 348 | ||
353 | if (acl) { | 349 | if (acl) { |
354 | struct posix_acl *acl_copy; | 350 | struct posix_acl *acl_copy; |
355 | mode_t mode = inode->i_mode; | 351 | mode_t mode = inode->i_mode; |
356 | int need_acl; | 352 | int need_acl; |
357 | 353 | ||
358 | /* Copy the default ACL to the default ACL of a new directory */ | 354 | /* Copy the default ACL to the default ACL of a new directory */ |
359 | if (S_ISDIR (inode->i_mode)) { | 355 | if (S_ISDIR(inode->i_mode)) { |
360 | err = reiserfs_set_acl (inode, ACL_TYPE_DEFAULT, acl); | 356 | err = reiserfs_set_acl(inode, ACL_TYPE_DEFAULT, acl); |
361 | if (err) | 357 | if (err) |
362 | goto cleanup; | 358 | goto cleanup; |
363 | } | 359 | } |
364 | 360 | ||
365 | /* Now we reconcile the new ACL and the mode, | 361 | /* Now we reconcile the new ACL and the mode, |
366 | potentially modifying both */ | 362 | potentially modifying both */ |
367 | acl_copy = posix_acl_clone (acl, GFP_NOFS); | 363 | acl_copy = posix_acl_clone(acl, GFP_NOFS); |
368 | if (!acl_copy) { | 364 | if (!acl_copy) { |
369 | err = -ENOMEM; | 365 | err = -ENOMEM; |
370 | goto cleanup; | 366 | goto cleanup; |
371 | } | 367 | } |
372 | 368 | ||
373 | 369 | need_acl = posix_acl_create_masq(acl_copy, &mode); | |
374 | need_acl = posix_acl_create_masq (acl_copy, &mode); | 370 | if (need_acl >= 0) { |
375 | if (need_acl >= 0) { | 371 | if (mode != inode->i_mode) { |
376 | if (mode != inode->i_mode) { | 372 | inode->i_mode = mode; |
377 | inode->i_mode = mode; | 373 | } |
378 | } | 374 | |
379 | 375 | /* If we need an ACL.. */ | |
380 | /* If we need an ACL.. */ | 376 | if (need_acl > 0) { |
381 | if (need_acl > 0) { | 377 | err = |
382 | err = reiserfs_set_acl (inode, ACL_TYPE_ACCESS, acl_copy); | 378 | reiserfs_set_acl(inode, ACL_TYPE_ACCESS, |
383 | if (err) | 379 | acl_copy); |
384 | goto cleanup_copy; | 380 | if (err) |
385 | } | 381 | goto cleanup_copy; |
386 | } | 382 | } |
387 | cleanup_copy: | 383 | } |
388 | posix_acl_release (acl_copy); | 384 | cleanup_copy: |
389 | cleanup: | 385 | posix_acl_release(acl_copy); |
390 | posix_acl_release (acl); | 386 | cleanup: |
391 | } else { | 387 | posix_acl_release(acl); |
392 | apply_umask: | 388 | } else { |
393 | /* no ACL, apply umask */ | 389 | apply_umask: |
394 | inode->i_mode &= ~current->fs->umask; | 390 | /* no ACL, apply umask */ |
395 | } | 391 | inode->i_mode &= ~current->fs->umask; |
396 | 392 | } | |
397 | return err; | 393 | |
394 | return err; | ||
398 | } | 395 | } |
399 | 396 | ||
400 | /* Looks up and caches the result of the default ACL. | 397 | /* Looks up and caches the result of the default ACL. |
401 | * We do this so that we don't need to carry the xattr_sem into | 398 | * We do this so that we don't need to carry the xattr_sem into |
402 | * reiserfs_new_inode if we don't need to */ | 399 | * reiserfs_new_inode if we don't need to */ |
403 | int | 400 | int reiserfs_cache_default_acl(struct inode *inode) |
404 | reiserfs_cache_default_acl (struct inode *inode) | ||
405 | { | 401 | { |
406 | int ret = 0; | 402 | int ret = 0; |
407 | if (reiserfs_posixacl (inode->i_sb) && | 403 | if (reiserfs_posixacl(inode->i_sb) && !is_reiserfs_priv_object(inode)) { |
408 | !is_reiserfs_priv_object (inode)) { | 404 | struct posix_acl *acl; |
409 | struct posix_acl *acl; | 405 | reiserfs_read_lock_xattr_i(inode); |
410 | reiserfs_read_lock_xattr_i (inode); | 406 | reiserfs_read_lock_xattrs(inode->i_sb); |
411 | reiserfs_read_lock_xattrs (inode->i_sb); | 407 | acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT); |
412 | acl = reiserfs_get_acl (inode, ACL_TYPE_DEFAULT); | 408 | reiserfs_read_unlock_xattrs(inode->i_sb); |
413 | reiserfs_read_unlock_xattrs (inode->i_sb); | 409 | reiserfs_read_unlock_xattr_i(inode); |
414 | reiserfs_read_unlock_xattr_i (inode); | 410 | ret = acl ? 1 : 0; |
415 | ret = acl ? 1 : 0; | 411 | posix_acl_release(acl); |
416 | posix_acl_release (acl); | 412 | } |
417 | } | 413 | |
418 | 414 | return ret; | |
419 | return ret; | ||
420 | } | 415 | } |
421 | 416 | ||
422 | int | 417 | int reiserfs_acl_chmod(struct inode *inode) |
423 | reiserfs_acl_chmod (struct inode *inode) | ||
424 | { | 418 | { |
425 | struct posix_acl *acl, *clone; | 419 | struct posix_acl *acl, *clone; |
426 | int error; | 420 | int error; |
427 | 421 | ||
428 | if (S_ISLNK(inode->i_mode)) | 422 | if (S_ISLNK(inode->i_mode)) |
429 | return -EOPNOTSUPP; | 423 | return -EOPNOTSUPP; |
430 | 424 | ||
431 | if (get_inode_sd_version (inode) == STAT_DATA_V1 || | 425 | if (get_inode_sd_version(inode) == STAT_DATA_V1 || |
432 | !reiserfs_posixacl(inode->i_sb)) | 426 | !reiserfs_posixacl(inode->i_sb)) { |
433 | { | 427 | return 0; |
434 | return 0; | ||
435 | } | 428 | } |
436 | 429 | ||
437 | reiserfs_read_lock_xattrs (inode->i_sb); | 430 | reiserfs_read_lock_xattrs(inode->i_sb); |
438 | acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); | 431 | acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); |
439 | reiserfs_read_unlock_xattrs (inode->i_sb); | 432 | reiserfs_read_unlock_xattrs(inode->i_sb); |
440 | if (!acl) | 433 | if (!acl) |
441 | return 0; | 434 | return 0; |
442 | if (IS_ERR(acl)) | 435 | if (IS_ERR(acl)) |
443 | return PTR_ERR(acl); | 436 | return PTR_ERR(acl); |
444 | clone = posix_acl_clone(acl, GFP_NOFS); | 437 | clone = posix_acl_clone(acl, GFP_NOFS); |
445 | posix_acl_release(acl); | 438 | posix_acl_release(acl); |
446 | if (!clone) | 439 | if (!clone) |
447 | return -ENOMEM; | 440 | return -ENOMEM; |
448 | error = posix_acl_chmod_masq(clone, inode->i_mode); | 441 | error = posix_acl_chmod_masq(clone, inode->i_mode); |
449 | if (!error) { | 442 | if (!error) { |
450 | int lock = !has_xattr_dir (inode); | 443 | int lock = !has_xattr_dir(inode); |
451 | reiserfs_write_lock_xattr_i (inode); | 444 | reiserfs_write_lock_xattr_i(inode); |
452 | if (lock) | 445 | if (lock) |
453 | reiserfs_write_lock_xattrs (inode->i_sb); | 446 | reiserfs_write_lock_xattrs(inode->i_sb); |
454 | else | 447 | else |
455 | reiserfs_read_lock_xattrs (inode->i_sb); | 448 | reiserfs_read_lock_xattrs(inode->i_sb); |
456 | error = reiserfs_set_acl(inode, ACL_TYPE_ACCESS, clone); | 449 | error = reiserfs_set_acl(inode, ACL_TYPE_ACCESS, clone); |
457 | if (lock) | 450 | if (lock) |
458 | reiserfs_write_unlock_xattrs (inode->i_sb); | 451 | reiserfs_write_unlock_xattrs(inode->i_sb); |
459 | else | 452 | else |
460 | reiserfs_read_unlock_xattrs (inode->i_sb); | 453 | reiserfs_read_unlock_xattrs(inode->i_sb); |
461 | reiserfs_write_unlock_xattr_i (inode); | 454 | reiserfs_write_unlock_xattr_i(inode); |
462 | } | 455 | } |
463 | posix_acl_release(clone); | 456 | posix_acl_release(clone); |
464 | return error; | 457 | return error; |
465 | } | 458 | } |
466 | 459 | ||
467 | static int | 460 | static int |
468 | posix_acl_access_get(struct inode *inode, const char *name, | 461 | posix_acl_access_get(struct inode *inode, const char *name, |
469 | void *buffer, size_t size) | 462 | void *buffer, size_t size) |
470 | { | 463 | { |
471 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS)-1) | 464 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1) |
472 | return -EINVAL; | 465 | return -EINVAL; |
473 | return xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); | 466 | return xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); |
474 | } | 467 | } |
475 | 468 | ||
476 | static int | 469 | static int |
477 | posix_acl_access_set(struct inode *inode, const char *name, | 470 | posix_acl_access_set(struct inode *inode, const char *name, |
478 | const void *value, size_t size, int flags) | 471 | const void *value, size_t size, int flags) |
479 | { | 472 | { |
480 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS)-1) | 473 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1) |
481 | return -EINVAL; | 474 | return -EINVAL; |
482 | return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); | 475 | return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); |
483 | } | 476 | } |
484 | 477 | ||
485 | static int | 478 | static int posix_acl_access_del(struct inode *inode, const char *name) |
486 | posix_acl_access_del (struct inode *inode, const char *name) | ||
487 | { | 479 | { |
488 | struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); | 480 | struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); |
489 | struct posix_acl **acl = &reiserfs_i->i_acl_access; | 481 | struct posix_acl **acl = &reiserfs_i->i_acl_access; |
490 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS)-1) | 482 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1) |
491 | return -EINVAL; | 483 | return -EINVAL; |
492 | if (!IS_ERR (*acl) && *acl) { | 484 | if (!IS_ERR(*acl) && *acl) { |
493 | posix_acl_release (*acl); | 485 | posix_acl_release(*acl); |
494 | *acl = ERR_PTR (-ENODATA); | 486 | *acl = ERR_PTR(-ENODATA); |
495 | } | 487 | } |
496 | 488 | ||
497 | return 0; | 489 | return 0; |
498 | } | 490 | } |
499 | 491 | ||
500 | static int | 492 | static int |
501 | posix_acl_access_list (struct inode *inode, const char *name, int namelen, char *out) | 493 | posix_acl_access_list(struct inode *inode, const char *name, int namelen, |
494 | char *out) | ||
502 | { | 495 | { |
503 | int len = namelen; | 496 | int len = namelen; |
504 | if (!reiserfs_posixacl (inode->i_sb)) | 497 | if (!reiserfs_posixacl(inode->i_sb)) |
505 | return 0; | 498 | return 0; |
506 | if (out) | 499 | if (out) |
507 | memcpy (out, name, len); | 500 | memcpy(out, name, len); |
508 | 501 | ||
509 | return len; | 502 | return len; |
510 | } | 503 | } |
511 | 504 | ||
512 | struct reiserfs_xattr_handler posix_acl_access_handler = { | 505 | struct reiserfs_xattr_handler posix_acl_access_handler = { |
@@ -518,48 +511,48 @@ struct reiserfs_xattr_handler posix_acl_access_handler = { | |||
518 | }; | 511 | }; |
519 | 512 | ||
520 | static int | 513 | static int |
521 | posix_acl_default_get (struct inode *inode, const char *name, | 514 | posix_acl_default_get(struct inode *inode, const char *name, |
522 | void *buffer, size_t size) | 515 | void *buffer, size_t size) |
523 | { | 516 | { |
524 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT)-1) | 517 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1) |
525 | return -EINVAL; | 518 | return -EINVAL; |
526 | return xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); | 519 | return xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); |
527 | } | 520 | } |
528 | 521 | ||
529 | static int | 522 | static int |
530 | posix_acl_default_set(struct inode *inode, const char *name, | 523 | posix_acl_default_set(struct inode *inode, const char *name, |
531 | const void *value, size_t size, int flags) | 524 | const void *value, size_t size, int flags) |
532 | { | 525 | { |
533 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT)-1) | 526 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1) |
534 | return -EINVAL; | 527 | return -EINVAL; |
535 | return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); | 528 | return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); |
536 | } | 529 | } |
537 | 530 | ||
538 | static int | 531 | static int posix_acl_default_del(struct inode *inode, const char *name) |
539 | posix_acl_default_del (struct inode *inode, const char *name) | ||
540 | { | 532 | { |
541 | struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); | 533 | struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); |
542 | struct posix_acl **acl = &reiserfs_i->i_acl_default; | 534 | struct posix_acl **acl = &reiserfs_i->i_acl_default; |
543 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT)-1) | 535 | if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1) |
544 | return -EINVAL; | 536 | return -EINVAL; |
545 | if (!IS_ERR (*acl) && *acl) { | 537 | if (!IS_ERR(*acl) && *acl) { |
546 | posix_acl_release (*acl); | 538 | posix_acl_release(*acl); |
547 | *acl = ERR_PTR (-ENODATA); | 539 | *acl = ERR_PTR(-ENODATA); |
548 | } | 540 | } |
549 | 541 | ||
550 | return 0; | 542 | return 0; |
551 | } | 543 | } |
552 | 544 | ||
553 | static int | 545 | static int |
554 | posix_acl_default_list (struct inode *inode, const char *name, int namelen, char *out) | 546 | posix_acl_default_list(struct inode *inode, const char *name, int namelen, |
547 | char *out) | ||
555 | { | 548 | { |
556 | int len = namelen; | 549 | int len = namelen; |
557 | if (!reiserfs_posixacl (inode->i_sb)) | 550 | if (!reiserfs_posixacl(inode->i_sb)) |
558 | return 0; | 551 | return 0; |
559 | if (out) | 552 | if (out) |
560 | memcpy (out, name, len); | 553 | memcpy(out, name, len); |
561 | 554 | ||
562 | return len; | 555 | return len; |
563 | } | 556 | } |
564 | 557 | ||
565 | struct reiserfs_xattr_handler posix_acl_default_handler = { | 558 | struct reiserfs_xattr_handler posix_acl_default_handler = { |