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>
This commit is contained in:
Andreas Gruenbacher
2015-12-02 14:44:43 +01:00
committed by Al Viro
父節點 1046cb1195
當前提交 764a5c6b1f
共有 22 個文件被更改,包括 113 次插入335 次删除

查看文件

@@ -58,7 +58,7 @@ ssize_t squashfs_listxattr(struct dentry *d, char *buffer,
struct squashfs_xattr_entry entry;
struct squashfs_xattr_val val;
const struct xattr_handler *handler;
int name_size, prefix_size = 0;
int name_size;
err = squashfs_read_metadata(sb, &entry, &start, &offset,
sizeof(entry));
@@ -67,15 +67,16 @@ ssize_t squashfs_listxattr(struct dentry *d, char *buffer,
name_size = le16_to_cpu(entry.size);
handler = squashfs_xattr_handler(le16_to_cpu(entry.type));
if (handler)
prefix_size = handler->list(handler, d, buffer, rest,
NULL, name_size);
if (prefix_size) {
if (handler && (!handler->list || handler->list(d))) {
const char *prefix = handler->prefix ?: handler->name;
size_t prefix_size = strlen(prefix);
if (buffer) {
if (prefix_size + name_size + 1 > rest) {
err = -ERANGE;
goto failed;
}
memcpy(buffer, prefix, prefix_size);
buffer += prefix_size;
}
err = squashfs_read_metadata(sb, buffer, &start,
@@ -212,18 +213,6 @@ failed:
}
static size_t squashfs_xattr_handler_list(const struct xattr_handler *handler,
struct dentry *d, char *list,
size_t list_size, const char *name,
size_t name_len)
{
int len = strlen(handler->prefix);
if (list && len <= list_size)
memcpy(list, handler->prefix, len);
return len;
}
static int squashfs_xattr_handler_get(const struct xattr_handler *handler,
struct dentry *d, const char *name,
void *buffer, size_t size)
@@ -238,22 +227,15 @@ static int squashfs_xattr_handler_get(const struct xattr_handler *handler,
static const struct xattr_handler squashfs_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX,
.flags = SQUASHFS_XATTR_USER,
.list = squashfs_xattr_handler_list,
.get = squashfs_xattr_handler_get
};
/*
* Trusted namespace support
*/
static size_t squashfs_trusted_xattr_handler_list(const struct xattr_handler *handler,
struct dentry *d, char *list,
size_t list_size, const char *name,
size_t name_len)
static bool squashfs_trusted_xattr_handler_list(struct dentry *d)
{
if (!capable(CAP_SYS_ADMIN))
return 0;
return squashfs_xattr_handler_list(handler, d, list, list_size, name,
name_len);
return capable(CAP_SYS_ADMIN);
}
static const struct xattr_handler squashfs_xattr_trusted_handler = {
@@ -269,7 +251,6 @@ static const struct xattr_handler squashfs_xattr_trusted_handler = {
static const struct xattr_handler squashfs_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX,
.flags = SQUASHFS_XATTR_SECURITY,
.list = squashfs_xattr_handler_list,
.get = squashfs_xattr_handler_get
};