blob: 54415f0e3d1868601ab08a6ff49d2fb29cdfb2da [file] [log] [blame]
Randy Dunlap16f7e0f2006-01-11 12:17:46 -08001#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/fs.h>
3#include <linux/posix_acl.h>
Al Virof466c6f2012-03-17 01:16:43 -04004#include "reiserfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/errno.h>
6#include <linux/pagemap.h>
7#include <linux/xattr.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
Christoph Hellwig9a59f452005-06-23 00:10:19 -07009#include <linux/posix_acl_xattr.h>
Al Viroc45ac882012-03-17 00:59:06 -040010#include "xattr.h"
Al Viroa3063ab2012-03-17 01:03:10 -040011#include "acl.h"
Fabian Frederick170939912014-08-08 14:21:12 -070012#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Christoph Hellwig47f70d02013-12-20 05:16:49 -080014static int __reiserfs_set_acl(struct reiserfs_transaction_handle *th,
Jeff Mahoney0ab26212009-03-30 14:02:39 -040015 struct inode *inode, int type,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070016 struct posix_acl *acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Christoph Hellwig47f70d02013-12-20 05:16:49 -080018
19int
20reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
Jeff Mahoney0ab26212009-03-30 14:02:39 -040022 int error, error2;
23 struct reiserfs_transaction_handle th;
24 size_t jcreate_blocks;
Christoph Hellwig47f70d02013-12-20 05:16:49 -080025 int size = acl ? posix_acl_xattr_size(acl->a_count) : 0;
Ernesto A. Fernándezfcea8ae2017-07-17 18:42:41 +020026 int update_mode = 0;
27 umode_t mode = inode->i_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Jeff Mahoney098297b2014-04-23 10:00:36 -040029 /*
30 * Pessimism: We can't assume that anything from the xattr root up
31 * has been created.
32 */
Jeff Mahoney0ab26212009-03-30 14:02:39 -040033
34 jcreate_blocks = reiserfs_xattr_jcreate_nblocks(inode) +
35 reiserfs_xattr_nblocks(inode, size) * 2;
36
37 reiserfs_write_lock(inode->i_sb);
38 error = journal_begin(&th, inode->i_sb, jcreate_blocks);
Jeff Mahoney4c051412013-08-08 17:27:19 -040039 reiserfs_write_unlock(inode->i_sb);
Jeff Mahoney0ab26212009-03-30 14:02:39 -040040 if (error == 0) {
Jan Kara6883cd72017-06-22 09:32:49 +020041 if (type == ACL_TYPE_ACCESS && acl) {
Ernesto A. Fernándezfcea8ae2017-07-17 18:42:41 +020042 error = posix_acl_update_mode(inode, &mode, &acl);
Jan Kara6883cd72017-06-22 09:32:49 +020043 if (error)
44 goto unlock;
Ernesto A. Fernándezfcea8ae2017-07-17 18:42:41 +020045 update_mode = 1;
Jan Kara6883cd72017-06-22 09:32:49 +020046 }
Christoph Hellwig47f70d02013-12-20 05:16:49 -080047 error = __reiserfs_set_acl(&th, inode, type, acl);
Ernesto A. Fernándezfcea8ae2017-07-17 18:42:41 +020048 if (!error && update_mode)
49 inode->i_mode = mode;
Jan Kara6883cd72017-06-22 09:32:49 +020050unlock:
Jeff Mahoney4c051412013-08-08 17:27:19 -040051 reiserfs_write_lock(inode->i_sb);
Jeff Mahoney58d85422014-04-23 10:00:38 -040052 error2 = journal_end(&th);
Jeff Mahoney4c051412013-08-08 17:27:19 -040053 reiserfs_write_unlock(inode->i_sb);
Jeff Mahoney0ab26212009-03-30 14:02:39 -040054 if (error2)
55 error = error2;
56 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 return error;
59}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/*
62 * Convert from filesystem to in-memory representation.
63 */
Christoph Hellwig9dad9432013-12-20 05:16:36 -080064static struct posix_acl *reiserfs_posix_acl_from_disk(const void *value, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66 const char *end = (char *)value + size;
67 int n, count;
68 struct posix_acl *acl;
69
70 if (!value)
71 return NULL;
72 if (size < sizeof(reiserfs_acl_header))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070073 return ERR_PTR(-EINVAL);
74 if (((reiserfs_acl_header *) value)->a_version !=
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 cpu_to_le32(REISERFS_ACL_VERSION))
76 return ERR_PTR(-EINVAL);
77 value = (char *)value + sizeof(reiserfs_acl_header);
78 count = reiserfs_acl_count(size);
79 if (count < 0)
80 return ERR_PTR(-EINVAL);
81 if (count == 0)
82 return NULL;
83 acl = posix_acl_alloc(count, GFP_NOFS);
84 if (!acl)
85 return ERR_PTR(-ENOMEM);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070086 for (n = 0; n < count; n++) {
87 reiserfs_acl_entry *entry = (reiserfs_acl_entry *) value;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 if ((char *)value + sizeof(reiserfs_acl_entry_short) > end)
89 goto fail;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070090 acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070092 switch (acl->a_entries[n].e_tag) {
93 case ACL_USER_OBJ:
94 case ACL_GROUP_OBJ:
95 case ACL_MASK:
96 case ACL_OTHER:
97 value = (char *)value +
98 sizeof(reiserfs_acl_entry_short);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070099 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700101 case ACL_USER:
Eric W. Biedermandf814652012-02-07 16:30:06 -0800102 value = (char *)value + sizeof(reiserfs_acl_entry);
103 if ((char *)value > end)
104 goto fail;
105 acl->a_entries[n].e_uid =
106 make_kuid(&init_user_ns,
107 le32_to_cpu(entry->e_id));
108 break;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700109 case ACL_GROUP:
110 value = (char *)value + sizeof(reiserfs_acl_entry);
111 if ((char *)value > end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 goto fail;
Eric W. Biedermandf814652012-02-07 16:30:06 -0800113 acl->a_entries[n].e_gid =
114 make_kgid(&init_user_ns,
115 le32_to_cpu(entry->e_id));
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700116 break;
117
118 default:
119 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121 }
122 if (value != end)
123 goto fail;
124 return acl;
125
Jeff Mahoneycf776a72014-04-23 10:00:41 -0400126fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 posix_acl_release(acl);
128 return ERR_PTR(-EINVAL);
129}
130
131/*
132 * Convert from in-memory to filesystem representation.
133 */
Christoph Hellwig9dad9432013-12-20 05:16:36 -0800134static void *reiserfs_posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 reiserfs_acl_header *ext_acl;
137 char *e;
138 int n;
139
140 *size = reiserfs_acl_size(acl->a_count);
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800141 ext_acl = kmalloc(sizeof(reiserfs_acl_header) +
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700142 acl->a_count *
143 sizeof(reiserfs_acl_entry),
144 GFP_NOFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 if (!ext_acl)
146 return ERR_PTR(-ENOMEM);
147 ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION);
148 e = (char *)ext_acl + sizeof(reiserfs_acl_header);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700149 for (n = 0; n < acl->a_count; n++) {
Eric W. Biedermandf814652012-02-07 16:30:06 -0800150 const struct posix_acl_entry *acl_e = &acl->a_entries[n];
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700151 reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e;
152 entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700154 switch (acl->a_entries[n].e_tag) {
155 case ACL_USER:
Eric W. Biedermandf814652012-02-07 16:30:06 -0800156 entry->e_id = cpu_to_le32(
157 from_kuid(&init_user_ns, acl_e->e_uid));
158 e += sizeof(reiserfs_acl_entry);
159 break;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700160 case ACL_GROUP:
Eric W. Biedermandf814652012-02-07 16:30:06 -0800161 entry->e_id = cpu_to_le32(
162 from_kgid(&init_user_ns, acl_e->e_gid));
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700163 e += sizeof(reiserfs_acl_entry);
164 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700166 case ACL_USER_OBJ:
167 case ACL_GROUP_OBJ:
168 case ACL_MASK:
169 case ACL_OTHER:
170 e += sizeof(reiserfs_acl_entry_short);
171 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700173 default:
174 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
176 }
177 return (char *)ext_acl;
178
Jeff Mahoneycf776a72014-04-23 10:00:41 -0400179fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 kfree(ext_acl);
181 return ERR_PTR(-EINVAL);
182}
183
184/*
185 * Inode operation get_posix_acl().
186 *
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800187 * inode->i_mutex: down
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 * BKL held [before 2.5.x]
189 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700190struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 char *name, *value;
Al Viro073aaa12009-06-09 12:11:54 -0400193 struct posix_acl *acl;
Adrian Bunk3cdc4092006-03-25 03:07:50 -0800194 int size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700197 switch (type) {
198 case ACL_TYPE_ACCESS:
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100199 name = XATTR_NAME_POSIX_ACL_ACCESS;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700200 break;
201 case ACL_TYPE_DEFAULT:
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100202 name = XATTR_NAME_POSIX_ACL_DEFAULT;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700203 break;
204 default:
Al Viro073aaa12009-06-09 12:11:54 -0400205 BUG();
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700208 size = reiserfs_xattr_get(inode, name, NULL, 0);
Adrian Bunk3cdc4092006-03-25 03:07:50 -0800209 if (size < 0) {
Andreas Gruenbacherb8a7a3a2016-03-24 14:38:37 +0100210 if (size == -ENODATA || size == -ENOSYS)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700211 return NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700212 return ERR_PTR(size);
213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700215 value = kmalloc(size, GFP_NOFS);
216 if (!value)
217 return ERR_PTR(-ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 retval = reiserfs_xattr_get(inode, name, value, size);
220 if (retval == -ENODATA || retval == -ENOSYS) {
Jeff Mahoney098297b2014-04-23 10:00:36 -0400221 /*
222 * This shouldn't actually happen as it should have
223 * been caught above.. but just in case
224 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 acl = NULL;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700226 } else if (retval < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 acl = ERR_PTR(retval);
228 } else {
Christoph Hellwig9dad9432013-12-20 05:16:36 -0800229 acl = reiserfs_posix_acl_from_disk(value, retval);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 kfree(value);
233 return acl;
234}
235
236/*
237 * Inode operation set_posix_acl().
238 *
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800239 * inode->i_mutex: down
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 * BKL held [before 2.5.x]
241 */
242static int
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800243__reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400244 int type, struct posix_acl *acl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700246 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 void *value = NULL;
Jeff Mahoney48b32a32009-03-30 14:02:38 -0400248 size_t size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700251 switch (type) {
252 case ACL_TYPE_ACCESS:
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100253 name = XATTR_NAME_POSIX_ACL_ACCESS;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700254 break;
255 case ACL_TYPE_DEFAULT:
Andreas Gruenbacher97d79292015-12-02 14:44:35 +0100256 name = XATTR_NAME_POSIX_ACL_DEFAULT;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700257 if (!S_ISDIR(inode->i_mode))
258 return acl ? -EACCES : 0;
259 break;
260 default:
261 return -EINVAL;
262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700264 if (acl) {
Christoph Hellwig9dad9432013-12-20 05:16:36 -0800265 value = reiserfs_posix_acl_to_disk(acl, &size);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700266 if (IS_ERR(value))
267 return (int)PTR_ERR(value);
Jeff Mahoney48b32a32009-03-30 14:02:38 -0400268 }
269
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400270 error = reiserfs_xattr_set_handle(th, inode, name, value, size, 0);
Jeff Mahoney48b32a32009-03-30 14:02:38 -0400271
272 /*
273 * Ensure that the inode gets dirtied if we're only using
274 * the mode bits and an old ACL didn't exist. We don't need
275 * to check if the inode is hashed here since we won't get
276 * called by reiserfs_inherit_default_acl().
277 */
278 if (error == -ENODATA) {
279 error = 0;
280 if (type == ACL_TYPE_ACCESS) {
Deepa Dinamani02027d42016-09-14 07:48:05 -0700281 inode->i_ctime = current_time(inode);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700282 mark_inode_dirty(inode);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700283 }
284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
James Lamanna833d3042005-10-30 15:00:16 -0800286 kfree(value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Jeff Mahoneyd9845612009-03-30 14:02:35 -0400288 if (!error)
Al Viro073aaa12009-06-09 12:11:54 -0400289 set_cached_acl(inode, type, acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 return error;
292}
293
Jeff Mahoney098297b2014-04-23 10:00:36 -0400294/*
295 * dir->i_mutex: locked,
296 * inode is new and not released into the wild yet
297 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298int
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400299reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
300 struct inode *dir, struct dentry *dentry,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700301 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800303 struct posix_acl *default_acl, *acl;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700304 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700306 /* ACLs only get applied to files and directories */
307 if (S_ISLNK(inode->i_mode))
308 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Jeff Mahoney098297b2014-04-23 10:00:36 -0400310 /*
311 * ACLs can only be used on "new" objects, so if it's an old object
312 * there is nothing to inherit from
313 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700314 if (get_inode_sd_version(dir) == STAT_DATA_V1)
315 goto apply_umask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Jeff Mahoney098297b2014-04-23 10:00:36 -0400317 /*
318 * Don't apply ACLs to objects in the .reiserfs_priv tree.. This
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700319 * would be useless since permissions are ignored, and a pain because
Jeff Mahoney098297b2014-04-23 10:00:36 -0400320 * it introduces locking cycles
321 */
Jeff Mahoney6dfede692009-03-30 14:02:32 -0400322 if (IS_PRIVATE(dir)) {
323 inode->i_flags |= S_PRIVATE;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700324 goto apply_umask;
325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800327 err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
328 if (err)
329 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800331 if (default_acl) {
332 err = __reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
333 default_acl);
334 posix_acl_release(default_acl);
335 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700336 if (acl) {
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800337 if (!err)
338 err = __reiserfs_set_acl(th, inode, ACL_TYPE_ACCESS,
339 acl);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700340 posix_acl_release(acl);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700343 return err;
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800344
Jeff Mahoneycf776a72014-04-23 10:00:41 -0400345apply_umask:
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800346 /* no ACL, apply umask */
347 inode->i_mode &= ~current_umask();
348 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400351/* This is used to cache the default acl before a new object is created.
352 * The biggest reason for this is to get an idea of how many blocks will
353 * actually be required for the create operation if we must inherit an ACL.
354 * An ACL write can add up to 3 object creations and an additional file write
355 * so we'd prefer not to reserve that many blocks in the journal if we can.
356 * It also has the advantage of not loading the ACL with a transaction open,
357 * this may seem silly, but if the owner of the directory is doing the
358 * creation, the ACL may not be loaded since the permissions wouldn't require
359 * it.
360 * We return the number of blocks required for the transaction.
361 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700362int reiserfs_cache_default_acl(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400364 struct posix_acl *acl;
365 int nblocks = 0;
366
367 if (IS_PRIVATE(inode))
368 return 0;
369
Al Viro7dffc872016-03-18 13:25:43 -0400370 acl = get_acl(inode, ACL_TYPE_DEFAULT);
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400371
372 if (acl && !IS_ERR(acl)) {
373 int size = reiserfs_acl_size(acl->a_count);
374
375 /* Other xattrs can be created during inode creation. We don't
376 * want to claim too many blocks, so we check to see if we
377 * we need to create the tree to the xattrs, and then we
378 * just want two files. */
379 nblocks = reiserfs_xattr_jcreate_nblocks(inode);
380 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
381
382 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
383
384 /* We need to account for writes + bitmaps for two files */
385 nblocks += reiserfs_xattr_nblocks(inode, size) * 4;
386 posix_acl_release(acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
388
Jeff Mahoney0ab26212009-03-30 14:02:39 -0400389 return nblocks;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700390}
391
Jeff Mahoney4c051412013-08-08 17:27:19 -0400392/*
393 * Called under i_mutex
394 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700395int reiserfs_acl_chmod(struct inode *inode)
396{
Jeff Mahoney4a857012013-05-31 15:54:17 -0400397 if (IS_PRIVATE(inode))
398 return 0;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700399 if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800400 !reiserfs_posixacl(inode->i_sb))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700401 return 0;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700402
Christoph Hellwig47f70d02013-12-20 05:16:49 -0800403 return posix_acl_chmod(inode, inode->i_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}