Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 2 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 3 | * linux/fs/ext4/acl.c |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de> |
| 6 | */ |
| 7 | |
Tahsin Erdogan | b8cb5a5 | 2017-05-24 18:24:07 -0400 | [diff] [blame] | 8 | #include <linux/quotaops.h> |
Christoph Hellwig | 3dcf545 | 2008-04-29 18:13:32 -0400 | [diff] [blame] | 9 | #include "ext4_jbd2.h" |
| 10 | #include "ext4.h" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 11 | #include "xattr.h" |
| 12 | #include "acl.h" |
| 13 | |
| 14 | /* |
| 15 | * Convert from filesystem to in-memory representation. |
| 16 | */ |
| 17 | static struct posix_acl * |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 18 | ext4_acl_from_disk(const void *value, size_t size) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 19 | { |
| 20 | const char *end = (char *)value + size; |
| 21 | int n, count; |
| 22 | struct posix_acl *acl; |
| 23 | |
| 24 | if (!value) |
| 25 | return NULL; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 26 | if (size < sizeof(ext4_acl_header)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 27 | return ERR_PTR(-EINVAL); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 28 | if (((ext4_acl_header *)value)->a_version != |
| 29 | cpu_to_le32(EXT4_ACL_VERSION)) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 30 | return ERR_PTR(-EINVAL); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 31 | value = (char *)value + sizeof(ext4_acl_header); |
| 32 | count = ext4_acl_count(size); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 33 | if (count < 0) |
| 34 | return ERR_PTR(-EINVAL); |
| 35 | if (count == 0) |
| 36 | return NULL; |
Josef Bacik | 216553c | 2008-04-29 22:02:02 -0400 | [diff] [blame] | 37 | acl = posix_acl_alloc(count, GFP_NOFS); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 38 | if (!acl) |
| 39 | return ERR_PTR(-ENOMEM); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 40 | for (n = 0; n < count; n++) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 41 | ext4_acl_entry *entry = |
| 42 | (ext4_acl_entry *)value; |
| 43 | if ((char *)value + sizeof(ext4_acl_entry_short) > end) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 44 | goto fail; |
| 45 | acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag); |
| 46 | acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 47 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 48 | switch (acl->a_entries[n].e_tag) { |
| 49 | case ACL_USER_OBJ: |
| 50 | case ACL_GROUP_OBJ: |
| 51 | case ACL_MASK: |
| 52 | case ACL_OTHER: |
| 53 | value = (char *)value + |
| 54 | sizeof(ext4_acl_entry_short); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 55 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 56 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 57 | case ACL_USER: |
Eric W. Biederman | af84df9 | 2012-09-10 20:44:54 -0700 | [diff] [blame] | 58 | value = (char *)value + sizeof(ext4_acl_entry); |
| 59 | if ((char *)value > end) |
| 60 | goto fail; |
| 61 | acl->a_entries[n].e_uid = |
| 62 | make_kuid(&init_user_ns, |
| 63 | le32_to_cpu(entry->e_id)); |
| 64 | break; |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 65 | case ACL_GROUP: |
| 66 | value = (char *)value + sizeof(ext4_acl_entry); |
| 67 | if ((char *)value > end) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 68 | goto fail; |
Eric W. Biederman | af84df9 | 2012-09-10 20:44:54 -0700 | [diff] [blame] | 69 | acl->a_entries[n].e_gid = |
| 70 | make_kgid(&init_user_ns, |
| 71 | le32_to_cpu(entry->e_id)); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 72 | break; |
| 73 | |
| 74 | default: |
| 75 | goto fail; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | if (value != end) |
| 79 | goto fail; |
| 80 | return acl; |
| 81 | |
| 82 | fail: |
| 83 | posix_acl_release(acl); |
| 84 | return ERR_PTR(-EINVAL); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Convert from in-memory to filesystem representation. |
| 89 | */ |
| 90 | static void * |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 91 | ext4_acl_to_disk(const struct posix_acl *acl, size_t *size) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 92 | { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 93 | ext4_acl_header *ext_acl; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 94 | char *e; |
| 95 | size_t n; |
| 96 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 97 | *size = ext4_acl_size(acl->a_count); |
| 98 | ext_acl = kmalloc(sizeof(ext4_acl_header) + acl->a_count * |
Josef Bacik | 216553c | 2008-04-29 22:02:02 -0400 | [diff] [blame] | 99 | sizeof(ext4_acl_entry), GFP_NOFS); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 100 | if (!ext_acl) |
| 101 | return ERR_PTR(-ENOMEM); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 102 | ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION); |
| 103 | e = (char *)ext_acl + sizeof(ext4_acl_header); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 104 | for (n = 0; n < acl->a_count; n++) { |
Eric W. Biederman | af84df9 | 2012-09-10 20:44:54 -0700 | [diff] [blame] | 105 | const struct posix_acl_entry *acl_e = &acl->a_entries[n]; |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 106 | ext4_acl_entry *entry = (ext4_acl_entry *)e; |
Eric W. Biederman | af84df9 | 2012-09-10 20:44:54 -0700 | [diff] [blame] | 107 | entry->e_tag = cpu_to_le16(acl_e->e_tag); |
| 108 | entry->e_perm = cpu_to_le16(acl_e->e_perm); |
| 109 | switch (acl_e->e_tag) { |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 110 | case ACL_USER: |
Eric W. Biederman | af84df9 | 2012-09-10 20:44:54 -0700 | [diff] [blame] | 111 | entry->e_id = cpu_to_le32( |
| 112 | from_kuid(&init_user_ns, acl_e->e_uid)); |
| 113 | e += sizeof(ext4_acl_entry); |
| 114 | break; |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 115 | case ACL_GROUP: |
Eric W. Biederman | af84df9 | 2012-09-10 20:44:54 -0700 | [diff] [blame] | 116 | entry->e_id = cpu_to_le32( |
| 117 | from_kgid(&init_user_ns, acl_e->e_gid)); |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 118 | e += sizeof(ext4_acl_entry); |
| 119 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 120 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 121 | case ACL_USER_OBJ: |
| 122 | case ACL_GROUP_OBJ: |
| 123 | case ACL_MASK: |
| 124 | case ACL_OTHER: |
| 125 | e += sizeof(ext4_acl_entry_short); |
| 126 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 127 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 128 | default: |
| 129 | goto fail; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | return (char *)ext_acl; |
| 133 | |
| 134 | fail: |
| 135 | kfree(ext_acl); |
| 136 | return ERR_PTR(-EINVAL); |
| 137 | } |
| 138 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 139 | /* |
| 140 | * Inode operation get_posix_acl(). |
| 141 | * |
| 142 | * inode->i_mutex: don't care |
| 143 | */ |
Christoph Hellwig | 4e34e71 | 2011-07-23 17:37:31 +0200 | [diff] [blame] | 144 | struct posix_acl * |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 145 | ext4_get_acl(struct inode *inode, int type) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 146 | { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 147 | int name_index; |
| 148 | char *value = NULL; |
| 149 | struct posix_acl *acl; |
| 150 | int retval; |
| 151 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 152 | switch (type) { |
| 153 | case ACL_TYPE_ACCESS: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 154 | name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS; |
| 155 | break; |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 156 | case ACL_TYPE_DEFAULT: |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 157 | name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT; |
| 158 | break; |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 159 | default: |
Al Viro | 073aaa1 | 2009-06-09 12:11:54 -0400 | [diff] [blame] | 160 | BUG(); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 161 | } |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 162 | retval = ext4_xattr_get(inode, name_index, "", NULL, 0); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 163 | if (retval > 0) { |
Josef Bacik | 216553c | 2008-04-29 22:02:02 -0400 | [diff] [blame] | 164 | value = kmalloc(retval, GFP_NOFS); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 165 | if (!value) |
| 166 | return ERR_PTR(-ENOMEM); |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 167 | retval = ext4_xattr_get(inode, name_index, "", value, retval); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 168 | } |
| 169 | if (retval > 0) |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 170 | acl = ext4_acl_from_disk(value, retval); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 171 | else if (retval == -ENODATA || retval == -ENOSYS) |
| 172 | acl = NULL; |
| 173 | else |
| 174 | acl = ERR_PTR(retval); |
| 175 | kfree(value); |
| 176 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 177 | return acl; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Set the access or default ACL of an inode. |
| 182 | * |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 183 | * inode->i_mutex: down unless called from ext4_new_inode |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 184 | */ |
| 185 | static int |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 186 | __ext4_set_acl(handle_t *handle, struct inode *inode, int type, |
Tahsin Erdogan | af65207 | 2017-07-06 00:01:59 -0400 | [diff] [blame] | 187 | struct posix_acl *acl, int xattr_flags) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 188 | { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 189 | int name_index; |
| 190 | void *value = NULL; |
| 191 | size_t size = 0; |
| 192 | int error; |
| 193 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 194 | switch (type) { |
| 195 | case ACL_TYPE_ACCESS: |
| 196 | name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS; |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 197 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 198 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 199 | case ACL_TYPE_DEFAULT: |
| 200 | name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT; |
| 201 | if (!S_ISDIR(inode->i_mode)) |
| 202 | return acl ? -EACCES : 0; |
| 203 | break; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 204 | |
Theodore Ts'o | 2b2d6d0 | 2008-07-26 16:15:44 -0400 | [diff] [blame] | 205 | default: |
| 206 | return -EINVAL; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 207 | } |
| 208 | if (acl) { |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 209 | value = ext4_acl_to_disk(acl, &size); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 210 | if (IS_ERR(value)) |
| 211 | return (int)PTR_ERR(value); |
| 212 | } |
| 213 | |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 214 | error = ext4_xattr_set_handle(handle, inode, name_index, "", |
Tahsin Erdogan | af65207 | 2017-07-06 00:01:59 -0400 | [diff] [blame] | 215 | value, size, xattr_flags); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 216 | |
| 217 | kfree(value); |
Carlos Guerrero Álvarez | 6b6aeff | 2020-04-16 16:14:56 +0200 | [diff] [blame^] | 218 | if (!error) |
Al Viro | 073aaa1 | 2009-06-09 12:11:54 -0400 | [diff] [blame] | 219 | set_cached_acl(inode, type, acl); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 220 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 221 | return error; |
| 222 | } |
| 223 | |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 224 | int |
| 225 | ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type) |
| 226 | { |
| 227 | handle_t *handle; |
Tahsin Erdogan | c1a5d5f | 2017-06-21 22:28:40 -0400 | [diff] [blame] | 228 | int error, credits, retries = 0; |
| 229 | size_t acl_size = acl ? ext4_acl_size(acl->a_count) : 0; |
Jan Kara | a3bb2d5 | 2017-07-30 23:33:01 -0400 | [diff] [blame] | 230 | umode_t mode = inode->i_mode; |
| 231 | int update_mode = 0; |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 232 | |
Tahsin Erdogan | b8cb5a5 | 2017-05-24 18:24:07 -0400 | [diff] [blame] | 233 | error = dquot_initialize(inode); |
| 234 | if (error) |
| 235 | return error; |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 236 | retry: |
Tahsin Erdogan | af65207 | 2017-07-06 00:01:59 -0400 | [diff] [blame] | 237 | error = ext4_xattr_set_credits(inode, acl_size, false /* is_create */, |
| 238 | &credits); |
Tahsin Erdogan | dec214d | 2017-06-22 11:44:55 -0400 | [diff] [blame] | 239 | if (error) |
| 240 | return error; |
| 241 | |
Tahsin Erdogan | c1a5d5f | 2017-06-21 22:28:40 -0400 | [diff] [blame] | 242 | handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits); |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 243 | if (IS_ERR(handle)) |
| 244 | return PTR_ERR(handle); |
| 245 | |
Jan Kara | a3bb2d5 | 2017-07-30 23:33:01 -0400 | [diff] [blame] | 246 | if ((type == ACL_TYPE_ACCESS) && acl) { |
| 247 | error = posix_acl_update_mode(inode, &mode, &acl); |
| 248 | if (error) |
| 249 | goto out_stop; |
Chengguang Xu | 0a1e825 | 2018-12-10 00:22:38 -0500 | [diff] [blame] | 250 | if (mode != inode->i_mode) |
| 251 | update_mode = 1; |
Jan Kara | a3bb2d5 | 2017-07-30 23:33:01 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Tahsin Erdogan | af65207 | 2017-07-06 00:01:59 -0400 | [diff] [blame] | 254 | error = __ext4_set_acl(handle, inode, type, acl, 0 /* xattr_flags */); |
Jan Kara | a3bb2d5 | 2017-07-30 23:33:01 -0400 | [diff] [blame] | 255 | if (!error && update_mode) { |
| 256 | inode->i_mode = mode; |
| 257 | inode->i_ctime = current_time(inode); |
| 258 | ext4_mark_inode_dirty(handle, inode); |
| 259 | } |
| 260 | out_stop: |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 261 | ext4_journal_stop(handle); |
| 262 | if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) |
| 263 | goto retry; |
| 264 | return error; |
| 265 | } |
| 266 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 267 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 268 | * Initialize the ACLs of a new inode. Called from ext4_new_inode. |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 269 | * |
| 270 | * dir->i_mutex: down |
| 271 | * inode->i_mutex: up (access to inode is still exclusive) |
| 272 | */ |
| 273 | int |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 274 | ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 275 | { |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 276 | struct posix_acl *default_acl, *acl; |
Andrew Morton | 63f5793 | 2006-10-11 01:21:24 -0700 | [diff] [blame] | 277 | int error; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 278 | |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 279 | error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl); |
Al Viro | bc26ab5 | 2011-07-23 00:18:02 -0400 | [diff] [blame] | 280 | if (error) |
| 281 | return error; |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 282 | |
| 283 | if (default_acl) { |
| 284 | error = __ext4_set_acl(handle, inode, ACL_TYPE_DEFAULT, |
Tahsin Erdogan | af65207 | 2017-07-06 00:01:59 -0400 | [diff] [blame] | 285 | default_acl, XATTR_CREATE); |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 286 | posix_acl_release(default_acl); |
Chengguang Xu | 6fd9417 | 2018-10-06 22:40:34 -0400 | [diff] [blame] | 287 | } else { |
| 288 | inode->i_default_acl = NULL; |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 289 | } |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 290 | if (acl) { |
| 291 | if (!error) |
| 292 | error = __ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, |
Tahsin Erdogan | af65207 | 2017-07-06 00:01:59 -0400 | [diff] [blame] | 293 | acl, XATTR_CREATE); |
Christoph Hellwig | 64e178a | 2013-12-20 05:16:44 -0800 | [diff] [blame] | 294 | posix_acl_release(acl); |
Chengguang Xu | 6fd9417 | 2018-10-06 22:40:34 -0400 | [diff] [blame] | 295 | } else { |
| 296 | inode->i_acl = NULL; |
Eugene Shatokhin | 24ec19b | 2012-11-08 15:11:11 -0500 | [diff] [blame] | 297 | } |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 298 | return error; |
| 299 | } |