4 * This file is released under the GPL.
6 * Generic ACL support for in-memory filesystems.
9 #include <linux/sched.h>
11 #include <linux/generic_acl.h>
12 #include <linux/posix_acl.h>
13 #include <linux/posix_acl_xattr.h>
17 generic_acl_list(struct dentry *dentry, char *list, size_t list_size,
18 const char *name, size_t name_len, int type)
20 struct posix_acl *acl;
24 acl = get_cached_acl(dentry->d_inode, type);
27 posix_acl_release(acl);
31 xname = POSIX_ACL_XATTR_ACCESS;
33 case ACL_TYPE_DEFAULT:
34 xname = POSIX_ACL_XATTR_DEFAULT;
39 size = strlen(xname) + 1;
40 if (list && size <= list_size)
41 memcpy(list, xname, size);
46 generic_acl_get(struct dentry *dentry, const char *name, void *buffer,
47 size_t size, int type)
49 struct posix_acl *acl;
52 if (strcmp(name, "") != 0)
55 acl = get_cached_acl(dentry->d_inode, type);
58 error = posix_acl_to_xattr(acl, buffer, size);
59 posix_acl_release(acl);
65 generic_acl_set(struct dentry *dentry, const char *name, const void *value,
66 size_t size, int flags, int type)
68 struct inode *inode = dentry->d_inode;
69 struct posix_acl *acl = NULL;
72 if (strcmp(name, "") != 0)
74 if (S_ISLNK(inode->i_mode))
76 if (!is_owner_or_cap(inode))
79 acl = posix_acl_from_xattr(value, size);
86 error = posix_acl_valid(acl);
92 error = posix_acl_equiv_mode(acl, &mode);
97 posix_acl_release(acl);
101 case ACL_TYPE_DEFAULT:
102 if (!S_ISDIR(inode->i_mode)) {
109 set_cached_acl(inode, type, acl);
112 posix_acl_release(acl);
117 * generic_acl_init - Take care of acl inheritance at @inode create time
119 * Files created inside a directory with a default ACL inherit the
120 * directory's default ACL.
123 generic_acl_init(struct inode *inode, struct inode *dir)
125 struct posix_acl *acl = NULL;
126 mode_t mode = inode->i_mode;
129 inode->i_mode = mode & ~current_umask();
130 if (!S_ISLNK(inode->i_mode))
131 acl = get_cached_acl(dir, ACL_TYPE_DEFAULT);
133 struct posix_acl *clone;
135 if (S_ISDIR(inode->i_mode)) {
136 clone = posix_acl_clone(acl, GFP_KERNEL);
140 set_cached_acl(inode, ACL_TYPE_DEFAULT, clone);
141 posix_acl_release(clone);
143 clone = posix_acl_clone(acl, GFP_KERNEL);
147 error = posix_acl_create_masq(clone, &mode);
149 inode->i_mode = mode;
151 set_cached_acl(inode, ACL_TYPE_ACCESS, clone);
153 posix_acl_release(clone);
158 posix_acl_release(acl);
163 * generic_acl_chmod - change the access acl of @inode upon chmod()
165 * A chmod also changes the permissions of the owner, group/mask, and
169 generic_acl_chmod(struct inode *inode)
171 struct posix_acl *acl, *clone;
174 if (S_ISLNK(inode->i_mode))
176 acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
178 clone = posix_acl_clone(acl, GFP_KERNEL);
179 posix_acl_release(acl);
182 error = posix_acl_chmod_masq(clone, inode->i_mode);
184 set_cached_acl(inode, ACL_TYPE_ACCESS, clone);
185 posix_acl_release(clone);
191 generic_check_acl(struct inode *inode, int mask)
193 struct posix_acl *acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
196 int error = posix_acl_permission(inode, acl, mask);
197 posix_acl_release(acl);
203 struct xattr_handler generic_acl_access_handler = {
204 .prefix = POSIX_ACL_XATTR_ACCESS,
205 .flags = ACL_TYPE_ACCESS,
206 .list = generic_acl_list,
207 .get = generic_acl_get,
208 .set = generic_acl_set,
211 struct xattr_handler generic_acl_default_handler = {
212 .prefix = POSIX_ACL_XATTR_DEFAULT,
213 .flags = ACL_TYPE_DEFAULT,
214 .list = generic_acl_list,
215 .get = generic_acl_get,
216 .set = generic_acl_set,