diff options
author | Christoph Hellwig <hch@lst.de> | 2009-11-13 04:52:56 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2009-12-16 12:16:49 -0500 |
commit | 431547b3c4533b8c7fd150ab36980b9a3147797b (patch) | |
tree | 807ff2790f3c13c7c91ed2afd6d833032899482d /fs/ocfs2 | |
parent | ef26ca97e83052790940cbc444b01b0d17a813c1 (diff) |
sanitize xattr handler prototypes
Add a flags argument to struct xattr_handler and pass it to all xattr
handler methods. This allows using the same methods for multiple
handlers, e.g. for the ACL methods which perform exactly the same action
for the access and default ACLs, just using a different underlying
attribute. With a little more groundwork it'll also allow sharing the
methods for the regular user/trusted/secure handlers in extN, ocfs2 and
jffs2 like it's already done for xfs in this patch.
Also change the inode argument to the handlers to a dentry to allow
using the handlers mechnism for filesystems that require it later,
e.g. cifs.
[with GFS2 bits updated by Steven Whitehouse <swhiteho@redhat.com>]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: James Morris <jmorris@namei.org>
Acked-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/ocfs2')
-rw-r--r-- | fs/ocfs2/acl.c | 87 | ||||
-rw-r--r-- | fs/ocfs2/xattr.c | 72 |
2 files changed, 60 insertions, 99 deletions
diff --git a/fs/ocfs2/acl.c b/fs/ocfs2/acl.c index fbeaec762103..e3e47415d851 100644 --- a/fs/ocfs2/acl.c +++ b/fs/ocfs2/acl.c | |||
@@ -331,13 +331,14 @@ cleanup: | |||
331 | return ret; | 331 | return ret; |
332 | } | 332 | } |
333 | 333 | ||
334 | static size_t ocfs2_xattr_list_acl_access(struct inode *inode, | 334 | static size_t ocfs2_xattr_list_acl_access(struct dentry *dentry, |
335 | char *list, | 335 | char *list, |
336 | size_t list_len, | 336 | size_t list_len, |
337 | const char *name, | 337 | const char *name, |
338 | size_t name_len) | 338 | size_t name_len, |
339 | int type) | ||
339 | { | 340 | { |
340 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 341 | struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); |
341 | const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); | 342 | const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); |
342 | 343 | ||
343 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) | 344 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) |
@@ -348,13 +349,14 @@ static size_t ocfs2_xattr_list_acl_access(struct inode *inode, | |||
348 | return size; | 349 | return size; |
349 | } | 350 | } |
350 | 351 | ||
351 | static size_t ocfs2_xattr_list_acl_default(struct inode *inode, | 352 | static size_t ocfs2_xattr_list_acl_default(struct dentry *dentry, |
352 | char *list, | 353 | char *list, |
353 | size_t list_len, | 354 | size_t list_len, |
354 | const char *name, | 355 | const char *name, |
355 | size_t name_len) | 356 | size_t name_len, |
357 | int type) | ||
356 | { | 358 | { |
357 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 359 | struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); |
358 | const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); | 360 | const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); |
359 | 361 | ||
360 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) | 362 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) |
@@ -365,19 +367,19 @@ static size_t ocfs2_xattr_list_acl_default(struct inode *inode, | |||
365 | return size; | 367 | return size; |
366 | } | 368 | } |
367 | 369 | ||
368 | static int ocfs2_xattr_get_acl(struct inode *inode, | 370 | static int ocfs2_xattr_get_acl(struct dentry *dentry, const char *name, |
369 | int type, | 371 | void *buffer, size_t size, int type) |
370 | void *buffer, | ||
371 | size_t size) | ||
372 | { | 372 | { |
373 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 373 | struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); |
374 | struct posix_acl *acl; | 374 | struct posix_acl *acl; |
375 | int ret; | 375 | int ret; |
376 | 376 | ||
377 | if (strcmp(name, "") != 0) | ||
378 | return -EINVAL; | ||
377 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) | 379 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) |
378 | return -EOPNOTSUPP; | 380 | return -EOPNOTSUPP; |
379 | 381 | ||
380 | acl = ocfs2_get_acl(inode, type); | 382 | acl = ocfs2_get_acl(dentry->d_inode, type); |
381 | if (IS_ERR(acl)) | 383 | if (IS_ERR(acl)) |
382 | return PTR_ERR(acl); | 384 | return PTR_ERR(acl); |
383 | if (acl == NULL) | 385 | if (acl == NULL) |
@@ -388,35 +390,16 @@ static int ocfs2_xattr_get_acl(struct inode *inode, | |||
388 | return ret; | 390 | return ret; |
389 | } | 391 | } |
390 | 392 | ||
391 | static int ocfs2_xattr_get_acl_access(struct inode *inode, | 393 | static int ocfs2_xattr_set_acl(struct dentry *dentry, const char *name, |
392 | const char *name, | 394 | const void *value, size_t size, int flags, int type) |
393 | void *buffer, | ||
394 | size_t size) | ||
395 | { | ||
396 | if (strcmp(name, "") != 0) | ||
397 | return -EINVAL; | ||
398 | return ocfs2_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); | ||
399 | } | ||
400 | |||
401 | static int ocfs2_xattr_get_acl_default(struct inode *inode, | ||
402 | const char *name, | ||
403 | void *buffer, | ||
404 | size_t size) | ||
405 | { | ||
406 | if (strcmp(name, "") != 0) | ||
407 | return -EINVAL; | ||
408 | return ocfs2_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); | ||
409 | } | ||
410 | |||
411 | static int ocfs2_xattr_set_acl(struct inode *inode, | ||
412 | int type, | ||
413 | const void *value, | ||
414 | size_t size) | ||
415 | { | 395 | { |
396 | struct inode *inode = dentry->d_inode; | ||
416 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 397 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
417 | struct posix_acl *acl; | 398 | struct posix_acl *acl; |
418 | int ret = 0; | 399 | int ret = 0; |
419 | 400 | ||
401 | if (strcmp(name, "") != 0) | ||
402 | return -EINVAL; | ||
420 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) | 403 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) |
421 | return -EOPNOTSUPP; | 404 | return -EOPNOTSUPP; |
422 | 405 | ||
@@ -442,38 +425,18 @@ cleanup: | |||
442 | return ret; | 425 | return ret; |
443 | } | 426 | } |
444 | 427 | ||
445 | static int ocfs2_xattr_set_acl_access(struct inode *inode, | ||
446 | const char *name, | ||
447 | const void *value, | ||
448 | size_t size, | ||
449 | int flags) | ||
450 | { | ||
451 | if (strcmp(name, "") != 0) | ||
452 | return -EINVAL; | ||
453 | return ocfs2_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); | ||
454 | } | ||
455 | |||
456 | static int ocfs2_xattr_set_acl_default(struct inode *inode, | ||
457 | const char *name, | ||
458 | const void *value, | ||
459 | size_t size, | ||
460 | int flags) | ||
461 | { | ||
462 | if (strcmp(name, "") != 0) | ||
463 | return -EINVAL; | ||
464 | return ocfs2_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); | ||
465 | } | ||
466 | |||
467 | struct xattr_handler ocfs2_xattr_acl_access_handler = { | 428 | struct xattr_handler ocfs2_xattr_acl_access_handler = { |
468 | .prefix = POSIX_ACL_XATTR_ACCESS, | 429 | .prefix = POSIX_ACL_XATTR_ACCESS, |
430 | .flags = ACL_TYPE_ACCESS, | ||
469 | .list = ocfs2_xattr_list_acl_access, | 431 | .list = ocfs2_xattr_list_acl_access, |
470 | .get = ocfs2_xattr_get_acl_access, | 432 | .get = ocfs2_xattr_get_acl, |
471 | .set = ocfs2_xattr_set_acl_access, | 433 | .set = ocfs2_xattr_set_acl, |
472 | }; | 434 | }; |
473 | 435 | ||
474 | struct xattr_handler ocfs2_xattr_acl_default_handler = { | 436 | struct xattr_handler ocfs2_xattr_acl_default_handler = { |
475 | .prefix = POSIX_ACL_XATTR_DEFAULT, | 437 | .prefix = POSIX_ACL_XATTR_DEFAULT, |
438 | .flags = ACL_TYPE_DEFAULT, | ||
476 | .list = ocfs2_xattr_list_acl_default, | 439 | .list = ocfs2_xattr_list_acl_default, |
477 | .get = ocfs2_xattr_get_acl_default, | 440 | .get = ocfs2_xattr_get_acl, |
478 | .set = ocfs2_xattr_set_acl_default, | 441 | .set = ocfs2_xattr_set_acl, |
479 | }; | 442 | }; |
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index fe3419068df2..43c114831c0d 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c | |||
@@ -205,8 +205,6 @@ static int ocfs2_get_xattr_tree_value_root(struct super_block *sb, | |||
205 | int offset, | 205 | int offset, |
206 | struct ocfs2_xattr_value_root **xv, | 206 | struct ocfs2_xattr_value_root **xv, |
207 | struct buffer_head **bh); | 207 | struct buffer_head **bh); |
208 | static int ocfs2_xattr_security_set(struct inode *inode, const char *name, | ||
209 | const void *value, size_t size, int flags); | ||
210 | 208 | ||
211 | static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb) | 209 | static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb) |
212 | { | 210 | { |
@@ -6978,9 +6976,9 @@ int ocfs2_init_security_and_acl(struct inode *dir, | |||
6978 | 6976 | ||
6979 | ret = ocfs2_init_security_get(inode, dir, &si); | 6977 | ret = ocfs2_init_security_get(inode, dir, &si); |
6980 | if (!ret) { | 6978 | if (!ret) { |
6981 | ret = ocfs2_xattr_security_set(inode, si.name, | 6979 | ret = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, |
6982 | si.value, si.value_len, | 6980 | si.name, si.value, si.value_len, |
6983 | XATTR_CREATE); | 6981 | XATTR_CREATE); |
6984 | if (ret) { | 6982 | if (ret) { |
6985 | mlog_errno(ret); | 6983 | mlog_errno(ret); |
6986 | goto leave; | 6984 | goto leave; |
@@ -7008,9 +7006,9 @@ leave: | |||
7008 | /* | 7006 | /* |
7009 | * 'security' attributes support | 7007 | * 'security' attributes support |
7010 | */ | 7008 | */ |
7011 | static size_t ocfs2_xattr_security_list(struct inode *inode, char *list, | 7009 | static size_t ocfs2_xattr_security_list(struct dentry *dentry, char *list, |
7012 | size_t list_size, const char *name, | 7010 | size_t list_size, const char *name, |
7013 | size_t name_len) | 7011 | size_t name_len, int type) |
7014 | { | 7012 | { |
7015 | const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; | 7013 | const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; |
7016 | const size_t total_len = prefix_len + name_len + 1; | 7014 | const size_t total_len = prefix_len + name_len + 1; |
@@ -7023,23 +7021,23 @@ static size_t ocfs2_xattr_security_list(struct inode *inode, char *list, | |||
7023 | return total_len; | 7021 | return total_len; |
7024 | } | 7022 | } |
7025 | 7023 | ||
7026 | static int ocfs2_xattr_security_get(struct inode *inode, const char *name, | 7024 | static int ocfs2_xattr_security_get(struct dentry *dentry, const char *name, |
7027 | void *buffer, size_t size) | 7025 | void *buffer, size_t size, int type) |
7028 | { | 7026 | { |
7029 | if (strcmp(name, "") == 0) | 7027 | if (strcmp(name, "") == 0) |
7030 | return -EINVAL; | 7028 | return -EINVAL; |
7031 | return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_SECURITY, name, | 7029 | return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_SECURITY, |
7032 | buffer, size); | 7030 | name, buffer, size); |
7033 | } | 7031 | } |
7034 | 7032 | ||
7035 | static int ocfs2_xattr_security_set(struct inode *inode, const char *name, | 7033 | static int ocfs2_xattr_security_set(struct dentry *dentry, const char *name, |
7036 | const void *value, size_t size, int flags) | 7034 | const void *value, size_t size, int flags, int type) |
7037 | { | 7035 | { |
7038 | if (strcmp(name, "") == 0) | 7036 | if (strcmp(name, "") == 0) |
7039 | return -EINVAL; | 7037 | return -EINVAL; |
7040 | 7038 | ||
7041 | return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, name, value, | 7039 | return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_SECURITY, |
7042 | size, flags); | 7040 | name, value, size, flags); |
7043 | } | 7041 | } |
7044 | 7042 | ||
7045 | int ocfs2_init_security_get(struct inode *inode, | 7043 | int ocfs2_init_security_get(struct inode *inode, |
@@ -7076,9 +7074,9 @@ struct xattr_handler ocfs2_xattr_security_handler = { | |||
7076 | /* | 7074 | /* |
7077 | * 'trusted' attributes support | 7075 | * 'trusted' attributes support |
7078 | */ | 7076 | */ |
7079 | static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list, | 7077 | static size_t ocfs2_xattr_trusted_list(struct dentry *dentry, char *list, |
7080 | size_t list_size, const char *name, | 7078 | size_t list_size, const char *name, |
7081 | size_t name_len) | 7079 | size_t name_len, int type) |
7082 | { | 7080 | { |
7083 | const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; | 7081 | const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; |
7084 | const size_t total_len = prefix_len + name_len + 1; | 7082 | const size_t total_len = prefix_len + name_len + 1; |
@@ -7091,23 +7089,23 @@ static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list, | |||
7091 | return total_len; | 7089 | return total_len; |
7092 | } | 7090 | } |
7093 | 7091 | ||
7094 | static int ocfs2_xattr_trusted_get(struct inode *inode, const char *name, | 7092 | static int ocfs2_xattr_trusted_get(struct dentry *dentry, const char *name, |
7095 | void *buffer, size_t size) | 7093 | void *buffer, size_t size, int type) |
7096 | { | 7094 | { |
7097 | if (strcmp(name, "") == 0) | 7095 | if (strcmp(name, "") == 0) |
7098 | return -EINVAL; | 7096 | return -EINVAL; |
7099 | return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_TRUSTED, name, | 7097 | return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_TRUSTED, |
7100 | buffer, size); | 7098 | name, buffer, size); |
7101 | } | 7099 | } |
7102 | 7100 | ||
7103 | static int ocfs2_xattr_trusted_set(struct inode *inode, const char *name, | 7101 | static int ocfs2_xattr_trusted_set(struct dentry *dentry, const char *name, |
7104 | const void *value, size_t size, int flags) | 7102 | const void *value, size_t size, int flags, int type) |
7105 | { | 7103 | { |
7106 | if (strcmp(name, "") == 0) | 7104 | if (strcmp(name, "") == 0) |
7107 | return -EINVAL; | 7105 | return -EINVAL; |
7108 | 7106 | ||
7109 | return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_TRUSTED, name, value, | 7107 | return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_TRUSTED, |
7110 | size, flags); | 7108 | name, value, size, flags); |
7111 | } | 7109 | } |
7112 | 7110 | ||
7113 | struct xattr_handler ocfs2_xattr_trusted_handler = { | 7111 | struct xattr_handler ocfs2_xattr_trusted_handler = { |
@@ -7120,13 +7118,13 @@ struct xattr_handler ocfs2_xattr_trusted_handler = { | |||
7120 | /* | 7118 | /* |
7121 | * 'user' attributes support | 7119 | * 'user' attributes support |
7122 | */ | 7120 | */ |
7123 | static size_t ocfs2_xattr_user_list(struct inode *inode, char *list, | 7121 | static size_t ocfs2_xattr_user_list(struct dentry *dentry, char *list, |
7124 | size_t list_size, const char *name, | 7122 | size_t list_size, const char *name, |
7125 | size_t name_len) | 7123 | size_t name_len, int type) |
7126 | { | 7124 | { |
7127 | const size_t prefix_len = XATTR_USER_PREFIX_LEN; | 7125 | const size_t prefix_len = XATTR_USER_PREFIX_LEN; |
7128 | const size_t total_len = prefix_len + name_len + 1; | 7126 | const size_t total_len = prefix_len + name_len + 1; |
7129 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 7127 | struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); |
7130 | 7128 | ||
7131 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | 7129 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) |
7132 | return 0; | 7130 | return 0; |
@@ -7139,31 +7137,31 @@ static size_t ocfs2_xattr_user_list(struct inode *inode, char *list, | |||
7139 | return total_len; | 7137 | return total_len; |
7140 | } | 7138 | } |
7141 | 7139 | ||
7142 | static int ocfs2_xattr_user_get(struct inode *inode, const char *name, | 7140 | static int ocfs2_xattr_user_get(struct dentry *dentry, const char *name, |
7143 | void *buffer, size_t size) | 7141 | void *buffer, size_t size, int type) |
7144 | { | 7142 | { |
7145 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 7143 | struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); |
7146 | 7144 | ||
7147 | if (strcmp(name, "") == 0) | 7145 | if (strcmp(name, "") == 0) |
7148 | return -EINVAL; | 7146 | return -EINVAL; |
7149 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | 7147 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) |
7150 | return -EOPNOTSUPP; | 7148 | return -EOPNOTSUPP; |
7151 | return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_USER, name, | 7149 | return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_USER, name, |
7152 | buffer, size); | 7150 | buffer, size); |
7153 | } | 7151 | } |
7154 | 7152 | ||
7155 | static int ocfs2_xattr_user_set(struct inode *inode, const char *name, | 7153 | static int ocfs2_xattr_user_set(struct dentry *dentry, const char *name, |
7156 | const void *value, size_t size, int flags) | 7154 | const void *value, size_t size, int flags, int type) |
7157 | { | 7155 | { |
7158 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 7156 | struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); |
7159 | 7157 | ||
7160 | if (strcmp(name, "") == 0) | 7158 | if (strcmp(name, "") == 0) |
7161 | return -EINVAL; | 7159 | return -EINVAL; |
7162 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | 7160 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) |
7163 | return -EOPNOTSUPP; | 7161 | return -EOPNOTSUPP; |
7164 | 7162 | ||
7165 | return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_USER, name, value, | 7163 | return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_USER, |
7166 | size, flags); | 7164 | name, value, size, flags); |
7167 | } | 7165 | } |
7168 | 7166 | ||
7169 | struct xattr_handler ocfs2_xattr_user_handler = { | 7167 | struct xattr_handler ocfs2_xattr_user_handler = { |