aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruenba@redhat.com>2015-12-02 08:44:43 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2015-12-13 19:46:12 -0500
commit764a5c6b1fa4306dd7573c1d80914254909cd036 (patch)
tree6e5ceb636c3b53cdc0994cf8c2415656e2b12e82 /fs/jffs2
parent1046cb119521b5e1881f380dc99729fc84c96661 (diff)
xattr handlers: Simplify list operation
Change the list operation to only return whether or not an attribute should be listed. Copying the attribute names into the buffer is moved to the callers. Since the result only depends on the dentry and not on the attribute name, we do not pass the attribute name to list operations. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/jffs2')
-rw-r--r--fs/jffs2/security.c16
-rw-r--r--fs/jffs2/xattr.c26
-rw-r--r--fs/jffs2/xattr_trusted.c17
-rw-r--r--fs/jffs2/xattr_user.c16
4 files changed, 18 insertions, 57 deletions
diff --git a/fs/jffs2/security.c b/fs/jffs2/security.c
index ea79932cd665..7a28facd7175 100644
--- a/fs/jffs2/security.c
+++ b/fs/jffs2/security.c
@@ -64,24 +64,8 @@ static int jffs2_security_setxattr(const struct xattr_handler *handler,
64 name, buffer, size, flags); 64 name, buffer, size, flags);
65} 65}
66 66
67static size_t jffs2_security_listxattr(const struct xattr_handler *handler,
68 struct dentry *dentry, char *list,
69 size_t list_size, const char *name,
70 size_t name_len)
71{
72 size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1;
73
74 if (list && retlen <= list_size) {
75 strcpy(list, XATTR_SECURITY_PREFIX);
76 strcpy(list + XATTR_SECURITY_PREFIX_LEN, name);
77 }
78
79 return retlen;
80}
81
82const struct xattr_handler jffs2_security_xattr_handler = { 67const struct xattr_handler jffs2_security_xattr_handler = {
83 .prefix = XATTR_SECURITY_PREFIX, 68 .prefix = XATTR_SECURITY_PREFIX,
84 .list = jffs2_security_listxattr,
85 .set = jffs2_security_setxattr, 69 .set = jffs2_security_setxattr,
86 .get = jffs2_security_getxattr 70 .get = jffs2_security_getxattr
87}; 71};
diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index 4c2c03663533..da3e18503c65 100644
--- a/fs/jffs2/xattr.c
+++ b/fs/jffs2/xattr.c
@@ -967,7 +967,8 @@ ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
967 struct jffs2_xattr_ref *ref, **pref; 967 struct jffs2_xattr_ref *ref, **pref;
968 struct jffs2_xattr_datum *xd; 968 struct jffs2_xattr_datum *xd;
969 const struct xattr_handler *xhandle; 969 const struct xattr_handler *xhandle;
970 ssize_t len, rc; 970 const char *prefix;
971 ssize_t prefix_len, len, rc;
971 int retry = 0; 972 int retry = 0;
972 973
973 rc = check_xattr_ref_inode(c, ic); 974 rc = check_xattr_ref_inode(c, ic);
@@ -998,18 +999,23 @@ ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
998 } 999 }
999 } 1000 }
1000 xhandle = xprefix_to_handler(xd->xprefix); 1001 xhandle = xprefix_to_handler(xd->xprefix);
1001 if (!xhandle) 1002 if (!xhandle || (xhandle->list && !xhandle->list(dentry)))
1002 continue; 1003 continue;
1004 prefix = xhandle->prefix ?: xhandle->name;
1005 prefix_len = strlen(prefix);
1006 rc = prefix_len + xd->name_len + 1;
1007
1003 if (buffer) { 1008 if (buffer) {
1004 rc = xhandle->list(xhandle, dentry, buffer + len, 1009 if (rc > size - len) {
1005 size - len, xd->xname, 1010 rc = -ERANGE;
1006 xd->name_len); 1011 goto out;
1007 } else { 1012 }
1008 rc = xhandle->list(xhandle, dentry, NULL, 0, 1013 memcpy(buffer, prefix, prefix_len);
1009 xd->xname, xd->name_len); 1014 buffer += prefix_len;
1015 memcpy(buffer, xd->xname, xd->name_len);
1016 buffer += xd->name_len;
1017 *buffer++ = 0;
1010 } 1018 }
1011 if (rc < 0)
1012 goto out;
1013 len += rc; 1019 len += rc;
1014 } 1020 }
1015 rc = len; 1021 rc = len;
diff --git a/fs/jffs2/xattr_trusted.c b/fs/jffs2/xattr_trusted.c
index 8b55fe44c777..b2555ef07a12 100644
--- a/fs/jffs2/xattr_trusted.c
+++ b/fs/jffs2/xattr_trusted.c
@@ -32,22 +32,9 @@ static int jffs2_trusted_setxattr(const struct xattr_handler *handler,
32 name, buffer, size, flags); 32 name, buffer, size, flags);
33} 33}
34 34
35static size_t jffs2_trusted_listxattr(const struct xattr_handler *handler, 35static bool jffs2_trusted_listxattr(struct dentry *dentry)
36 struct dentry *dentry, char *list,
37 size_t list_size, const char *name,
38 size_t name_len)
39{ 36{
40 size_t retlen = XATTR_TRUSTED_PREFIX_LEN + name_len + 1; 37 return capable(CAP_SYS_ADMIN);
41
42 if (!capable(CAP_SYS_ADMIN))
43 return 0;
44
45 if (list && retlen<=list_size) {
46 strcpy(list, XATTR_TRUSTED_PREFIX);
47 strcpy(list + XATTR_TRUSTED_PREFIX_LEN, name);
48 }
49
50 return retlen;
51} 38}
52 39
53const struct xattr_handler jffs2_trusted_xattr_handler = { 40const struct xattr_handler jffs2_trusted_xattr_handler = {
diff --git a/fs/jffs2/xattr_user.c b/fs/jffs2/xattr_user.c
index b04335b84833..539bd630b5e4 100644
--- a/fs/jffs2/xattr_user.c
+++ b/fs/jffs2/xattr_user.c
@@ -32,24 +32,8 @@ static int jffs2_user_setxattr(const struct xattr_handler *handler,
32 name, buffer, size, flags); 32 name, buffer, size, flags);
33} 33}
34 34
35static size_t jffs2_user_listxattr(const struct xattr_handler *handler,
36 struct dentry *dentry, char *list,
37 size_t list_size, const char *name,
38 size_t name_len)
39{
40 size_t retlen = XATTR_USER_PREFIX_LEN + name_len + 1;
41
42 if (list && retlen <= list_size) {
43 strcpy(list, XATTR_USER_PREFIX);
44 strcpy(list + XATTR_USER_PREFIX_LEN, name);
45 }
46
47 return retlen;
48}
49
50const struct xattr_handler jffs2_user_xattr_handler = { 35const struct xattr_handler jffs2_user_xattr_handler = {
51 .prefix = XATTR_USER_PREFIX, 36 .prefix = XATTR_USER_PREFIX,
52 .list = jffs2_user_listxattr,
53 .set = jffs2_user_setxattr, 37 .set = jffs2_user_setxattr,
54 .get = jffs2_user_getxattr 38 .get = jffs2_user_getxattr
55}; 39};