2 * linux/fs/hfsplus/posix_acl.c
6 * Handler for Posix Access Control Lists (ACLs) support.
9 #include "hfsplus_fs.h"
13 struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type)
15 struct posix_acl *acl;
20 acl = get_cached_acl(inode, type);
21 if (acl != ACL_NOT_CACHED)
26 xattr_name = POSIX_ACL_XATTR_ACCESS;
28 case ACL_TYPE_DEFAULT:
29 xattr_name = POSIX_ACL_XATTR_DEFAULT;
32 return ERR_PTR(-EINVAL);
35 size = __hfsplus_getxattr(inode, xattr_name, NULL, 0);
38 value = (char *)hfsplus_alloc_attr_entry();
40 return ERR_PTR(-ENOMEM);
41 size = __hfsplus_getxattr(inode, xattr_name, value, size);
45 acl = posix_acl_from_xattr(&init_user_ns, value, size);
46 else if (size == -ENODATA)
51 hfsplus_destroy_attr_entry((hfsplus_attr_entry *)value);
54 set_cached_acl(inode, type, acl);
59 static int hfsplus_set_posix_acl(struct inode *inode,
61 struct posix_acl *acl)
68 if (S_ISLNK(inode->i_mode))
73 xattr_name = POSIX_ACL_XATTR_ACCESS;
75 err = posix_acl_equiv_mode(acl, &inode->i_mode);
82 case ACL_TYPE_DEFAULT:
83 xattr_name = POSIX_ACL_XATTR_DEFAULT;
84 if (!S_ISDIR(inode->i_mode))
85 return acl ? -EACCES : 0;
93 size = posix_acl_xattr_size(acl->a_count);
94 if (unlikely(size > HFSPLUS_MAX_INLINE_DATA_SIZE))
96 value = (char *)hfsplus_alloc_attr_entry();
99 err = posix_acl_to_xattr(&init_user_ns, acl, value, size);
100 if (unlikely(err < 0))
104 err = __hfsplus_setxattr(inode, xattr_name, value, size, 0);
107 hfsplus_destroy_attr_entry((hfsplus_attr_entry *)value);
110 set_cached_acl(inode, type, acl);
115 int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
118 struct posix_acl *acl = NULL;
121 "[%s]: ino %lu, dir->ino %lu\n",
122 __func__, inode->i_ino, dir->i_ino);
124 if (S_ISLNK(inode->i_mode))
127 acl = hfsplus_get_posix_acl(dir, ACL_TYPE_DEFAULT);
132 if (S_ISDIR(inode->i_mode)) {
133 err = hfsplus_set_posix_acl(inode,
137 goto init_acl_cleanup;
140 err = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
141 if (unlikely(err < 0))
145 err = hfsplus_set_posix_acl(inode,
149 inode->i_mode &= ~current_umask();
152 posix_acl_release(acl);
156 int hfsplus_posix_acl_chmod(struct inode *inode)
159 struct posix_acl *acl;
161 hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
163 if (S_ISLNK(inode->i_mode))
166 acl = hfsplus_get_posix_acl(inode, ACL_TYPE_ACCESS);
167 if (IS_ERR(acl) || !acl)
170 err = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
174 err = hfsplus_set_posix_acl(inode, ACL_TYPE_ACCESS, acl);
175 posix_acl_release(acl);
179 static int hfsplus_xattr_get_posix_acl(struct dentry *dentry,
186 struct posix_acl *acl;
189 "[%s]: ino %lu, buffer %p, size %zu, type %#x\n",
190 __func__, dentry->d_inode->i_ino, buffer, size, type);
192 if (strcmp(name, "") != 0)
195 acl = hfsplus_get_posix_acl(dentry->d_inode, type);
201 err = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
202 posix_acl_release(acl);
207 static int hfsplus_xattr_set_posix_acl(struct dentry *dentry,
215 struct inode *inode = dentry->d_inode;
216 struct posix_acl *acl = NULL;
219 "[%s]: ino %lu, value %p, size %zu, flags %#x, type %#x\n",
220 __func__, inode->i_ino, value, size, flags, type);
222 if (strcmp(name, "") != 0)
225 if (!inode_owner_or_capable(inode))
229 acl = posix_acl_from_xattr(&init_user_ns, value, size);
233 err = posix_acl_valid(acl);
235 goto end_xattr_set_acl;
239 err = hfsplus_set_posix_acl(inode, type, acl);
242 posix_acl_release(acl);
246 static size_t hfsplus_xattr_list_posix_acl(struct dentry *dentry,
254 * This method is not used.
255 * It is used hfsplus_listxattr() instead of generic_listxattr().
260 const struct xattr_handler hfsplus_xattr_acl_access_handler = {
261 .prefix = POSIX_ACL_XATTR_ACCESS,
262 .flags = ACL_TYPE_ACCESS,
263 .list = hfsplus_xattr_list_posix_acl,
264 .get = hfsplus_xattr_get_posix_acl,
265 .set = hfsplus_xattr_set_posix_acl,
268 const struct xattr_handler hfsplus_xattr_acl_default_handler = {
269 .prefix = POSIX_ACL_XATTR_DEFAULT,
270 .flags = ACL_TYPE_DEFAULT,
271 .list = hfsplus_xattr_list_posix_acl,
272 .get = hfsplus_xattr_get_posix_acl,
273 .set = hfsplus_xattr_set_posix_acl,