blob: a9547144a09995104d530add71577dd61fe02c3d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Randy Dunlap16f7e0f2006-01-11 12:17:46 -08002#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#include <linux/fs.h>
4#include <linux/posix_acl.h>
Al Virof466c6f2012-03-17 01:16:43 -04005#include "reiserfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/errno.h>
7#include <linux/pagemap.h>
8#include <linux/xattr.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Christoph Hellwig9a59f4522005-06-23 00:10:19 -070010#include <linux/posix_acl_xattr.h>
Al Viroc45ac882012-03-17 00:59:06 -040011#include "xattr.h"
Al Viroa3063ab2012-03-17 01:03:10 -040012#include "acl.h"
Fabian Frederick170939912014-08-08 14:21:12 -070013#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Christoph Hellwig47f70d02013-12-20 05:16:49 -080015static int __reiserfs_set_acl(struct reiserfs_transaction_handle *th,
Jeff Mahoney0ab26212009-03-30 14:02:39 -040016 struct inode *inode, int type,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070017 struct posix_acl *acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Christoph Hellwig47f70d02013-12-20 05:16:49 -080019
20int
Christian Brauner549c7292021-01-21 14:19:43 +010021reiserfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
22 struct posix_acl *acl, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
Jeff Mahoney0ab26212009-03-30 14:02:39 -040024 int error, error2;
25 struct reiserfs_transaction_handle th;
26 size_t jcreate_blocks;
Christoph Hellwig47f70d02013-12-20 05:16:49 -080027 int size = acl ? posix_acl_xattr_size(acl->a_count) : 0;
Ernesto A. Fernándezfcea8ae2017-07-17 18:42:41 +020028 int update_mode = 0;
29 umode_t mode = inode->i_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Jeff Mahoney098297b2014-04-23 10:00:36 -040031 /*
32 * Pessimism: We can't assume that anything from the xattr root up
33 * has been created.
34 */
Jeff Mahoney0ab26212009-03-30 14:02:39 -040035
36 jcreate_blocks = reiserfs_xattr_jcreate_nblocks(inode) +
37 reiserfs_xattr_nblocks(inode, size) * 2;
38
39 reiserfs_write_lock(inode->i_sb);
40 error = journal_begin(&th, inode->i_sb, jcreate_blocks);
Jeff Mahoney4c051412013-08-08 17:27:19 -040041 reiserfs_write_unlock(inode->i_sb);
Jeff Mahoney0ab26212009-03-30 14:02:39 -040042 if (error == 0) {
Jan Kara6883cd72017-06-22 09:32:49 +020043 if (type == ACL_TYPE_ACCESS && acl) {
Christian Braunere65ce2a2021-01-21 14:19:27 +010044 error = posix_acl_update_mode(&init_user_ns, inode,
45 &mode, &acl);
Jan Kara6883cd72017-06-22 09:32:49 +020046 if (error)
47 goto unlock;
Ernesto A. Fernándezfcea8ae2017-07-17 18:42:41 +020048 update_mode = 1;
Jan Kara6883cd72017-06-22 09:32:49 +020049 }
Christoph Hellwig47f70d02013-12-20 05:16:49 -080050 error = __reiserfs_set_acl(&th, inode, type, acl);
Ernesto A. Fernándezfcea8ae2017-07-17 18:42:41 +020051 if (!error && update_mode)
52 inode->i_mode = mode;
Jan Kara6883cd72017-06-22 09:32:49 +020053unlock:
Jeff Mahoney4c051412013-08-08 17:27:19 -040054 reiserfs_write_lock(inode->i_sb);
Jeff Mahoney58d85422014-04-23 10:00:38 -040055 error2 = journal_end(&th);
Jeff Mahoney4c051412013-08-08 17:27:19 -040056 reiserfs_write_unlock(inode->i_sb);
Jeff Mahoney0ab26212009-03-30 14:02:39 -040057 if (error2)
58 error = error2;
59 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return error;
62}
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064/*
65 * Convert from filesystem to in-memory representation.
66 */
Christoph Hellwig9dad9432013-12-20 05:16:36 -080067static struct posix_acl *reiserfs_posix_acl_from_disk(const void *value, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 const char *end = (char *)value + size;
70 int n, count;
71 struct posix_acl *acl;
72
73 if (!value)
74 return NULL;
75 if (size < sizeof(reiserfs_acl_header))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070076 return ERR_PTR(-EINVAL);
77 if (((reiserfs_acl_header *) value)->a_version !=
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 cpu_to_le32(REISERFS_ACL_VERSION))
79 return ERR_PTR(-EINVAL);
80 value = (char *)value + sizeof(reiserfs_acl_header);
81 count = reiserfs_acl_count(size);
82 if (count < 0)
83 return ERR_PTR(-EINVAL);
84 if (count == 0)
85 return NULL;
86 acl = posix_acl_alloc(count, GFP_NOFS);
87 if (!acl)
88 return ERR_PTR(-ENOMEM);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070089 for (n = 0; n < count; n++) {
90 reiserfs_acl_entry *entry = (reiserfs_acl_entry *) value;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 if ((char *)value + sizeof(reiserfs_acl_entry_short) > end)
92 goto fail;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070093 acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070095 switch (acl->a_entries[n].e_tag) {
96 case ACL_USER_OBJ:
97 case ACL_GROUP_OBJ:
98 case ACL_MASK:
99 case ACL_OTHER:
100 value = (char *)value +
101 sizeof(reiserfs_acl_entry_short);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700102 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700104 case ACL_USER:
Eric W. Biedermandf814652012-02-07 16:30:06 -0800105 value = (char *)value + sizeof(reiserfs_acl_entry);
106 if ((char *)value > end)
107 goto fail;
108 acl->a_entries[n].e_uid =
109 make_kuid(&init_user_ns,
110 le32_to_cpu(entry->e_id));
111 break;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700112 case ACL_GROUP:
113 value = (char *)value + sizeof(reiserfs_acl_entry);
114 if ((char *)value > end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 goto fail;
Eric W. Biedermandf814652012-02-07 16:30:06 -0800116 acl->a_entries[n].e_gid =
117 make_kgid(&init_user_ns,
118 le32_to_cpu(entry->e_id));
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700119 break;
120
121 default:
122 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124 }
125 if (value != end)
126 goto fail;
127 return acl;
128
Jeff Mahoneycf776a72014-04-23 10:00:41 -0400129fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 posix_acl_release(acl);
131 return ERR_PTR(-EINVAL);
132}
133
134/*
135 * Convert from in-memory to filesystem representation.
136 */
Christoph Hellwig9dad9432013-12-20 05:16:36 -0800137static void *reiserfs_posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 reiserfs_acl_header *ext_acl;
140 char *e;
141 int n;
142
143 *size = reiserfs_acl_size(acl->a_count);
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800144 ext_acl = kmalloc(sizeof(reiserfs_acl_header) +
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700145 acl->a_count *
146 sizeof(reiserfs_acl_entry),
147 GFP_NOFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 if (!ext_acl)
149 return ERR_PTR(-ENOMEM);
150 ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION);
151 e = (char *)ext_acl + sizeof(reiserfs_acl_header);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700152 for (n = 0; n < acl->a_count; n++) {
Eric W. Biedermandf814652012-02-07 16:30:06 -0800153 const struct posix_acl_entry *acl_e = &acl->a_entries[n];
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700154 reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e;
155 entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700157 switch (acl->a_entries[n].e_tag) {
158 case ACL_USER:
Eric W. Biedermandf814652012-02-07 16:30:06 -0800159 entry->e_id = cpu_to_le32(
160 from_kuid(&init_user_ns, acl_e->e_uid));
161 e += sizeof(reiserfs_acl_entry);
162 break;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700163 case ACL_GROUP:
Eric W. Biedermandf814652012-02-07 16:30:06 -0800164 entry->e_id = cpu_to_le32(
165 from_kgid(&init_user_ns, acl_e->e_gid));
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700166 e += sizeof(reiserfs_acl_entry);
167 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700169 case ACL_USER_OBJ:
170 case ACL_GROUP_OBJ:
171 case ACL_MASK:
172 case ACL_OTHER:
173 e += sizeof(reiserfs_acl_entry_short);
174 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700176 default:
177 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
179 }
180 return (char *)ext_acl;
181
Jeff Mahoneycf776a72014-04-23 10:00:41 -0400182fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 kfree(ext_acl);
184 return ERR_PTR(-EINVAL);
185}
186
187/*
188 * Inode operation get_posix_acl().
189 *
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800190 * inode->i_mutex: down
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 * BKL held [before 2.5.x]
192 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700193struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
195 char *name, *value;
Al Viro073aaa12009-06-09 12:11:54 -0400196 struct posix_acl *acl;
Adrian Bunk3cdc4092006-03-25 03:07:50 -0800197 int size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700200 switch (type) {
201 case ACL_TYPE_ACCESS:
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100202 name = XATTR_NAME_POSIX_ACL_ACCESS;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700203 break;
204 case ACL_TYPE_DEFAULT:
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100205 name = XATTR_NAME_POSIX_ACL_DEFAULT;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700206 break;
207 default:
Al Viro073aaa12009-06-09 12:11:54 -0400208 BUG();
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700211 size = reiserfs_xattr_get(inode, name, NULL, 0);
Adrian Bunk3cdc4092006-03-25 03:07:50 -0800212 if (size < 0) {
Andreas Gruenbacherb8a7a3a2016-03-24 14:38:37 +0100213 if (size == -ENODATA || size == -ENOSYS)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700214 return NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700215 return ERR_PTR(size);
216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700218 value = kmalloc(size, GFP_NOFS);
219 if (!value)
220 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 retval = reiserfs_xattr_get(inode, name, value, size);
223 if (retval == -ENODATA || retval == -ENOSYS) {
Jeff Mahoney098297b2014-04-23 10:00:36 -0400224 /*
225 * This shouldn't actually happen as it should have
226 * been caught above.. but just in case
227 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 acl = NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700229 } else if (retval < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 acl = ERR_PTR(retval);
231 } else {
Christoph Hellwig9dad9432013-12-20 05:16:36 -0800232 acl = reiserfs_posix_acl_from_disk(value, retval);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 kfree(value);
236 return acl;
237}
238
239/*
240 * Inode operation set_posix_acl().
241 *
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800242 * inode->i_mutex: down
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 * BKL held [before 2.5.x]
244 */
245static int
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800246__reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400247 int type, struct posix_acl *acl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700249 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 void *value = NULL;
Jeff Mahoney48b32a32009-03-30 14:02:38 -0400251 size_t size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700254 switch (type) {
255 case ACL_TYPE_ACCESS:
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100256 name = XATTR_NAME_POSIX_ACL_ACCESS;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700257 break;
258 case ACL_TYPE_DEFAULT:
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100259 name = XATTR_NAME_POSIX_ACL_DEFAULT;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700260 if (!S_ISDIR(inode->i_mode))
261 return acl ? -EACCES : 0;
262 break;
263 default:
264 return -EINVAL;
265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700267 if (acl) {
Christoph Hellwig9dad9432013-12-20 05:16:36 -0800268 value = reiserfs_posix_acl_to_disk(acl, &size);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700269 if (IS_ERR(value))
270 return (int)PTR_ERR(value);
Jeff Mahoney48b32a32009-03-30 14:02:38 -0400271 }
272
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400273 error = reiserfs_xattr_set_handle(th, inode, name, value, size, 0);
Jeff Mahoney48b32a32009-03-30 14:02:38 -0400274
275 /*
276 * Ensure that the inode gets dirtied if we're only using
277 * the mode bits and an old ACL didn't exist. We don't need
278 * to check if the inode is hashed here since we won't get
279 * called by reiserfs_inherit_default_acl().
280 */
281 if (error == -ENODATA) {
282 error = 0;
283 if (type == ACL_TYPE_ACCESS) {
Deepa Dinamani02027d42016-09-14 07:48:05 -0700284 inode->i_ctime = current_time(inode);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700285 mark_inode_dirty(inode);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700286 }
287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
James Lamanna833d3042005-10-30 15:00:16 -0800289 kfree(value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Jeff Mahoneyd9845612009-03-30 14:02:35 -0400291 if (!error)
Al Viro073aaa12009-06-09 12:11:54 -0400292 set_cached_acl(inode, type, acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 return error;
295}
296
Jeff Mahoney098297b2014-04-23 10:00:36 -0400297/*
298 * dir->i_mutex: locked,
299 * inode is new and not released into the wild yet
300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301int
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400302reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
303 struct inode *dir, struct dentry *dentry,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700304 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800306 struct posix_acl *default_acl, *acl;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700307 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700309 /* ACLs only get applied to files and directories */
310 if (S_ISLNK(inode->i_mode))
311 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Jeff Mahoney098297b2014-04-23 10:00:36 -0400313 /*
314 * ACLs can only be used on "new" objects, so if it's an old object
315 * there is nothing to inherit from
316 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700317 if (get_inode_sd_version(dir) == STAT_DATA_V1)
318 goto apply_umask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Jeff Mahoney098297b2014-04-23 10:00:36 -0400320 /*
321 * Don't apply ACLs to objects in the .reiserfs_priv tree.. This
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700322 * would be useless since permissions are ignored, and a pain because
Jeff Mahoney098297b2014-04-23 10:00:36 -0400323 * it introduces locking cycles
324 */
Jeff Mahoney60e4cf62019-10-24 10:31:27 -0400325 if (IS_PRIVATE(inode))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700326 goto apply_umask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800328 err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
329 if (err)
330 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800332 if (default_acl) {
333 err = __reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
334 default_acl);
335 posix_acl_release(default_acl);
336 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700337 if (acl) {
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800338 if (!err)
339 err = __reiserfs_set_acl(th, inode, ACL_TYPE_ACCESS,
340 acl);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700341 posix_acl_release(acl);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700344 return err;
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800345
Jeff Mahoneycf776a72014-04-23 10:00:41 -0400346apply_umask:
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800347 /* no ACL, apply umask */
348 inode->i_mode &= ~current_umask();
349 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400352/* This is used to cache the default acl before a new object is created.
353 * The biggest reason for this is to get an idea of how many blocks will
354 * actually be required for the create operation if we must inherit an ACL.
355 * An ACL write can add up to 3 object creations and an additional file write
356 * so we'd prefer not to reserve that many blocks in the journal if we can.
357 * It also has the advantage of not loading the ACL with a transaction open,
358 * this may seem silly, but if the owner of the directory is doing the
359 * creation, the ACL may not be loaded since the permissions wouldn't require
360 * it.
361 * We return the number of blocks required for the transaction.
362 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700363int reiserfs_cache_default_acl(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400365 struct posix_acl *acl;
366 int nblocks = 0;
367
368 if (IS_PRIVATE(inode))
369 return 0;
370
Al Viro7dffc87f2016-03-18 13:25:43 -0400371 acl = get_acl(inode, ACL_TYPE_DEFAULT);
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400372
373 if (acl && !IS_ERR(acl)) {
374 int size = reiserfs_acl_size(acl->a_count);
375
376 /* Other xattrs can be created during inode creation. We don't
377 * want to claim too many blocks, so we check to see if we
Randy Dunlap9436fb42020-08-04 19:49:25 -0700378 * need to create the tree to the xattrs, and then we
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400379 * just want two files. */
380 nblocks = reiserfs_xattr_jcreate_nblocks(inode);
381 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
382
383 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
384
385 /* We need to account for writes + bitmaps for two files */
386 nblocks += reiserfs_xattr_nblocks(inode, size) * 4;
387 posix_acl_release(acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400390 return nblocks;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700391}
392
Jeff Mahoney4c051412013-08-08 17:27:19 -0400393/*
394 * Called under i_mutex
395 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700396int reiserfs_acl_chmod(struct inode *inode)
397{
Jeff Mahoney4a857012013-05-31 15:54:17 -0400398 if (IS_PRIVATE(inode))
399 return 0;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700400 if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800401 !reiserfs_posixacl(inode->i_sb))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700402 return 0;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700403
Christian Braunere65ce2a2021-01-21 14:19:27 +0100404 return posix_acl_chmod(&init_user_ns, inode, inode->i_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}