aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/f2fs/acl.c174
-rw-r--r--fs/f2fs/acl.h7
-rw-r--r--fs/f2fs/f2fs.h4
-rw-r--r--fs/f2fs/file.c3
-rw-r--r--fs/f2fs/namei.c2
-rw-r--r--fs/f2fs/xattr.c9
-rw-r--r--fs/f2fs/xattr.h2
7 files changed, 31 insertions, 170 deletions
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 45e84303c247..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};
diff --git a/fs/f2fs/acl.h b/fs/f2fs/acl.h
index 49633131e038..e0864651cdc1 100644
--- a/fs/f2fs/acl.h
+++ b/fs/f2fs/acl.h
@@ -37,18 +37,13 @@ struct f2fs_acl_header {
37#ifdef CONFIG_F2FS_FS_POSIX_ACL 37#ifdef CONFIG_F2FS_FS_POSIX_ACL
38 38
39extern struct posix_acl *f2fs_get_acl(struct inode *, int); 39extern struct posix_acl *f2fs_get_acl(struct inode *, int);
40extern int f2fs_acl_chmod(struct inode *); 40extern int f2fs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
41extern int f2fs_init_acl(struct inode *, struct inode *, struct page *); 41extern int f2fs_init_acl(struct inode *, struct inode *, struct page *);
42#else 42#else
43#define f2fs_check_acl NULL 43#define f2fs_check_acl NULL
44#define f2fs_get_acl NULL 44#define f2fs_get_acl NULL
45#define f2fs_set_acl NULL 45#define f2fs_set_acl NULL
46 46
47static inline int f2fs_acl_chmod(struct inode *inode)
48{
49 return 0;
50}
51
52static inline int f2fs_init_acl(struct inode *inode, struct inode *dir, 47static inline int f2fs_init_acl(struct inode *inode, struct inode *dir,
53 struct page *page) 48 struct page *page)
54{ 49{
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 89dc7508faf2..934b59cf819e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -953,6 +953,10 @@ static inline int f2fs_readonly(struct super_block *sb)
953 return sb->s_flags & MS_RDONLY; 953 return sb->s_flags & MS_RDONLY;
954} 954}
955 955
956#define get_inode_mode(i) \
957 ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
958 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
959
956/* 960/*
957 * file.c 961 * file.c
958 */ 962 */
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 7d714f4972d5..cf835e05f39b 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -390,7 +390,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
390 __setattr_copy(inode, attr); 390 __setattr_copy(inode, attr);
391 391
392 if (attr->ia_valid & ATTR_MODE) { 392 if (attr->ia_valid & ATTR_MODE) {
393 err = f2fs_acl_chmod(inode); 393 err = posix_acl_chmod(inode, get_inode_mode(inode));
394 if (err || is_inode_flag_set(fi, FI_ACL_MODE)) { 394 if (err || is_inode_flag_set(fi, FI_ACL_MODE)) {
395 inode->i_mode = fi->i_acl_mode; 395 inode->i_mode = fi->i_acl_mode;
396 clear_inode_flag(fi, FI_ACL_MODE); 396 clear_inode_flag(fi, FI_ACL_MODE);
@@ -405,6 +405,7 @@ const struct inode_operations f2fs_file_inode_operations = {
405 .getattr = f2fs_getattr, 405 .getattr = f2fs_getattr,
406 .setattr = f2fs_setattr, 406 .setattr = f2fs_setattr,
407 .get_acl = f2fs_get_acl, 407 .get_acl = f2fs_get_acl,
408 .set_acl = f2fs_set_acl,
408#ifdef CONFIG_F2FS_FS_XATTR 409#ifdef CONFIG_F2FS_FS_XATTR
409 .setxattr = generic_setxattr, 410 .setxattr = generic_setxattr,
410 .getxattr = generic_getxattr, 411 .getxattr = generic_getxattr,
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 575adac17f8b..5846eeb22ce5 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -496,6 +496,7 @@ const struct inode_operations f2fs_dir_inode_operations = {
496 .getattr = f2fs_getattr, 496 .getattr = f2fs_getattr,
497 .setattr = f2fs_setattr, 497 .setattr = f2fs_setattr,
498 .get_acl = f2fs_get_acl, 498 .get_acl = f2fs_get_acl,
499 .set_acl = f2fs_set_acl,
499#ifdef CONFIG_F2FS_FS_XATTR 500#ifdef CONFIG_F2FS_FS_XATTR
500 .setxattr = generic_setxattr, 501 .setxattr = generic_setxattr,
501 .getxattr = generic_getxattr, 502 .getxattr = generic_getxattr,
@@ -522,6 +523,7 @@ const struct inode_operations f2fs_special_inode_operations = {
522 .getattr = f2fs_getattr, 523 .getattr = f2fs_getattr,
523 .setattr = f2fs_setattr, 524 .setattr = f2fs_setattr,
524 .get_acl = f2fs_get_acl, 525 .get_acl = f2fs_get_acl,
526 .set_acl = f2fs_set_acl,
525#ifdef CONFIG_F2FS_FS_XATTR 527#ifdef CONFIG_F2FS_FS_XATTR
526 .setxattr = generic_setxattr, 528 .setxattr = generic_setxattr,
527 .getxattr = generic_getxattr, 529 .getxattr = generic_getxattr,
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index aa7a3f139fe5..e2b929954081 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -21,6 +21,7 @@
21#include <linux/rwsem.h> 21#include <linux/rwsem.h>
22#include <linux/f2fs_fs.h> 22#include <linux/f2fs_fs.h>
23#include <linux/security.h> 23#include <linux/security.h>
24#include <linux/posix_acl_xattr.h>
24#include "f2fs.h" 25#include "f2fs.h"
25#include "xattr.h" 26#include "xattr.h"
26 27
@@ -216,8 +217,8 @@ const struct xattr_handler f2fs_xattr_security_handler = {
216static const struct xattr_handler *f2fs_xattr_handler_map[] = { 217static const struct xattr_handler *f2fs_xattr_handler_map[] = {
217 [F2FS_XATTR_INDEX_USER] = &f2fs_xattr_user_handler, 218 [F2FS_XATTR_INDEX_USER] = &f2fs_xattr_user_handler,
218#ifdef CONFIG_F2FS_FS_POSIX_ACL 219#ifdef CONFIG_F2FS_FS_POSIX_ACL
219 [F2FS_XATTR_INDEX_POSIX_ACL_ACCESS] = &f2fs_xattr_acl_access_handler, 220 [F2FS_XATTR_INDEX_POSIX_ACL_ACCESS] = &posix_acl_access_xattr_handler,
220 [F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &f2fs_xattr_acl_default_handler, 221 [F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT] = &posix_acl_default_xattr_handler,
221#endif 222#endif
222 [F2FS_XATTR_INDEX_TRUSTED] = &f2fs_xattr_trusted_handler, 223 [F2FS_XATTR_INDEX_TRUSTED] = &f2fs_xattr_trusted_handler,
223#ifdef CONFIG_F2FS_FS_SECURITY 224#ifdef CONFIG_F2FS_FS_SECURITY
@@ -229,8 +230,8 @@ static const struct xattr_handler *f2fs_xattr_handler_map[] = {
229const struct xattr_handler *f2fs_xattr_handlers[] = { 230const struct xattr_handler *f2fs_xattr_handlers[] = {
230 &f2fs_xattr_user_handler, 231 &f2fs_xattr_user_handler,
231#ifdef CONFIG_F2FS_FS_POSIX_ACL 232#ifdef CONFIG_F2FS_FS_POSIX_ACL
232 &f2fs_xattr_acl_access_handler, 233 &posix_acl_access_xattr_handler,
233 &f2fs_xattr_acl_default_handler, 234 &posix_acl_default_xattr_handler,
234#endif 235#endif
235 &f2fs_xattr_trusted_handler, 236 &f2fs_xattr_trusted_handler,
236#ifdef CONFIG_F2FS_FS_SECURITY 237#ifdef CONFIG_F2FS_FS_SECURITY
diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h
index 02a08fb88a15..b21d9ebdeff3 100644
--- a/fs/f2fs/xattr.h
+++ b/fs/f2fs/xattr.h
@@ -108,8 +108,6 @@ struct f2fs_xattr_entry {
108#ifdef CONFIG_F2FS_FS_XATTR 108#ifdef CONFIG_F2FS_FS_XATTR
109extern const struct xattr_handler f2fs_xattr_user_handler; 109extern const struct xattr_handler f2fs_xattr_user_handler;
110extern const struct xattr_handler f2fs_xattr_trusted_handler; 110extern const struct xattr_handler f2fs_xattr_trusted_handler;
111extern const struct xattr_handler f2fs_xattr_acl_access_handler;
112extern const struct xattr_handler f2fs_xattr_acl_default_handler;
113extern const struct xattr_handler f2fs_xattr_advise_handler; 111extern const struct xattr_handler f2fs_xattr_advise_handler;
114extern const struct xattr_handler f2fs_xattr_security_handler; 112extern const struct xattr_handler f2fs_xattr_security_handler;
115 113