Blame view
fs/hfsplus/posix_acl.c
2.77 KB
eef80d4ad hfsplus: implemen... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* * linux/fs/hfsplus/posix_acl.c * * Vyacheslav Dubeyko <slava@dubeyko.com> * * Handler for Posix Access Control Lists (ACLs) support. */ #include "hfsplus_fs.h" #include "xattr.h" #include "acl.h" struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type) { struct posix_acl *acl; char *xattr_name; char *value = NULL; ssize_t size; |
b0a7ab570 hfsplus: use gene... |
19 20 |
hfs_dbg(ACL_MOD, "[%s]: ino %lu ", __func__, inode->i_ino); |
eef80d4ad hfsplus: implemen... |
21 22 23 |
switch (type) { case ACL_TYPE_ACCESS: |
97d792992 posix acls: Remov... |
24 |
xattr_name = XATTR_NAME_POSIX_ACL_ACCESS; |
eef80d4ad hfsplus: implemen... |
25 26 |
break; case ACL_TYPE_DEFAULT: |
97d792992 posix acls: Remov... |
27 |
xattr_name = XATTR_NAME_POSIX_ACL_DEFAULT; |
eef80d4ad hfsplus: implemen... |
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
break; default: return ERR_PTR(-EINVAL); } size = __hfsplus_getxattr(inode, xattr_name, NULL, 0); if (size > 0) { value = (char *)hfsplus_alloc_attr_entry(); if (unlikely(!value)) return ERR_PTR(-ENOMEM); size = __hfsplus_getxattr(inode, xattr_name, value, size); } if (size > 0) acl = posix_acl_from_xattr(&init_user_ns, value, size); else if (size == -ENODATA) acl = NULL; else acl = ERR_PTR(size); hfsplus_destroy_attr_entry((hfsplus_attr_entry *)value); |
eef80d4ad hfsplus: implemen... |
50 51 |
return acl; } |
b0a7ab570 hfsplus: use gene... |
52 53 |
int hfsplus_set_posix_acl(struct inode *inode, struct posix_acl *acl, int type) |
eef80d4ad hfsplus: implemen... |
54 55 56 57 58 |
{ int err; char *xattr_name; size_t size = 0; char *value = NULL; |
b0a7ab570 hfsplus: use gene... |
59 60 |
hfs_dbg(ACL_MOD, "[%s]: ino %lu ", __func__, inode->i_ino); |
eef80d4ad hfsplus: implemen... |
61 62 63 |
switch (type) { case ACL_TYPE_ACCESS: |
97d792992 posix acls: Remov... |
64 |
xattr_name = XATTR_NAME_POSIX_ACL_ACCESS; |
eef80d4ad hfsplus: implemen... |
65 |
if (acl) { |
073931017 posix_acl: Clear ... |
66 67 |
err = posix_acl_update_mode(inode, &inode->i_mode, &acl); if (err) |
eef80d4ad hfsplus: implemen... |
68 69 70 71 72 73 |
return err; } err = 0; break; case ACL_TYPE_DEFAULT: |
97d792992 posix acls: Remov... |
74 |
xattr_name = XATTR_NAME_POSIX_ACL_DEFAULT; |
eef80d4ad hfsplus: implemen... |
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
if (!S_ISDIR(inode->i_mode)) return acl ? -EACCES : 0; break; default: return -EINVAL; } if (acl) { size = posix_acl_xattr_size(acl->a_count); if (unlikely(size > HFSPLUS_MAX_INLINE_DATA_SIZE)) return -ENOMEM; value = (char *)hfsplus_alloc_attr_entry(); if (unlikely(!value)) return -ENOMEM; err = posix_acl_to_xattr(&init_user_ns, acl, value, size); if (unlikely(err < 0)) goto end_set_acl; } err = __hfsplus_setxattr(inode, xattr_name, value, size, 0); end_set_acl: hfsplus_destroy_attr_entry((hfsplus_attr_entry *)value); if (!err) set_cached_acl(inode, type, acl); return err; } int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir) { int err = 0; |
b0a7ab570 hfsplus: use gene... |
109 |
struct posix_acl *default_acl, *acl; |
eef80d4ad hfsplus: implemen... |
110 111 112 113 114 115 116 117 |
hfs_dbg(ACL_MOD, "[%s]: ino %lu, dir->ino %lu ", __func__, inode->i_ino, dir->i_ino); if (S_ISLNK(inode->i_mode)) return 0; |
b0a7ab570 hfsplus: use gene... |
118 119 |
err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl); if (err) |
eef80d4ad hfsplus: implemen... |
120 |
return err; |
b0a7ab570 hfsplus: use gene... |
121 122 123 124 |
if (default_acl) { err = hfsplus_set_posix_acl(inode, default_acl, ACL_TYPE_DEFAULT); posix_acl_release(default_acl); |
eef80d4ad hfsplus: implemen... |
125 |
} |
b0a7ab570 hfsplus: use gene... |
126 127 128 129 130 131 |
if (acl) { if (!err) err = hfsplus_set_posix_acl(inode, acl, ACL_TYPE_ACCESS); posix_acl_release(acl); } |
eef80d4ad hfsplus: implemen... |
132 133 |
return err; } |