]>
Commit | Line | Data |
---|---|---|
39f0247d AG |
1 | /* |
2 | * mm/shmem_acl.c | |
3 | * | |
4 | * (C) 2005 Andreas Gruenbacher <agruen@suse.de> | |
5 | * | |
6 | * This file is released under the GPL. | |
7 | */ | |
8 | ||
9 | #include <linux/fs.h> | |
10 | #include <linux/shmem_fs.h> | |
11 | #include <linux/xattr.h> | |
12 | #include <linux/generic_acl.h> | |
13 | ||
14 | /** | |
15 | * shmem_get_acl - generic_acl_operations->getacl() operation | |
16 | */ | |
17 | static struct posix_acl * | |
18 | shmem_get_acl(struct inode *inode, int type) | |
19 | { | |
20 | struct posix_acl *acl = NULL; | |
21 | ||
22 | spin_lock(&inode->i_lock); | |
23 | switch(type) { | |
24 | case ACL_TYPE_ACCESS: | |
06b16e9f | 25 | acl = posix_acl_dup(inode->i_acl); |
39f0247d AG |
26 | break; |
27 | ||
28 | case ACL_TYPE_DEFAULT: | |
06b16e9f | 29 | acl = posix_acl_dup(inode->i_default_acl); |
39f0247d AG |
30 | break; |
31 | } | |
32 | spin_unlock(&inode->i_lock); | |
33 | ||
34 | return acl; | |
35 | } | |
36 | ||
37 | /** | |
53bc5b2d | 38 | * shmem_set_acl - generic_acl_operations->setacl() operation |
39f0247d AG |
39 | */ |
40 | static void | |
41 | shmem_set_acl(struct inode *inode, int type, struct posix_acl *acl) | |
42 | { | |
43 | struct posix_acl *free = NULL; | |
44 | ||
45 | spin_lock(&inode->i_lock); | |
46 | switch(type) { | |
47 | case ACL_TYPE_ACCESS: | |
06b16e9f AV |
48 | free = inode->i_acl; |
49 | inode->i_acl = posix_acl_dup(acl); | |
39f0247d AG |
50 | break; |
51 | ||
52 | case ACL_TYPE_DEFAULT: | |
06b16e9f AV |
53 | free = inode->i_default_acl; |
54 | inode->i_default_acl = posix_acl_dup(acl); | |
39f0247d AG |
55 | break; |
56 | } | |
57 | spin_unlock(&inode->i_lock); | |
58 | posix_acl_release(free); | |
59 | } | |
60 | ||
61 | struct generic_acl_operations shmem_acl_ops = { | |
62 | .getacl = shmem_get_acl, | |
63 | .setacl = shmem_set_acl, | |
64 | }; | |
65 | ||
39f0247d | 66 | static size_t |
431547b3 CH |
67 | shmem_xattr_list_acl(struct dentry *dentry, char *list, size_t list_size, |
68 | const char *name, size_t name_len, int type) | |
39f0247d | 69 | { |
431547b3 CH |
70 | return generic_acl_list(dentry->d_inode, &shmem_acl_ops, |
71 | type, list, list_size); | |
39f0247d AG |
72 | } |
73 | ||
74 | static int | |
431547b3 CH |
75 | shmem_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer, |
76 | size_t size, int type) | |
39f0247d AG |
77 | { |
78 | if (strcmp(name, "") != 0) | |
79 | return -EINVAL; | |
431547b3 CH |
80 | return generic_acl_get(dentry->d_inode, &shmem_acl_ops, type, |
81 | buffer, size); | |
39f0247d AG |
82 | } |
83 | ||
84 | static int | |
431547b3 CH |
85 | shmem_xattr_set_acl(struct dentry *dentry, const char *name, const void *value, |
86 | size_t size, int flags, int type) | |
39f0247d AG |
87 | { |
88 | if (strcmp(name, "") != 0) | |
89 | return -EINVAL; | |
431547b3 CH |
90 | return generic_acl_set(dentry->d_inode, &shmem_acl_ops, type, |
91 | value, size); | |
39f0247d AG |
92 | } |
93 | ||
94 | struct xattr_handler shmem_xattr_acl_access_handler = { | |
95 | .prefix = POSIX_ACL_XATTR_ACCESS, | |
431547b3 CH |
96 | .flags = ACL_TYPE_ACCESS, |
97 | .list = shmem_xattr_list_acl, | |
98 | .get = shmem_xattr_get_acl, | |
99 | .set = shmem_xattr_set_acl, | |
39f0247d AG |
100 | }; |
101 | ||
39f0247d AG |
102 | struct xattr_handler shmem_xattr_acl_default_handler = { |
103 | .prefix = POSIX_ACL_XATTR_DEFAULT, | |
431547b3 CH |
104 | .flags = ACL_TYPE_DEFAULT, |
105 | .list = shmem_xattr_list_acl, | |
106 | .get = shmem_xattr_get_acl, | |
107 | .set = shmem_xattr_set_acl, | |
39f0247d AG |
108 | }; |
109 | ||
110 | /** | |
111 | * shmem_acl_init - Inizialize the acl(s) of a new inode | |
112 | */ | |
113 | int | |
114 | shmem_acl_init(struct inode *inode, struct inode *dir) | |
115 | { | |
116 | return generic_acl_init(inode, dir, &shmem_acl_ops); | |
117 | } | |
118 | ||
39f0247d AG |
119 | /** |
120 | * shmem_check_acl - check_acl() callback for generic_permission() | |
121 | */ | |
6d848a48 | 122 | int |
39f0247d AG |
123 | shmem_check_acl(struct inode *inode, int mask) |
124 | { | |
125 | struct posix_acl *acl = shmem_get_acl(inode, ACL_TYPE_ACCESS); | |
126 | ||
127 | if (acl) { | |
128 | int error = posix_acl_permission(inode, acl, mask); | |
129 | posix_acl_release(acl); | |
130 | return error; | |
131 | } | |
132 | return -EAGAIN; | |
133 | } |