blob: 6703efa3c4308fb6f0e46aa8bcf23c7fd0416d24 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/fs.h>
2#include <linux/posix_acl.h>
3#include <linux/reiserfs_fs.h>
4#include <linux/errno.h>
5#include <linux/pagemap.h>
6#include <linux/xattr.h>
Christoph Hellwig9a59f452005-06-23 00:10:19 -07007#include <linux/posix_acl_xattr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/reiserfs_xattr.h>
9#include <linux/reiserfs_acl.h>
10#include <asm/uaccess.h>
11
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070012static int reiserfs_set_acl(struct inode *inode, int type,
13 struct posix_acl *acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15static int
16xattr_set_acl(struct inode *inode, int type, const void *value, size_t size)
17{
18 struct posix_acl *acl;
19 int error;
20
21 if (!reiserfs_posixacl(inode->i_sb))
22 return -EOPNOTSUPP;
23 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
24 return -EPERM;
25
26 if (value) {
27 acl = posix_acl_from_xattr(value, size);
28 if (IS_ERR(acl)) {
29 return PTR_ERR(acl);
30 } else if (acl) {
31 error = posix_acl_valid(acl);
32 if (error)
33 goto release_and_out;
34 }
35 } else
36 acl = NULL;
37
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070038 error = reiserfs_set_acl(inode, type, acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070040 release_and_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 posix_acl_release(acl);
42 return error;
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static int
46xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
47{
48 struct posix_acl *acl;
49 int error;
50
51 if (!reiserfs_posixacl(inode->i_sb))
52 return -EOPNOTSUPP;
53
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070054 acl = reiserfs_get_acl(inode, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 if (IS_ERR(acl))
56 return PTR_ERR(acl);
57 if (acl == NULL)
58 return -ENODATA;
59 error = posix_acl_to_xattr(acl, buffer, size);
60 posix_acl_release(acl);
61
62 return error;
63}
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/*
66 * Convert from filesystem to in-memory representation.
67 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070068static struct posix_acl *posix_acl_from_disk(const void *value, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 const char *end = (char *)value + size;
71 int n, count;
72 struct posix_acl *acl;
73
74 if (!value)
75 return NULL;
76 if (size < sizeof(reiserfs_acl_header))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070077 return ERR_PTR(-EINVAL);
78 if (((reiserfs_acl_header *) value)->a_version !=
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 cpu_to_le32(REISERFS_ACL_VERSION))
80 return ERR_PTR(-EINVAL);
81 value = (char *)value + sizeof(reiserfs_acl_header);
82 count = reiserfs_acl_count(size);
83 if (count < 0)
84 return ERR_PTR(-EINVAL);
85 if (count == 0)
86 return NULL;
87 acl = posix_acl_alloc(count, GFP_NOFS);
88 if (!acl)
89 return ERR_PTR(-ENOMEM);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070090 for (n = 0; n < count; n++) {
91 reiserfs_acl_entry *entry = (reiserfs_acl_entry *) value;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 if ((char *)value + sizeof(reiserfs_acl_entry_short) > end)
93 goto fail;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070094 acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070096 switch (acl->a_entries[n].e_tag) {
97 case ACL_USER_OBJ:
98 case ACL_GROUP_OBJ:
99 case ACL_MASK:
100 case ACL_OTHER:
101 value = (char *)value +
102 sizeof(reiserfs_acl_entry_short);
103 acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
104 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700106 case ACL_USER:
107 case ACL_GROUP:
108 value = (char *)value + sizeof(reiserfs_acl_entry);
109 if ((char *)value > end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 goto fail;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700111 acl->a_entries[n].e_id = le32_to_cpu(entry->e_id);
112 break;
113
114 default:
115 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117 }
118 if (value != end)
119 goto fail;
120 return acl;
121
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700122 fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 posix_acl_release(acl);
124 return ERR_PTR(-EINVAL);
125}
126
127/*
128 * Convert from in-memory to filesystem representation.
129 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700130static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
132 reiserfs_acl_header *ext_acl;
133 char *e;
134 int n;
135
136 *size = reiserfs_acl_size(acl->a_count);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700137 ext_acl = (reiserfs_acl_header *) kmalloc(sizeof(reiserfs_acl_header) +
138 acl->a_count *
139 sizeof(reiserfs_acl_entry),
140 GFP_NOFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 if (!ext_acl)
142 return ERR_PTR(-ENOMEM);
143 ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION);
144 e = (char *)ext_acl + sizeof(reiserfs_acl_header);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700145 for (n = 0; n < acl->a_count; n++) {
146 reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e;
147 entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700149 switch (acl->a_entries[n].e_tag) {
150 case ACL_USER:
151 case ACL_GROUP:
152 entry->e_id = cpu_to_le32(acl->a_entries[n].e_id);
153 e += sizeof(reiserfs_acl_entry);
154 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700156 case ACL_USER_OBJ:
157 case ACL_GROUP_OBJ:
158 case ACL_MASK:
159 case ACL_OTHER:
160 e += sizeof(reiserfs_acl_entry_short);
161 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700163 default:
164 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166 }
167 return (char *)ext_acl;
168
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700169 fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 kfree(ext_acl);
171 return ERR_PTR(-EINVAL);
172}
173
174/*
175 * Inode operation get_posix_acl().
176 *
177 * inode->i_sem: down
178 * BKL held [before 2.5.x]
179 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700180struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 char *name, *value;
183 struct posix_acl *acl, **p_acl;
184 size_t size;
185 int retval;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700186 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700188 switch (type) {
189 case ACL_TYPE_ACCESS:
190 name = POSIX_ACL_XATTR_ACCESS;
191 p_acl = &reiserfs_i->i_acl_access;
192 break;
193 case ACL_TYPE_DEFAULT:
194 name = POSIX_ACL_XATTR_DEFAULT;
195 p_acl = &reiserfs_i->i_acl_default;
196 break;
197 default:
198 return ERR_PTR(-EINVAL);
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700201 if (IS_ERR(*p_acl)) {
202 if (PTR_ERR(*p_acl) == -ENODATA)
203 return NULL;
204 } else if (*p_acl != NULL)
205 return posix_acl_dup(*p_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700207 size = reiserfs_xattr_get(inode, name, NULL, 0);
208 if ((int)size < 0) {
209 if (size == -ENODATA || size == -ENOSYS) {
210 *p_acl = ERR_PTR(-ENODATA);
211 return NULL;
212 }
213 return ERR_PTR(size);
214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700216 value = kmalloc(size, GFP_NOFS);
217 if (!value)
218 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 retval = reiserfs_xattr_get(inode, name, value, size);
221 if (retval == -ENODATA || retval == -ENOSYS) {
222 /* This shouldn't actually happen as it should have
223 been caught above.. but just in case */
224 acl = NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700225 *p_acl = ERR_PTR(-ENODATA);
226 } else if (retval < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 acl = ERR_PTR(retval);
228 } else {
229 acl = posix_acl_from_disk(value, retval);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700230 *p_acl = posix_acl_dup(acl);
231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 kfree(value);
234 return acl;
235}
236
237/*
238 * Inode operation set_posix_acl().
239 *
240 * inode->i_sem: down
241 * BKL held [before 2.5.x]
242 */
243static int
244reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
245{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700246 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 void *value = NULL;
248 struct posix_acl **p_acl;
249 size_t size;
250 int error;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700251 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 if (S_ISLNK(inode->i_mode))
254 return -EOPNOTSUPP;
255
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700256 switch (type) {
257 case ACL_TYPE_ACCESS:
258 name = POSIX_ACL_XATTR_ACCESS;
259 p_acl = &reiserfs_i->i_acl_access;
260 if (acl) {
261 mode_t mode = inode->i_mode;
262 error = posix_acl_equiv_mode(acl, &mode);
263 if (error < 0)
264 return error;
265 else {
266 inode->i_mode = mode;
267 if (error == 0)
268 acl = NULL;
269 }
270 }
271 break;
272 case ACL_TYPE_DEFAULT:
273 name = POSIX_ACL_XATTR_DEFAULT;
274 p_acl = &reiserfs_i->i_acl_default;
275 if (!S_ISDIR(inode->i_mode))
276 return acl ? -EACCES : 0;
277 break;
278 default:
279 return -EINVAL;
280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700282 if (acl) {
283 value = posix_acl_to_disk(acl, &size);
284 if (IS_ERR(value))
285 return (int)PTR_ERR(value);
286 error = reiserfs_xattr_set(inode, name, value, size, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 } else {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700288 error = reiserfs_xattr_del(inode, name);
289 if (error == -ENODATA) {
290 /* This may seem odd here, but it means that the ACL was set
291 * with a value representable with mode bits. If there was
292 * an ACL before, reiserfs_xattr_del already dirtied the inode.
293 */
294 mark_inode_dirty(inode);
295 error = 0;
296 }
297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 if (value)
300 kfree(value);
301
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700302 if (!error) {
303 /* Release the old one */
304 if (!IS_ERR(*p_acl) && *p_acl)
305 posix_acl_release(*p_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700307 if (acl == NULL)
308 *p_acl = ERR_PTR(-ENODATA);
309 else
310 *p_acl = posix_acl_dup(acl);
311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 return error;
314}
315
316/* dir->i_sem: down,
317 * inode is new and not released into the wild yet */
318int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700319reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
320 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700322 struct posix_acl *acl;
323 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700325 /* ACLs only get applied to files and directories */
326 if (S_ISLNK(inode->i_mode))
327 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700329 /* ACLs can only be used on "new" objects, so if it's an old object
330 * there is nothing to inherit from */
331 if (get_inode_sd_version(dir) == STAT_DATA_V1)
332 goto apply_umask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700334 /* Don't apply ACLs to objects in the .reiserfs_priv tree.. This
335 * would be useless since permissions are ignored, and a pain because
336 * it introduces locking cycles */
337 if (is_reiserfs_priv_object(dir)) {
338 reiserfs_mark_inode_private(inode);
339 goto apply_umask;
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700342 acl = reiserfs_get_acl(dir, ACL_TYPE_DEFAULT);
343 if (IS_ERR(acl)) {
344 if (PTR_ERR(acl) == -ENODATA)
345 goto apply_umask;
346 return PTR_ERR(acl);
347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700349 if (acl) {
350 struct posix_acl *acl_copy;
351 mode_t mode = inode->i_mode;
352 int need_acl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700354 /* Copy the default ACL to the default ACL of a new directory */
355 if (S_ISDIR(inode->i_mode)) {
356 err = reiserfs_set_acl(inode, ACL_TYPE_DEFAULT, acl);
357 if (err)
358 goto cleanup;
359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700361 /* Now we reconcile the new ACL and the mode,
362 potentially modifying both */
363 acl_copy = posix_acl_clone(acl, GFP_NOFS);
364 if (!acl_copy) {
365 err = -ENOMEM;
366 goto cleanup;
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700369 need_acl = posix_acl_create_masq(acl_copy, &mode);
370 if (need_acl >= 0) {
371 if (mode != inode->i_mode) {
372 inode->i_mode = mode;
373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700375 /* If we need an ACL.. */
376 if (need_acl > 0) {
377 err =
378 reiserfs_set_acl(inode, ACL_TYPE_ACCESS,
379 acl_copy);
380 if (err)
381 goto cleanup_copy;
382 }
383 }
384 cleanup_copy:
385 posix_acl_release(acl_copy);
386 cleanup:
387 posix_acl_release(acl);
388 } else {
389 apply_umask:
390 /* no ACL, apply umask */
391 inode->i_mode &= ~current->fs->umask;
392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700394 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
396
397/* Looks up and caches the result of the default ACL.
398 * We do this so that we don't need to carry the xattr_sem into
399 * reiserfs_new_inode if we don't need to */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700400int reiserfs_cache_default_acl(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700402 int ret = 0;
403 if (reiserfs_posixacl(inode->i_sb) && !is_reiserfs_priv_object(inode)) {
404 struct posix_acl *acl;
405 reiserfs_read_lock_xattr_i(inode);
406 reiserfs_read_lock_xattrs(inode->i_sb);
407 acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
408 reiserfs_read_unlock_xattrs(inode->i_sb);
409 reiserfs_read_unlock_xattr_i(inode);
410 ret = acl ? 1 : 0;
411 posix_acl_release(acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
413
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700414 return ret;
415}
416
417int reiserfs_acl_chmod(struct inode *inode)
418{
419 struct posix_acl *acl, *clone;
420 int error;
421
422 if (S_ISLNK(inode->i_mode))
423 return -EOPNOTSUPP;
424
425 if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
426 !reiserfs_posixacl(inode->i_sb)) {
427 return 0;
428 }
429
430 reiserfs_read_lock_xattrs(inode->i_sb);
431 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
432 reiserfs_read_unlock_xattrs(inode->i_sb);
433 if (!acl)
434 return 0;
435 if (IS_ERR(acl))
436 return PTR_ERR(acl);
437 clone = posix_acl_clone(acl, GFP_NOFS);
438 posix_acl_release(acl);
439 if (!clone)
440 return -ENOMEM;
441 error = posix_acl_chmod_masq(clone, inode->i_mode);
442 if (!error) {
443 int lock = !has_xattr_dir(inode);
444 reiserfs_write_lock_xattr_i(inode);
445 if (lock)
446 reiserfs_write_lock_xattrs(inode->i_sb);
447 else
448 reiserfs_read_lock_xattrs(inode->i_sb);
449 error = reiserfs_set_acl(inode, ACL_TYPE_ACCESS, clone);
450 if (lock)
451 reiserfs_write_unlock_xattrs(inode->i_sb);
452 else
453 reiserfs_read_unlock_xattrs(inode->i_sb);
454 reiserfs_write_unlock_xattr_i(inode);
455 }
456 posix_acl_release(clone);
457 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
460static int
461posix_acl_access_get(struct inode *inode, const char *name,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700462 void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700464 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 return -EINVAL;
466 return xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size);
467}
468
469static int
470posix_acl_access_set(struct inode *inode, const char *name,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700471 const void *value, size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700473 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return -EINVAL;
475 return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
476}
477
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700478static int posix_acl_access_del(struct inode *inode, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700480 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
481 struct posix_acl **acl = &reiserfs_i->i_acl_access;
482 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
483 return -EINVAL;
484 if (!IS_ERR(*acl) && *acl) {
485 posix_acl_release(*acl);
486 *acl = ERR_PTR(-ENODATA);
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700489 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
492static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700493posix_acl_access_list(struct inode *inode, const char *name, int namelen,
494 char *out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700496 int len = namelen;
497 if (!reiserfs_posixacl(inode->i_sb))
498 return 0;
499 if (out)
500 memcpy(out, name, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700502 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
505struct reiserfs_xattr_handler posix_acl_access_handler = {
Christoph Hellwig9a59f452005-06-23 00:10:19 -0700506 .prefix = POSIX_ACL_XATTR_ACCESS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .get = posix_acl_access_get,
508 .set = posix_acl_access_set,
509 .del = posix_acl_access_del,
510 .list = posix_acl_access_list,
511};
512
513static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700514posix_acl_default_get(struct inode *inode, const char *name,
515 void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700517 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return -EINVAL;
519 return xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size);
520}
521
522static int
523posix_acl_default_set(struct inode *inode, const char *name,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700524 const void *value, size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700526 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return -EINVAL;
528 return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
529}
530
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700531static int posix_acl_default_del(struct inode *inode, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700533 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
534 struct posix_acl **acl = &reiserfs_i->i_acl_default;
535 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
536 return -EINVAL;
537 if (!IS_ERR(*acl) && *acl) {
538 posix_acl_release(*acl);
539 *acl = ERR_PTR(-ENODATA);
540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700542 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
545static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700546posix_acl_default_list(struct inode *inode, const char *name, int namelen,
547 char *out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700549 int len = namelen;
550 if (!reiserfs_posixacl(inode->i_sb))
551 return 0;
552 if (out)
553 memcpy(out, name, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700555 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558struct reiserfs_xattr_handler posix_acl_default_handler = {
Christoph Hellwig9a59f452005-06-23 00:10:19 -0700559 .prefix = POSIX_ACL_XATTR_DEFAULT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 .get = posix_acl_default_get,
561 .set = posix_acl_default_set,
562 .del = posix_acl_default_del,
563 .list = posix_acl_default_list,
564};