From 764a5c6b1fa4306dd7573c1d80914254909cd036 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Wed, 2 Dec 2015 14:44:43 +0100 Subject: 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 Signed-off-by: Al Viro --- fs/jffs2/security.c | 16 ---------------- fs/jffs2/xattr.c | 26 ++++++++++++++++---------- fs/jffs2/xattr_trusted.c | 17 ++--------------- fs/jffs2/xattr_user.c | 16 ---------------- 4 files changed, 18 insertions(+), 57 deletions(-) (limited to 'fs/jffs2') 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, name, buffer, size, flags); } -static size_t jffs2_security_listxattr(const struct xattr_handler *handler, - struct dentry *dentry, char *list, - size_t list_size, const char *name, - size_t name_len) -{ - size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1; - - if (list && retlen <= list_size) { - strcpy(list, XATTR_SECURITY_PREFIX); - strcpy(list + XATTR_SECURITY_PREFIX_LEN, name); - } - - return retlen; -} - const struct xattr_handler jffs2_security_xattr_handler = { .prefix = XATTR_SECURITY_PREFIX, - .list = jffs2_security_listxattr, .set = jffs2_security_setxattr, .get = jffs2_security_getxattr }; 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) struct jffs2_xattr_ref *ref, **pref; struct jffs2_xattr_datum *xd; const struct xattr_handler *xhandle; - ssize_t len, rc; + const char *prefix; + ssize_t prefix_len, len, rc; int retry = 0; rc = check_xattr_ref_inode(c, ic); @@ -998,18 +999,23 @@ ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size) } } xhandle = xprefix_to_handler(xd->xprefix); - if (!xhandle) + if (!xhandle || (xhandle->list && !xhandle->list(dentry))) continue; + prefix = xhandle->prefix ?: xhandle->name; + prefix_len = strlen(prefix); + rc = prefix_len + xd->name_len + 1; + if (buffer) { - rc = xhandle->list(xhandle, dentry, buffer + len, - size - len, xd->xname, - xd->name_len); - } else { - rc = xhandle->list(xhandle, dentry, NULL, 0, - xd->xname, xd->name_len); + if (rc > size - len) { + rc = -ERANGE; + goto out; + } + memcpy(buffer, prefix, prefix_len); + buffer += prefix_len; + memcpy(buffer, xd->xname, xd->name_len); + buffer += xd->name_len; + *buffer++ = 0; } - if (rc < 0) - goto out; len += rc; } 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, name, buffer, size, flags); } -static size_t jffs2_trusted_listxattr(const struct xattr_handler *handler, - struct dentry *dentry, char *list, - size_t list_size, const char *name, - size_t name_len) +static bool jffs2_trusted_listxattr(struct dentry *dentry) { - size_t retlen = XATTR_TRUSTED_PREFIX_LEN + name_len + 1; - - if (!capable(CAP_SYS_ADMIN)) - return 0; - - if (list && retlen<=list_size) { - strcpy(list, XATTR_TRUSTED_PREFIX); - strcpy(list + XATTR_TRUSTED_PREFIX_LEN, name); - } - - return retlen; + return capable(CAP_SYS_ADMIN); } const 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, name, buffer, size, flags); } -static size_t jffs2_user_listxattr(const struct xattr_handler *handler, - struct dentry *dentry, char *list, - size_t list_size, const char *name, - size_t name_len) -{ - size_t retlen = XATTR_USER_PREFIX_LEN + name_len + 1; - - if (list && retlen <= list_size) { - strcpy(list, XATTR_USER_PREFIX); - strcpy(list + XATTR_USER_PREFIX_LEN, name); - } - - return retlen; -} - const struct xattr_handler jffs2_user_xattr_handler = { .prefix = XATTR_USER_PREFIX, - .list = jffs2_user_listxattr, .set = jffs2_user_setxattr, .get = jffs2_user_getxattr }; -- cgit v1.2.3