2 * linux/fs/hfsplus/posix_acl.c
4 * Vyacheslav Dubeyko <slava@dubeyko.com>
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 hfs_dbg(ACL_MOD
, "[%s]: ino %lu\n", __func__
, inode
->i_ino
);
24 xattr_name
= XATTR_NAME_POSIX_ACL_ACCESS
;
26 case ACL_TYPE_DEFAULT
:
27 xattr_name
= XATTR_NAME_POSIX_ACL_DEFAULT
;
30 return ERR_PTR(-EINVAL
);
33 size
= __hfsplus_getxattr(inode
, xattr_name
, NULL
, 0);
36 value
= (char *)hfsplus_alloc_attr_entry();
38 return ERR_PTR(-ENOMEM
);
39 size
= __hfsplus_getxattr(inode
, xattr_name
, value
, size
);
43 acl
= posix_acl_from_xattr(&init_user_ns
, value
, size
);
44 else if (size
== -ENODATA
)
49 hfsplus_destroy_attr_entry((hfsplus_attr_entry
*)value
);
54 int hfsplus_set_posix_acl(struct inode
*inode
, struct posix_acl
*acl
,
62 hfs_dbg(ACL_MOD
, "[%s]: ino %lu\n", __func__
, inode
->i_ino
);
66 xattr_name
= XATTR_NAME_POSIX_ACL_ACCESS
;
68 err
= posix_acl_update_mode(inode
, &inode
->i_mode
, &acl
);
75 case ACL_TYPE_DEFAULT
:
76 xattr_name
= XATTR_NAME_POSIX_ACL_DEFAULT
;
77 if (!S_ISDIR(inode
->i_mode
))
78 return acl
? -EACCES
: 0;
86 size
= posix_acl_xattr_size(acl
->a_count
);
87 if (unlikely(size
> HFSPLUS_MAX_INLINE_DATA_SIZE
))
89 value
= (char *)hfsplus_alloc_attr_entry();
92 err
= posix_acl_to_xattr(&init_user_ns
, acl
, value
, size
);
93 if (unlikely(err
< 0))
97 err
= __hfsplus_setxattr(inode
, xattr_name
, value
, size
, 0);
100 hfsplus_destroy_attr_entry((hfsplus_attr_entry
*)value
);
103 set_cached_acl(inode
, type
, acl
);
108 int hfsplus_init_posix_acl(struct inode
*inode
, struct inode
*dir
)
111 struct posix_acl
*default_acl
, *acl
;
114 "[%s]: ino %lu, dir->ino %lu\n",
115 __func__
, inode
->i_ino
, dir
->i_ino
);
117 if (S_ISLNK(inode
->i_mode
))
120 err
= posix_acl_create(dir
, &inode
->i_mode
, &default_acl
, &acl
);
125 err
= hfsplus_set_posix_acl(inode
, default_acl
,
127 posix_acl_release(default_acl
);
132 err
= hfsplus_set_posix_acl(inode
, acl
,
134 posix_acl_release(acl
);