aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/acl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/f2fs/acl.c')
-rw-r--r--fs/f2fs/acl.c174
1 files changed, 17 insertions, 157 deletions
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index d0fc287efeff..fa8da4cb8c4b 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -17,9 +17,6 @@
17#include "xattr.h" 17#include "xattr.h"
18#include "acl.h" 18#include "acl.h"
19 19
20#define get_inode_mode(i) ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
21 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
22
23static inline size_t f2fs_acl_size(int count) 20static inline size_t f2fs_acl_size(int count)
24{ 21{
25 if (count <= 4) { 22 if (count <= 4) {
@@ -167,19 +164,11 @@ fail:
167 164
168struct posix_acl *f2fs_get_acl(struct inode *inode, int type) 165struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
169{ 166{
170 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
171 int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT; 167 int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT;
172 void *value = NULL; 168 void *value = NULL;
173 struct posix_acl *acl; 169 struct posix_acl *acl;
174 int retval; 170 int retval;
175 171
176 if (!test_opt(sbi, POSIX_ACL))
177 return NULL;
178
179 acl = get_cached_acl(inode, type);
180 if (acl != ACL_NOT_CACHED)
181 return acl;
182
183 if (type == ACL_TYPE_ACCESS) 172 if (type == ACL_TYPE_ACCESS)
184 name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS; 173 name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
185 174
@@ -205,21 +194,15 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
205 return acl; 194 return acl;
206} 195}
207 196
208static int f2fs_set_acl(struct inode *inode, int type, 197static int __f2fs_set_acl(struct inode *inode, int type,
209 struct posix_acl *acl, struct page *ipage) 198 struct posix_acl *acl, struct page *ipage)
210{ 199{
211 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
212 struct f2fs_inode_info *fi = F2FS_I(inode); 200 struct f2fs_inode_info *fi = F2FS_I(inode);
213 int name_index; 201 int name_index;
214 void *value = NULL; 202 void *value = NULL;
215 size_t size = 0; 203 size_t size = 0;
216 int error; 204 int error;
217 205
218 if (!test_opt(sbi, POSIX_ACL))
219 return 0;
220 if (S_ISLNK(inode->i_mode))
221 return -EOPNOTSUPP;
222
223 switch (type) { 206 switch (type) {
224 case ACL_TYPE_ACCESS: 207 case ACL_TYPE_ACCESS:
225 name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS; 208 name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
@@ -261,154 +244,31 @@ static int f2fs_set_acl(struct inode *inode, int type,
261 return error; 244 return error;
262} 245}
263 246
264int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage) 247int f2fs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
265{ 248{
266 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); 249 return __f2fs_set_acl(inode, type, acl, NULL);
267 struct posix_acl *acl = NULL;
268 int error = 0;
269
270 if (!S_ISLNK(inode->i_mode)) {
271 if (test_opt(sbi, POSIX_ACL)) {
272 acl = f2fs_get_acl(dir, ACL_TYPE_DEFAULT);
273 if (IS_ERR(acl))
274 return PTR_ERR(acl);
275 }
276 if (!acl)
277 inode->i_mode &= ~current_umask();
278 }
279
280 if (!test_opt(sbi, POSIX_ACL) || !acl)
281 goto cleanup;
282
283 if (S_ISDIR(inode->i_mode)) {
284 error = f2fs_set_acl(inode, ACL_TYPE_DEFAULT, acl, ipage);
285 if (error)
286 goto cleanup;
287 }
288 error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
289 if (error < 0)
290 return error;
291 if (error > 0)
292 error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl, ipage);
293cleanup:
294 posix_acl_release(acl);
295 return error;
296} 250}
297 251
298int f2fs_acl_chmod(struct inode *inode) 252int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage)
299{ 253{
300 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 254 struct posix_acl *default_acl, *acl;
301 struct posix_acl *acl; 255 int error = 0;
302 int error;
303 umode_t mode = get_inode_mode(inode);
304
305 if (!test_opt(sbi, POSIX_ACL))
306 return 0;
307 if (S_ISLNK(mode))
308 return -EOPNOTSUPP;
309
310 acl = f2fs_get_acl(inode, ACL_TYPE_ACCESS);
311 if (IS_ERR(acl) || !acl)
312 return PTR_ERR(acl);
313 256
314 error = posix_acl_chmod(&acl, GFP_KERNEL, mode); 257 error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
315 if (error) 258 if (error)
316 return error; 259 return error;
317 260
318 error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl, NULL); 261 if (default_acl) {
319 posix_acl_release(acl); 262 error = __f2fs_set_acl(inode, ACL_TYPE_DEFAULT, default_acl,
320 return error; 263 ipage);
321} 264 posix_acl_release(default_acl);
322 265 }
323static size_t f2fs_xattr_list_acl(struct dentry *dentry, char *list, 266 if (acl) {
324 size_t list_size, const char *name, size_t name_len, int type) 267 if (error)
325{ 268 error = __f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl,
326 struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb); 269 ipage);
327 const char *xname = POSIX_ACL_XATTR_DEFAULT; 270 posix_acl_release(acl);
328 size_t size;
329
330 if (!test_opt(sbi, POSIX_ACL))
331 return 0;
332
333 if (type == ACL_TYPE_ACCESS)
334 xname = POSIX_ACL_XATTR_ACCESS;
335
336 size = strlen(xname) + 1;
337 if (list && size <= list_size)
338 memcpy(list, xname, size);
339 return size;
340}
341
342static int f2fs_xattr_get_acl(struct dentry *dentry, const char *name,
343 void *buffer, size_t size, int type)
344{
345 struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
346 struct posix_acl *acl;
347 int error;
348
349 if (strcmp(name, "") != 0)
350 return -EINVAL;
351 if (!test_opt(sbi, POSIX_ACL))
352 return -EOPNOTSUPP;
353
354 acl = f2fs_get_acl(dentry->d_inode, type);
355 if (IS_ERR(acl))
356 return PTR_ERR(acl);
357 if (!acl)
358 return -ENODATA;
359 error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
360 posix_acl_release(acl);
361
362 return error;
363}
364
365static int f2fs_xattr_set_acl(struct dentry *dentry, const char *name,
366 const void *value, size_t size, int flags, int type)
367{
368 struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
369 struct inode *inode = dentry->d_inode;
370 struct posix_acl *acl = NULL;
371 int error;
372
373 if (strcmp(name, "") != 0)
374 return -EINVAL;
375 if (!test_opt(sbi, POSIX_ACL))
376 return -EOPNOTSUPP;
377 if (!inode_owner_or_capable(inode))
378 return -EPERM;
379
380 if (value) {
381 acl = posix_acl_from_xattr(&init_user_ns, value, size);
382 if (IS_ERR(acl))
383 return PTR_ERR(acl);
384 if (acl) {
385 error = posix_acl_valid(acl);
386 if (error)
387 goto release_and_out;
388 }
389 } else {
390 acl = NULL;
391 } 271 }
392 272
393 error = f2fs_set_acl(inode, type, acl, NULL);
394
395release_and_out:
396 posix_acl_release(acl);
397 return error; 273 return error;
398} 274}
399
400const struct xattr_handler f2fs_xattr_acl_default_handler = {
401 .prefix = POSIX_ACL_XATTR_DEFAULT,
402 .flags = ACL_TYPE_DEFAULT,
403 .list = f2fs_xattr_list_acl,
404 .get = f2fs_xattr_get_acl,
405 .set = f2fs_xattr_set_acl,
406};
407
408const struct xattr_handler f2fs_xattr_acl_access_handler = {
409 .prefix = POSIX_ACL_XATTR_ACCESS,
410 .flags = ACL_TYPE_ACCESS,
411 .list = f2fs_xattr_list_acl,
412 .get = f2fs_xattr_get_acl,
413 .set = f2fs_xattr_set_acl,
414};