Commit 5d2eb548 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus-3' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull vfs xattr cleanups from Al Viro.

* 'for-linus-3' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  f2fs: xattr simplifications
  squashfs: xattr simplifications
  9p: xattr simplifications
  xattr handlers: Pass handler to operations instead of flags
  jffs2: Add missing capability check for listing trusted xattrs
  hfsplus: Remove unused xattr handler list operations
  ubifs: Remove unused security xattr handler
  vfs: Fix the posix_acl_xattr_list return value
  vfs: Check attribute names in posix acl xattr handers
parents 2870f6c4 29608d20
...@@ -10,10 +10,7 @@ obj-$(CONFIG_9P_FS) := 9p.o ...@@ -10,10 +10,7 @@ obj-$(CONFIG_9P_FS) := 9p.o
vfs_dentry.o \ vfs_dentry.o \
v9fs.o \ v9fs.o \
fid.o \ fid.o \
xattr.o \ xattr.o
xattr_user.o \
xattr_trusted.o
9p-$(CONFIG_9P_FSCACHE) += cache.o 9p-$(CONFIG_9P_FSCACHE) += cache.o
9p-$(CONFIG_9P_FS_POSIX_ACL) += acl.o 9p-$(CONFIG_9P_FS_POSIX_ACL) += acl.o
9p-$(CONFIG_9P_FS_SECURITY) += xattr_security.o
...@@ -212,26 +212,9 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep, ...@@ -212,26 +212,9 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep,
return 0; return 0;
} }
static int v9fs_remote_get_acl(struct dentry *dentry, const char *name, static int v9fs_xattr_get_acl(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
{ void *buffer, size_t size)
char *full_name;
switch (type) {
case ACL_TYPE_ACCESS:
full_name = POSIX_ACL_XATTR_ACCESS;
break;
case ACL_TYPE_DEFAULT:
full_name = POSIX_ACL_XATTR_DEFAULT;
break;
default:
BUG();
}
return v9fs_xattr_get(dentry, full_name, buffer, size);
}
static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
void *buffer, size_t size, int type)
{ {
struct v9fs_session_info *v9ses; struct v9fs_session_info *v9ses;
struct posix_acl *acl; struct posix_acl *acl;
...@@ -245,9 +228,9 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name, ...@@ -245,9 +228,9 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
* We allow set/get/list of acl when access=client is not specified * We allow set/get/list of acl when access=client is not specified
*/ */
if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
return v9fs_remote_get_acl(dentry, name, buffer, size, type); return v9fs_xattr_get(dentry, handler->prefix, buffer, size);
acl = v9fs_get_cached_acl(d_inode(dentry), type); acl = v9fs_get_cached_acl(d_inode(dentry), handler->flags);
if (IS_ERR(acl)) if (IS_ERR(acl))
return PTR_ERR(acl); return PTR_ERR(acl);
if (acl == NULL) if (acl == NULL)
...@@ -258,29 +241,9 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name, ...@@ -258,29 +241,9 @@ static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name,
return error; return error;
} }
static int v9fs_remote_set_acl(struct dentry *dentry, const char *name, static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
const void *value, size_t size, struct dentry *dentry, const char *name,
int flags, int type) const void *value, size_t size, int flags)
{
char *full_name;
switch (type) {
case ACL_TYPE_ACCESS:
full_name = POSIX_ACL_XATTR_ACCESS;
break;
case ACL_TYPE_DEFAULT:
full_name = POSIX_ACL_XATTR_DEFAULT;
break;
default:
BUG();
}
return v9fs_xattr_set(dentry, full_name, value, size, flags);
}
static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
const void *value, size_t size,
int flags, int type)
{ {
int retval; int retval;
struct posix_acl *acl; struct posix_acl *acl;
...@@ -296,8 +259,8 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, ...@@ -296,8 +259,8 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
* xattr value. We leave it to the server to validate * xattr value. We leave it to the server to validate
*/ */
if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
return v9fs_remote_set_acl(dentry, name, return v9fs_xattr_set(dentry, handler->prefix, value, size,
value, size, flags, type); flags);
if (S_ISLNK(inode->i_mode)) if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -316,9 +279,8 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, ...@@ -316,9 +279,8 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
} else } else
acl = NULL; acl = NULL;
switch (type) { switch (handler->flags) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
name = POSIX_ACL_XATTR_ACCESS;
if (acl) { if (acl) {
umode_t mode = inode->i_mode; umode_t mode = inode->i_mode;
retval = posix_acl_equiv_mode(acl, &mode); retval = posix_acl_equiv_mode(acl, &mode);
...@@ -349,7 +311,6 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, ...@@ -349,7 +311,6 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
} }
break; break;
case ACL_TYPE_DEFAULT: case ACL_TYPE_DEFAULT:
name = POSIX_ACL_XATTR_DEFAULT;
if (!S_ISDIR(inode->i_mode)) { if (!S_ISDIR(inode->i_mode)) {
retval = acl ? -EINVAL : 0; retval = acl ? -EINVAL : 0;
goto err_out; goto err_out;
...@@ -358,9 +319,9 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, ...@@ -358,9 +319,9 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
default: default:
BUG(); BUG();
} }
retval = v9fs_xattr_set(dentry, name, value, size, flags); retval = v9fs_xattr_set(dentry, handler->prefix, value, size, flags);
if (!retval) if (!retval)
set_cached_acl(inode, type, acl); set_cached_acl(inode, handler->flags, acl);
err_out: err_out:
posix_acl_release(acl); posix_acl_release(acl);
return retval; return retval;
......
...@@ -137,6 +137,48 @@ ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) ...@@ -137,6 +137,48 @@ ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
return v9fs_xattr_get(dentry, NULL, buffer, buffer_size); return v9fs_xattr_get(dentry, NULL, buffer, buffer_size);
} }
static int v9fs_xattr_handler_get(const struct xattr_handler *handler,
struct dentry *dentry, const char *name,
void *buffer, size_t size)
{
const char *full_name = xattr_full_name(handler, name);
if (strcmp(name, "") == 0)
return -EINVAL;
return v9fs_xattr_get(dentry, full_name, buffer, size);
}
static int v9fs_xattr_handler_set(const struct xattr_handler *handler,
struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{
const char *full_name = xattr_full_name(handler, name);
if (strcmp(name, "") == 0)
return -EINVAL;
return v9fs_xattr_set(dentry, full_name, value, size, flags);
}
static struct xattr_handler v9fs_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX,
.get = v9fs_xattr_handler_get,
.set = v9fs_xattr_handler_set,
};
static struct xattr_handler v9fs_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX,
.get = v9fs_xattr_handler_get,
.set = v9fs_xattr_handler_set,
};
#ifdef CONFIG_9P_FS_SECURITY
static struct xattr_handler v9fs_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX,
.get = v9fs_xattr_handler_get,
.set = v9fs_xattr_handler_set,
};
#endif
const struct xattr_handler *v9fs_xattr_handlers[] = { const struct xattr_handler *v9fs_xattr_handlers[] = {
&v9fs_xattr_user_handler, &v9fs_xattr_user_handler,
&v9fs_xattr_trusted_handler, &v9fs_xattr_trusted_handler,
......
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
#include <net/9p/client.h> #include <net/9p/client.h>
extern const struct xattr_handler *v9fs_xattr_handlers[]; extern const struct xattr_handler *v9fs_xattr_handlers[];
extern struct xattr_handler v9fs_xattr_user_handler;
extern struct xattr_handler v9fs_xattr_trusted_handler;
extern struct xattr_handler v9fs_xattr_security_handler;
extern const struct xattr_handler v9fs_xattr_acl_access_handler; extern const struct xattr_handler v9fs_xattr_acl_access_handler;
extern const struct xattr_handler v9fs_xattr_acl_default_handler; extern const struct xattr_handler v9fs_xattr_acl_default_handler;
......
/*
* Copyright IBM Corporation, 2010
* Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include <linux/module.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include "xattr.h"
static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
void *buffer, size_t size, int type)
{
int retval;
char *full_name;
size_t name_len;
size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
if (name == NULL)
return -EINVAL;
if (strcmp(name, "") == 0)
return -EINVAL;
name_len = strlen(name);
full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
if (!full_name)
return -ENOMEM;
memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
memcpy(full_name+prefix_len, name, name_len);
full_name[prefix_len + name_len] = '\0';
retval = v9fs_xattr_get(dentry, full_name, buffer, size);
kfree(full_name);
return retval;
}
static int v9fs_xattr_security_set(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags, int type)
{
int retval;
char *full_name;
size_t name_len;
size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
if (name == NULL)
return -EINVAL;
if (strcmp(name, "") == 0)
return -EINVAL;
name_len = strlen(name);
full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
if (!full_name)
return -ENOMEM;
memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
memcpy(full_name + prefix_len, name, name_len);
full_name[prefix_len + name_len] = '\0';
retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
kfree(full_name);
return retval;
}
struct xattr_handler v9fs_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX,
.get = v9fs_xattr_security_get,
.set = v9fs_xattr_security_set,
};
/*
* Copyright IBM Corporation, 2010
* Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include <linux/module.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include "xattr.h"
static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name,
void *buffer, size_t size, int type)
{
int retval;
char *full_name;
size_t name_len;
size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
if (name == NULL)
return -EINVAL;
if (strcmp(name, "") == 0)
return -EINVAL;
name_len = strlen(name);
full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
if (!full_name)
return -ENOMEM;
memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len);
memcpy(full_name+prefix_len, name, name_len);
full_name[prefix_len + name_len] = '\0';
retval = v9fs_xattr_get(dentry, full_name, buffer, size);
kfree(full_name);
return retval;
}
static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags, int type)
{
int retval;
char *full_name;
size_t name_len;
size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
if (name == NULL)
return -EINVAL;
if (strcmp(name, "") == 0)
return -EINVAL;
name_len = strlen(name);
full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
if (!full_name)
return -ENOMEM;
memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len);
memcpy(full_name + prefix_len, name, name_len);
full_name[prefix_len + name_len] = '\0';
retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
kfree(full_name);
return retval;
}
struct xattr_handler v9fs_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX,
.get = v9fs_xattr_trusted_get,
.set = v9fs_xattr_trusted_set,
};
/*
* Copyright IBM Corporation, 2010
* Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2.1 of the GNU Lesser General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include <linux/module.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include "xattr.h"
static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
void *buffer, size_t size, int type)
{
int retval;
char *full_name;
size_t name_len;
size_t prefix_len = XATTR_USER_PREFIX_LEN;
if (name == NULL)
return -EINVAL;
if (strcmp(name, "") == 0)
return -EINVAL;
name_len = strlen(name);
full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
if (!full_name)
return -ENOMEM;
memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
memcpy(full_name+prefix_len, name, name_len);
full_name[prefix_len + name_len] = '\0';
retval = v9fs_xattr_get(dentry, full_name, buffer, size);
kfree(full_name);
return retval;
}
static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
const void *value, size_t size, int flags, int type)
{
int retval;
char *full_name;
size_t name_len;
size_t prefix_len = XATTR_USER_PREFIX_LEN;
if (name == NULL)
return -EINVAL;
if (strcmp(name, "") == 0)
return -EINVAL;
name_len = strlen(name);
full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
if (!full_name)
return -ENOMEM;
memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
memcpy(full_name + prefix_len, name, name_len);
full_name[prefix_len + name_len] = '\0';
retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
kfree(full_name);
return retval;
}
struct xattr_handler v9fs_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX,
.get = v9fs_xattr_user_get,
.set = v9fs_xattr_user_set,
};
...@@ -293,10 +293,9 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list", ...@@ -293,10 +293,9 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
ext2_xattr_handler(entry->e_name_index); ext2_xattr_handler(entry->e_name_index);
if (handler) { if (handler) {
size_t size = handler->list(dentry, buffer, rest, size_t size = handler->list(handler, dentry, buffer,
entry->e_name, rest, entry->e_name,
entry->e_name_len, entry->e_name_len);
handler->flags);
if (buffer) { if (buffer) {
if (size > rest) { if (size > rest) {
error = -ERANGE; error = -ERANGE;
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#include "xattr.h" #include "xattr.h"
static size_t static size_t
ext2_xattr_security_list(struct dentry *dentry, char *list, size_t list_size, ext2_xattr_security_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const int prefix_len = XATTR_SECURITY_PREFIX_LEN; const int prefix_len = XATTR_SECURITY_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -23,8 +24,9 @@ ext2_xattr_security_list(struct dentry *dentry, char *list, size_t list_size, ...@@ -23,8 +24,9 @@ ext2_xattr_security_list(struct dentry *dentry, char *list, size_t list_size,
} }
static int static int
ext2_xattr_security_get(struct dentry *dentry, const char *name, ext2_xattr_security_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -33,8 +35,9 @@ ext2_xattr_security_get(struct dentry *dentry, const char *name, ...@@ -33,8 +35,9 @@ ext2_xattr_security_get(struct dentry *dentry, const char *name,
} }
static int static int
ext2_xattr_security_set(struct dentry *dentry, const char *name, ext2_xattr_security_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
#include "xattr.h" #include "xattr.h"
static size_t static size_t
ext2_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, ext2_xattr_trusted_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const int prefix_len = XATTR_TRUSTED_PREFIX_LEN; const int prefix_len = XATTR_TRUSTED_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -27,8 +28,9 @@ ext2_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, ...@@ -27,8 +28,9 @@ ext2_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size,
} }
static int static int
ext2_xattr_trusted_get(struct dentry *dentry, const char *name, ext2_xattr_trusted_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -37,8 +39,9 @@ ext2_xattr_trusted_get(struct dentry *dentry, const char *name, ...@@ -37,8 +39,9 @@ ext2_xattr_trusted_get(struct dentry *dentry, const char *name,
} }
static int static int
ext2_xattr_trusted_set(struct dentry *dentry, const char *name, ext2_xattr_trusted_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
......
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
#include "xattr.h" #include "xattr.h"
static size_t static size_t
ext2_xattr_user_list(struct dentry *dentry, char *list, size_t list_size, ext2_xattr_user_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const size_t prefix_len = XATTR_USER_PREFIX_LEN; const size_t prefix_len = XATTR_USER_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -29,8 +30,9 @@ ext2_xattr_user_list(struct dentry *dentry, char *list, size_t list_size, ...@@ -29,8 +30,9 @@ ext2_xattr_user_list(struct dentry *dentry, char *list, size_t list_size,
} }
static int static int
ext2_xattr_user_get(struct dentry *dentry, const char *name, ext2_xattr_user_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -41,8 +43,9 @@ ext2_xattr_user_get(struct dentry *dentry, const char *name, ...@@ -41,8 +43,9 @@ ext2_xattr_user_get(struct dentry *dentry, const char *name,
} }
static int static int
ext2_xattr_user_set(struct dentry *dentry, const char *name, ext2_xattr_user_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
......
...@@ -405,10 +405,9 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry, ...@@ -405,10 +405,9 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
ext4_xattr_handler(entry->e_name_index); ext4_xattr_handler(entry->e_name_index);
if (handler) { if (handler) {
size_t size = handler->list(dentry, buffer, rest, size_t size = handler->list(handler, dentry, buffer,
entry->e_name, rest, entry->e_name,
entry->e_name_len, entry->e_name_len);
handler->flags);
if (buffer) { if (buffer) {
if (size > rest) if (size > rest)
return -ERANGE; return -ERANGE;
......
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
#include "xattr.h" #include "xattr.h"
static size_t static size_t
ext4_xattr_security_list(struct dentry *dentry, char *list, size_t list_size, ext4_xattr_security_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1; const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -28,8 +29,9 @@ ext4_xattr_security_list(struct dentry *dentry, char *list, size_t list_size, ...@@ -28,8 +29,9 @@ ext4_xattr_security_list(struct dentry *dentry, char *list, size_t list_size,
} }
static int static int
ext4_xattr_security_get(struct dentry *dentry, const char *name, ext4_xattr_security_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -38,8 +40,9 @@ ext4_xattr_security_get(struct dentry *dentry, const char *name, ...@@ -38,8 +40,9 @@ ext4_xattr_security_get(struct dentry *dentry, const char *name,
} }
static int static int
ext4_xattr_security_set(struct dentry *dentry, const char *name, ext4_xattr_security_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
......
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
#include "xattr.h" #include "xattr.h"
static size_t static size_t
ext4_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, ext4_xattr_trusted_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -31,8 +32,9 @@ ext4_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, ...@@ -31,8 +32,9 @@ ext4_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size,
} }
static int static int
ext4_xattr_trusted_get(struct dentry *dentry, const char *name, void *buffer, ext4_xattr_trusted_get(const struct xattr_handler *handler,
size_t size, int type) struct dentry *dentry, const char *name, void *buffer,
size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -41,8 +43,9 @@ ext4_xattr_trusted_get(struct dentry *dentry, const char *name, void *buffer, ...@@ -41,8 +43,9 @@ ext4_xattr_trusted_get(struct dentry *dentry, const char *name, void *buffer,
} }
static int static int
ext4_xattr_trusted_set(struct dentry *dentry, const char *name, ext4_xattr_trusted_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
......
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
#include "xattr.h" #include "xattr.h"
static size_t static size_t
ext4_xattr_user_list(struct dentry *dentry, char *list, size_t list_size, ext4_xattr_user_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const size_t prefix_len = XATTR_USER_PREFIX_LEN; const size_t prefix_len = XATTR_USER_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -30,8 +31,9 @@ ext4_xattr_user_list(struct dentry *dentry, char *list, size_t list_size, ...@@ -30,8 +31,9 @@ ext4_xattr_user_list(struct dentry *dentry, char *list, size_t list_size,
} }
static int static int
ext4_xattr_user_get(struct dentry *dentry, const char *name, ext4_xattr_user_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -42,8 +44,9 @@ ext4_xattr_user_get(struct dentry *dentry, const char *name, ...@@ -42,8 +44,9 @@ ext4_xattr_user_get(struct dentry *dentry, const char *name,
} }
static int static int
ext4_xattr_user_set(struct dentry *dentry, const char *name, ext4_xattr_user_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
......
...@@ -25,49 +25,45 @@ ...@@ -25,49 +25,45 @@
#include "f2fs.h" #include "f2fs.h"
#include "xattr.h" #include "xattr.h"
static size_t f2fs_xattr_generic_list(struct dentry *dentry, char *list, static size_t f2fs_xattr_generic_list(const struct xattr_handler *handler,
size_t list_size, const char *name, size_t len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t len)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb); struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
int total_len, prefix_len = 0; int total_len, prefix_len;
const char *prefix = NULL;
switch (type) { switch (handler->flags) {
case F2FS_XATTR_INDEX_USER: case F2FS_XATTR_INDEX_USER:
if (!test_opt(sbi, XATTR_USER)) if (!test_opt(sbi, XATTR_USER))
return -EOPNOTSUPP; return -EOPNOTSUPP;
prefix = XATTR_USER_PREFIX;
prefix_len = XATTR_USER_PREFIX_LEN;
break; break;
case F2FS_XATTR_INDEX_TRUSTED: case F2FS_XATTR_INDEX_TRUSTED:
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
prefix = XATTR_TRUSTED_PREFIX;
prefix_len = XATTR_TRUSTED_PREFIX_LEN;
break; break;
case F2FS_XATTR_INDEX_SECURITY: case F2FS_XATTR_INDEX_SECURITY:
prefix = XATTR_SECURITY_PREFIX;
prefix_len = XATTR_SECURITY_PREFIX_LEN;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
prefix_len = strlen(handler->prefix);
total_len = prefix_len + len + 1; total_len = prefix_len + len + 1;
if (list && total_len <= list_size) { if (list && total_len <= list_size) {
memcpy(list, prefix, prefix_len); memcpy(list, handler->prefix, prefix_len);
memcpy(list + prefix_len, name, len); memcpy(list + prefix_len, name, len);
list[prefix_len + len] = '\0'; list[prefix_len + len] = '\0';
} }
return total_len; return total_len;
} }
static int f2fs_xattr_generic_get(struct dentry *dentry, const char *name, static int f2fs_xattr_generic_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name, void *buffer,
size_t size)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb); struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
switch (type) { switch (handler->flags) {
case F2FS_XATTR_INDEX_USER: case F2FS_XATTR_INDEX_USER:
if (!test_opt(sbi, XATTR_USER)) if (!test_opt(sbi, XATTR_USER))
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -83,15 +79,17 @@ static int f2fs_xattr_generic_get(struct dentry *dentry, const char *name, ...@@ -83,15 +79,17 @@ static int f2fs_xattr_generic_get(struct dentry *dentry, const char *name,
} }
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
return f2fs_getxattr(d_inode(dentry), type, name, buffer, size, NULL); return f2fs_getxattr(d_inode(dentry), handler->flags, name,
buffer, size, NULL);
} }
static int f2fs_xattr_generic_set(struct dentry *dentry, const char *name, static int f2fs_xattr_generic_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name, const void *value,
size_t size, int flags)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb); struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
switch (type) { switch (handler->flags) {
case F2FS_XATTR_INDEX_USER: case F2FS_XATTR_INDEX_USER:
if (!test_opt(sbi, XATTR_USER)) if (!test_opt(sbi, XATTR_USER))
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -108,27 +106,26 @@ static int f2fs_xattr_generic_set(struct dentry *dentry, const char *name, ...@@ -108,27 +106,26 @@ static int f2fs_xattr_generic_set(struct dentry *dentry, const char *name,
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
return f2fs_setxattr(d_inode(dentry), type, name, return f2fs_setxattr(d_inode(dentry), handler->flags, name,
value, size, NULL, flags); value, size, NULL, flags);
} }
static size_t f2fs_xattr_advise_list(struct dentry *dentry, char *list, static size_t f2fs_xattr_advise_list(const struct xattr_handler *handler,
size_t list_size, const char *name, size_t len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t len)
{ {
const char *xname = F2FS_SYSTEM_ADVISE_PREFIX; const char *xname = F2FS_SYSTEM_ADVISE_PREFIX;
size_t size; size_t size;
if (type != F2FS_XATTR_INDEX_ADVISE)
return 0;
size = strlen(xname) + 1; size = strlen(xname) + 1;
if (list && size <= list_size) if (list && size <= list_size)
memcpy(list, xname, size); memcpy(list, xname, size);
return size; return size;
} }
static int f2fs_xattr_advise_get(struct dentry *dentry, const char *name, static int f2fs_xattr_advise_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name, void *buffer,
size_t size)
{ {
struct inode *inode = d_inode(dentry); struct inode *inode = d_inode(dentry);
...@@ -140,8 +137,9 @@ static int f2fs_xattr_advise_get(struct dentry *dentry, const char *name, ...@@ -140,8 +137,9 @@ static int f2fs_xattr_advise_get(struct dentry *dentry, const char *name,
return sizeof(char); return sizeof(char);
} }
static int f2fs_xattr_advise_set(struct dentry *dentry, const char *name, static int f2fs_xattr_advise_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name, const void *value,
size_t size, int flags)
{ {
struct inode *inode = d_inode(dentry); struct inode *inode = d_inode(dentry);
...@@ -462,8 +460,8 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) ...@@ -462,8 +460,8 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
if (!handler) if (!handler)
continue; continue;
size = handler->list(dentry, buffer, rest, entry->e_name, size = handler->list(handler, dentry, buffer, rest,
entry->e_name_len, handler->flags); entry->e_name, entry->e_name_len);
if (buffer && size > rest) { if (buffer && size > rest) {
error = -ERANGE; error = -ERANGE;
goto cleanup; goto cleanup;
......
...@@ -583,11 +583,13 @@ int gfs2_xattr_acl_get(struct gfs2_inode *ip, const char *name, char **ppdata) ...@@ -583,11 +583,13 @@ int gfs2_xattr_acl_get(struct gfs2_inode *ip, const char *name, char **ppdata)
* *
* Returns: actual size of data on success, -errno on error * Returns: actual size of data on success, -errno on error
*/ */
static int gfs2_xattr_get(struct dentry *dentry, const char *name, static int gfs2_xattr_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
struct gfs2_inode *ip = GFS2_I(d_inode(dentry)); struct gfs2_inode *ip = GFS2_I(d_inode(dentry));
struct gfs2_ea_location el; struct gfs2_ea_location el;
int type = handler->flags;
int error; int error;
if (!ip->i_eattr) if (!ip->i_eattr)
...@@ -1227,11 +1229,12 @@ int __gfs2_xattr_set(struct inode *inode, const char *name, ...@@ -1227,11 +1229,12 @@ int __gfs2_xattr_set(struct inode *inode, const char *name,
return error; return error;
} }
static int gfs2_xattr_set(struct dentry *dentry, const char *name, static int gfs2_xattr_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
return __gfs2_xattr_set(d_inode(dentry), name, value, return __gfs2_xattr_set(d_inode(dentry), name, value,
size, flags, type); size, flags, handler->flags);
} }
......
...@@ -849,8 +849,9 @@ static int hfsplus_removexattr(struct inode *inode, const char *name) ...@@ -849,8 +849,9 @@ static int hfsplus_removexattr(struct inode *inode, const char *name)
return err; return err;
} }
static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, static int hfsplus_osx_getxattr(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (!strcmp(name, "")) if (!strcmp(name, ""))
return -EINVAL; return -EINVAL;
...@@ -871,8 +872,9 @@ static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name, ...@@ -871,8 +872,9 @@ static int hfsplus_osx_getxattr(struct dentry *dentry, const char *name,
return __hfsplus_getxattr(d_inode(dentry), name, buffer, size); return __hfsplus_getxattr(d_inode(dentry), name, buffer, size);
} }
static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, static int hfsplus_osx_setxattr(const struct xattr_handler *handler,
const void *buffer, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags)
{ {
if (!strcmp(name, "")) if (!strcmp(name, ""))
return -EINVAL; return -EINVAL;
...@@ -893,19 +895,8 @@ static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name, ...@@ -893,19 +895,8 @@ static int hfsplus_osx_setxattr(struct dentry *dentry, const char *name,
return __hfsplus_setxattr(d_inode(dentry), name, buffer, size, flags); return __hfsplus_setxattr(d_inode(dentry), name, buffer, size, flags);
} }
static size_t hfsplus_osx_listxattr(struct dentry *dentry, char *list,
size_t list_size, const char *name, size_t name_len, int type)
{
/*
* This method is not used.
* It is used hfsplus_listxattr() instead of generic_listxattr().
*/
return -EOPNOTSUPP;
}
const struct xattr_handler hfsplus_xattr_osx_handler = { const struct xattr_handler hfsplus_xattr_osx_handler = {
.prefix = XATTR_MAC_OSX_PREFIX, .prefix = XATTR_MAC_OSX_PREFIX,
.list = hfsplus_osx_listxattr,
.get = hfsplus_osx_getxattr, .get = hfsplus_osx_getxattr,
.set = hfsplus_osx_setxattr, .set = hfsplus_osx_setxattr,
}; };
...@@ -13,32 +13,24 @@ ...@@ -13,32 +13,24 @@
#include "xattr.h" #include "xattr.h"
#include "acl.h" #include "acl.h"
static int hfsplus_security_getxattr(struct dentry *dentry, const char *name, static int hfsplus_security_getxattr(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
return hfsplus_getxattr(dentry, name, buffer, size, return hfsplus_getxattr(dentry, name, buffer, size,
XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX,
XATTR_SECURITY_PREFIX_LEN); XATTR_SECURITY_PREFIX_LEN);
} }
static int hfsplus_security_setxattr(struct dentry *dentry, const char *name, static int hfsplus_security_setxattr(const struct xattr_handler *handler,
const void *buffer, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags)
{ {
return hfsplus_setxattr(dentry, name, buffer, size, flags, return hfsplus_setxattr(dentry, name, buffer, size, flags,
XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX,
XATTR_SECURITY_PREFIX_LEN); XATTR_SECURITY_PREFIX_LEN);
} }
static size_t hfsplus_security_listxattr(struct dentry *dentry, char *list,
size_t list_size, const char *name, size_t name_len, int type)
{
/*
* This method is not used.
* It is used hfsplus_listxattr() instead of generic_listxattr().
*/
return -EOPNOTSUPP;
}
static int hfsplus_initxattrs(struct inode *inode, static int hfsplus_initxattrs(struct inode *inode,
const struct xattr *xattr_array, const struct xattr *xattr_array,
void *fs_info) void *fs_info)
...@@ -92,7 +84,6 @@ int hfsplus_init_inode_security(struct inode *inode, ...@@ -92,7 +84,6 @@ int hfsplus_init_inode_security(struct inode *inode,
const struct xattr_handler hfsplus_xattr_security_handler = { const struct xattr_handler hfsplus_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX, .prefix = XATTR_SECURITY_PREFIX,
.list = hfsplus_security_listxattr,
.get = hfsplus_security_getxattr, .get = hfsplus_security_getxattr,
.set = hfsplus_security_setxattr, .set = hfsplus_security_setxattr,
}; };
...@@ -11,34 +11,25 @@ ...@@ -11,34 +11,25 @@
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
#include "xattr.h" #include "xattr.h"
static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, static int hfsplus_trusted_getxattr(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
return hfsplus_getxattr(dentry, name, buffer, size, return hfsplus_getxattr(dentry, name, buffer, size,
XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX,
XATTR_TRUSTED_PREFIX_LEN); XATTR_TRUSTED_PREFIX_LEN);
} }
static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, static int hfsplus_trusted_setxattr(const struct xattr_handler *handler,
const void *buffer, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags)
{ {
return hfsplus_setxattr(dentry, name, buffer, size, flags, return hfsplus_setxattr(dentry, name, buffer, size, flags,
XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN); XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
} }
static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list,
size_t list_size, const char *name, size_t name_len, int type)
{
/*
* This method is not used.
* It is used hfsplus_listxattr() instead of generic_listxattr().
*/
return -EOPNOTSUPP;
}
const struct xattr_handler hfsplus_xattr_trusted_handler = { const struct xattr_handler hfsplus_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX, .prefix = XATTR_TRUSTED_PREFIX,
.list = hfsplus_trusted_listxattr,
.get = hfsplus_trusted_getxattr, .get = hfsplus_trusted_getxattr,
.set = hfsplus_trusted_setxattr, .set = hfsplus_trusted_setxattr,
}; };
...@@ -11,34 +11,25 @@ ...@@ -11,34 +11,25 @@
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
#include "xattr.h" #include "xattr.h"
static int hfsplus_user_getxattr(struct dentry *dentry, const char *name, static int hfsplus_user_getxattr(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
return hfsplus_getxattr(dentry, name, buffer, size, return hfsplus_getxattr(dentry, name, buffer, size,
XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
} }
static int hfsplus_user_setxattr(struct dentry *dentry, const char *name, static int hfsplus_user_setxattr(const struct xattr_handler *handler,
const void *buffer, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags)
{ {
return hfsplus_setxattr(dentry, name, buffer, size, flags, return hfsplus_setxattr(dentry, name, buffer, size, flags,
XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
} }
static size_t hfsplus_user_listxattr(struct dentry *dentry, char *list,
size_t list_size, const char *name, size_t name_len, int type)
{
/*
* This method is not used.
* It is used hfsplus_listxattr() instead of generic_listxattr().
*/
return -EOPNOTSUPP;
}
const struct xattr_handler hfsplus_xattr_user_handler = { const struct xattr_handler hfsplus_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX, .prefix = XATTR_USER_PREFIX,
.list = hfsplus_user_listxattr,
.get = hfsplus_user_getxattr, .get = hfsplus_user_getxattr,
.set = hfsplus_user_setxattr, .set = hfsplus_user_setxattr,
}; };
...@@ -48,8 +48,9 @@ int jffs2_init_security(struct inode *inode, struct inode *dir, ...@@ -48,8 +48,9 @@ int jffs2_init_security(struct inode *inode, struct inode *dir,
} }
/* ---- XATTR Handler for "security.*" ----------------- */ /* ---- XATTR Handler for "security.*" ----------------- */
static int jffs2_security_getxattr(struct dentry *dentry, const char *name, static int jffs2_security_getxattr(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (!strcmp(name, "")) if (!strcmp(name, ""))
return -EINVAL; return -EINVAL;
...@@ -58,8 +59,9 @@ static int jffs2_security_getxattr(struct dentry *dentry, const char *name, ...@@ -58,8 +59,9 @@ static int jffs2_security_getxattr(struct dentry *dentry, const char *name,
name, buffer, size); name, buffer, size);
} }
static int jffs2_security_setxattr(struct dentry *dentry, const char *name, static int jffs2_security_setxattr(const struct xattr_handler *handler,
const void *buffer, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags)
{ {
if (!strcmp(name, "")) if (!strcmp(name, ""))
return -EINVAL; return -EINVAL;
...@@ -68,8 +70,10 @@ static int jffs2_security_setxattr(struct dentry *dentry, const char *name, ...@@ -68,8 +70,10 @@ static int jffs2_security_setxattr(struct dentry *dentry, const char *name,
name, buffer, size, flags); name, buffer, size, flags);
} }
static size_t jffs2_security_listxattr(struct dentry *dentry, char *list, static size_t jffs2_security_listxattr(const struct xattr_handler *handler,
size_t list_size, const char *name, size_t name_len, int type) 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; size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1;
......
...@@ -1001,11 +1001,12 @@ ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size) ...@@ -1001,11 +1001,12 @@ ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
if (!xhandle) if (!xhandle)
continue; continue;
if (buffer) { if (buffer) {
rc = xhandle->list(dentry, buffer+len, size-len, rc = xhandle->list(xhandle, dentry, buffer + len,
xd->xname, xd->name_len, xd->flags); size - len, xd->xname,
xd->name_len);
} else { } else {
rc = xhandle->list(dentry, NULL, 0, xd->xname, rc = xhandle->list(xhandle, dentry, NULL, 0,
xd->name_len, xd->flags); xd->xname, xd->name_len);
} }
if (rc < 0) if (rc < 0)
goto out; goto out;
......
...@@ -16,8 +16,9 @@ ...@@ -16,8 +16,9 @@
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include "nodelist.h" #include "nodelist.h"
static int jffs2_trusted_getxattr(struct dentry *dentry, const char *name, static int jffs2_trusted_getxattr(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (!strcmp(name, "")) if (!strcmp(name, ""))
return -EINVAL; return -EINVAL;
...@@ -25,8 +26,9 @@ static int jffs2_trusted_getxattr(struct dentry *dentry, const char *name, ...@@ -25,8 +26,9 @@ static int jffs2_trusted_getxattr(struct dentry *dentry, const char *name,
name, buffer, size); name, buffer, size);
} }
static int jffs2_trusted_setxattr(struct dentry *dentry, const char *name, static int jffs2_trusted_setxattr(const struct xattr_handler *handler,
const void *buffer, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags)
{ {
if (!strcmp(name, "")) if (!strcmp(name, ""))
return -EINVAL; return -EINVAL;
...@@ -34,11 +36,16 @@ static int jffs2_trusted_setxattr(struct dentry *dentry, const char *name, ...@@ -34,11 +36,16 @@ static int jffs2_trusted_setxattr(struct dentry *dentry, const char *name,
name, buffer, size, flags); name, buffer, size, flags);
} }
static size_t jffs2_trusted_listxattr(struct dentry *dentry, char *list, static size_t jffs2_trusted_listxattr(const struct xattr_handler *handler,
size_t list_size, const char *name, size_t name_len, int type) struct dentry *dentry, char *list,
size_t list_size, const char *name,
size_t name_len)
{ {
size_t retlen = XATTR_TRUSTED_PREFIX_LEN + name_len + 1; size_t retlen = XATTR_TRUSTED_PREFIX_LEN + name_len + 1;
if (!capable(CAP_SYS_ADMIN))
return 0;
if (list && retlen<=list_size) { if (list && retlen<=list_size) {
strcpy(list, XATTR_TRUSTED_PREFIX); strcpy(list, XATTR_TRUSTED_PREFIX);
strcpy(list + XATTR_TRUSTED_PREFIX_LEN, name); strcpy(list + XATTR_TRUSTED_PREFIX_LEN, name);
......
...@@ -16,8 +16,9 @@ ...@@ -16,8 +16,9 @@
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include "nodelist.h" #include "nodelist.h"
static int jffs2_user_getxattr(struct dentry *dentry, const char *name, static int jffs2_user_getxattr(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (!strcmp(name, "")) if (!strcmp(name, ""))
return -EINVAL; return -EINVAL;
...@@ -25,8 +26,9 @@ static int jffs2_user_getxattr(struct dentry *dentry, const char *name, ...@@ -25,8 +26,9 @@ static int jffs2_user_getxattr(struct dentry *dentry, const char *name,
name, buffer, size); name, buffer, size);
} }
static int jffs2_user_setxattr(struct dentry *dentry, const char *name, static int jffs2_user_setxattr(const struct xattr_handler *handler,
const void *buffer, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *buffer, size_t size, int flags)
{ {
if (!strcmp(name, "")) if (!strcmp(name, ""))
return -EINVAL; return -EINVAL;
...@@ -34,8 +36,10 @@ static int jffs2_user_setxattr(struct dentry *dentry, const char *name, ...@@ -34,8 +36,10 @@ static int jffs2_user_setxattr(struct dentry *dentry, const char *name,
name, buffer, size, flags); name, buffer, size, flags);
} }
static size_t jffs2_user_listxattr(struct dentry *dentry, char *list, static size_t jffs2_user_listxattr(const struct xattr_handler *handler,
size_t list_size, const char *name, size_t name_len, int type) 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; size_t retlen = XATTR_USER_PREFIX_LEN + name_len + 1;
......
...@@ -6248,9 +6248,10 @@ nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp) ...@@ -6248,9 +6248,10 @@ nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp)
#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler *handler,
struct dentry *dentry, const char *key,
const void *buf, size_t buflen, const void *buf, size_t buflen,
int flags, int type) int flags)
{ {
if (strcmp(key, "") != 0) if (strcmp(key, "") != 0)
return -EINVAL; return -EINVAL;
...@@ -6258,8 +6259,9 @@ static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, ...@@ -6258,8 +6259,9 @@ static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
return nfs4_proc_set_acl(d_inode(dentry), buf, buflen); return nfs4_proc_set_acl(d_inode(dentry), buf, buflen);
} }
static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler *handler,
void *buf, size_t buflen, int type) struct dentry *dentry, const char *key,
void *buf, size_t buflen)
{ {
if (strcmp(key, "") != 0) if (strcmp(key, "") != 0)
return -EINVAL; return -EINVAL;
...@@ -6267,9 +6269,10 @@ static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, ...@@ -6267,9 +6269,10 @@ static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
return nfs4_proc_get_acl(d_inode(dentry), buf, buflen); return nfs4_proc_get_acl(d_inode(dentry), buf, buflen);
} }
static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, static size_t nfs4_xattr_list_nfs4_acl(const struct xattr_handler *handler,
struct dentry *dentry, char *list,
size_t list_len, const char *name, size_t list_len, const char *name,
size_t name_len, int type) size_t name_len)
{ {
size_t len = sizeof(XATTR_NAME_NFSV4_ACL); size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
...@@ -6287,9 +6290,10 @@ static inline int nfs4_server_supports_labels(struct nfs_server *server) ...@@ -6287,9 +6290,10 @@ static inline int nfs4_server_supports_labels(struct nfs_server *server)
return server->caps & NFS_CAP_SECURITY_LABEL; return server->caps & NFS_CAP_SECURITY_LABEL;
} }
static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, static int nfs4_xattr_set_nfs4_label(const struct xattr_handler *handler,
const void *buf, size_t buflen, struct dentry *dentry, const char *key,
int flags, int type) const void *buf, size_t buflen,
int flags)
{ {
if (security_ismaclabel(key)) if (security_ismaclabel(key))
return nfs4_set_security_label(dentry, buf, buflen); return nfs4_set_security_label(dentry, buf, buflen);
...@@ -6297,17 +6301,19 @@ static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key, ...@@ -6297,17 +6301,19 @@ static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key, static int nfs4_xattr_get_nfs4_label(const struct xattr_handler *handler,
void *buf, size_t buflen, int type) struct dentry *dentry, const char *key,
void *buf, size_t buflen)
{ {
if (security_ismaclabel(key)) if (security_ismaclabel(key))
return nfs4_get_security_label(d_inode(dentry), buf, buflen); return nfs4_get_security_label(d_inode(dentry), buf, buflen);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list, static size_t nfs4_xattr_list_nfs4_label(const struct xattr_handler *handler,
size_t list_len, const char *name, struct dentry *dentry, char *list,
size_t name_len, int type) size_t list_len, const char *name,
size_t name_len)
{ {
size_t len = 0; size_t len = 0;
......
...@@ -7229,9 +7229,10 @@ int ocfs2_init_security_and_acl(struct inode *dir, ...@@ -7229,9 +7229,10 @@ int ocfs2_init_security_and_acl(struct inode *dir,
/* /*
* 'security' attributes support * 'security' attributes support
*/ */
static size_t ocfs2_xattr_security_list(struct dentry *dentry, char *list, static size_t ocfs2_xattr_security_list(const struct xattr_handler *handler,
struct dentry *dentry, char *list,
size_t list_size, const char *name, size_t list_size, const char *name,
size_t name_len, int type) size_t name_len)
{ {
const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -7244,8 +7245,9 @@ static size_t ocfs2_xattr_security_list(struct dentry *dentry, char *list, ...@@ -7244,8 +7245,9 @@ static size_t ocfs2_xattr_security_list(struct dentry *dentry, char *list,
return total_len; return total_len;
} }
static int ocfs2_xattr_security_get(struct dentry *dentry, const char *name, static int ocfs2_xattr_security_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -7253,8 +7255,9 @@ static int ocfs2_xattr_security_get(struct dentry *dentry, const char *name, ...@@ -7253,8 +7255,9 @@ static int ocfs2_xattr_security_get(struct dentry *dentry, const char *name,
name, buffer, size); name, buffer, size);
} }
static int ocfs2_xattr_security_set(struct dentry *dentry, const char *name, static int ocfs2_xattr_security_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -7319,9 +7322,10 @@ const struct xattr_handler ocfs2_xattr_security_handler = { ...@@ -7319,9 +7322,10 @@ const struct xattr_handler ocfs2_xattr_security_handler = {
/* /*
* 'trusted' attributes support * 'trusted' attributes support
*/ */
static size_t ocfs2_xattr_trusted_list(struct dentry *dentry, char *list, static size_t ocfs2_xattr_trusted_list(const struct xattr_handler *handler,
struct dentry *dentry, char *list,
size_t list_size, const char *name, size_t list_size, const char *name,
size_t name_len, int type) size_t name_len)
{ {
const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -7337,8 +7341,9 @@ static size_t ocfs2_xattr_trusted_list(struct dentry *dentry, char *list, ...@@ -7337,8 +7341,9 @@ static size_t ocfs2_xattr_trusted_list(struct dentry *dentry, char *list,
return total_len; return total_len;
} }
static int ocfs2_xattr_trusted_get(struct dentry *dentry, const char *name, static int ocfs2_xattr_trusted_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -7346,8 +7351,9 @@ static int ocfs2_xattr_trusted_get(struct dentry *dentry, const char *name, ...@@ -7346,8 +7351,9 @@ static int ocfs2_xattr_trusted_get(struct dentry *dentry, const char *name,
name, buffer, size); name, buffer, size);
} }
static int ocfs2_xattr_trusted_set(struct dentry *dentry, const char *name, static int ocfs2_xattr_trusted_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
...@@ -7366,9 +7372,10 @@ const struct xattr_handler ocfs2_xattr_trusted_handler = { ...@@ -7366,9 +7372,10 @@ const struct xattr_handler ocfs2_xattr_trusted_handler = {
/* /*
* 'user' attributes support * 'user' attributes support
*/ */
static size_t ocfs2_xattr_user_list(struct dentry *dentry, char *list, static size_t ocfs2_xattr_user_list(const struct xattr_handler *handler,
struct dentry *dentry, char *list,
size_t list_size, const char *name, size_t list_size, const char *name,
size_t name_len, int type) size_t name_len)
{ {
const size_t prefix_len = XATTR_USER_PREFIX_LEN; const size_t prefix_len = XATTR_USER_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1; const size_t total_len = prefix_len + name_len + 1;
...@@ -7385,8 +7392,9 @@ static size_t ocfs2_xattr_user_list(struct dentry *dentry, char *list, ...@@ -7385,8 +7392,9 @@ static size_t ocfs2_xattr_user_list(struct dentry *dentry, char *list,
return total_len; return total_len;
} }
static int ocfs2_xattr_user_get(struct dentry *dentry, const char *name, static int ocfs2_xattr_user_get(const struct xattr_handler *handler,
void *buffer, size_t size, int type) struct dentry *dentry, const char *name,
void *buffer, size_t size)
{ {
struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
...@@ -7398,8 +7406,9 @@ static int ocfs2_xattr_user_get(struct dentry *dentry, const char *name, ...@@ -7398,8 +7406,9 @@ static int ocfs2_xattr_user_get(struct dentry *dentry, const char *name,
buffer, size); buffer, size);
} }
static int ocfs2_xattr_user_set(struct dentry *dentry, const char *name, static int ocfs2_xattr_user_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
......
...@@ -762,18 +762,21 @@ posix_acl_to_xattr(struct user_namespace *user_ns, const struct posix_acl *acl, ...@@ -762,18 +762,21 @@ posix_acl_to_xattr(struct user_namespace *user_ns, const struct posix_acl *acl,
EXPORT_SYMBOL (posix_acl_to_xattr); EXPORT_SYMBOL (posix_acl_to_xattr);
static int static int
posix_acl_xattr_get(struct dentry *dentry, const char *name, posix_acl_xattr_get(const struct xattr_handler *handler,
void *value, size_t size, int type) struct dentry *dentry, const char *name,
void *value, size_t size)
{ {
struct posix_acl *acl; struct posix_acl *acl;
int error; int error;
if (strcmp(name, "") != 0)
return -EINVAL;
if (!IS_POSIXACL(d_backing_inode(dentry))) if (!IS_POSIXACL(d_backing_inode(dentry)))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (d_is_symlink(dentry)) if (d_is_symlink(dentry))
return -EOPNOTSUPP; return -EOPNOTSUPP;
acl = get_acl(d_backing_inode(dentry), type); acl = get_acl(d_backing_inode(dentry), handler->flags);
if (IS_ERR(acl)) if (IS_ERR(acl))
return PTR_ERR(acl); return PTR_ERR(acl);
if (acl == NULL) if (acl == NULL)
...@@ -786,19 +789,22 @@ posix_acl_xattr_get(struct dentry *dentry, const char *name, ...@@ -786,19 +789,22 @@ posix_acl_xattr_get(struct dentry *dentry, const char *name,
} }
static int static int
posix_acl_xattr_set(struct dentry *dentry, const char *name, posix_acl_xattr_set(const struct xattr_handler *handler,
const void *value, size_t size, int flags, int type) struct dentry *dentry, const char *name,
const void *value, size_t size, int flags)
{ {
struct inode *inode = d_backing_inode(dentry); struct inode *inode = d_backing_inode(dentry);
struct posix_acl *acl = NULL; struct posix_acl *acl = NULL;
int ret; int ret;
if (strcmp(name, "") != 0)
return -EINVAL;
if (!IS_POSIXACL(inode)) if (!IS_POSIXACL(inode))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!inode->i_op->set_acl) if (!inode->i_op->set_acl)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) if (handler->flags == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
return value ? -EACCES : 0; return value ? -EACCES : 0;
if (!inode_owner_or_capable(inode)) if (!inode_owner_or_capable(inode))
return -EPERM; return -EPERM;
...@@ -815,28 +821,22 @@ posix_acl_xattr_set(struct dentry *dentry, const char *name, ...@@ -815,28 +821,22 @@ posix_acl_xattr_set(struct dentry *dentry, const char *name,
} }
} }
ret = inode->i_op->set_acl(inode, acl, type); ret = inode->i_op->set_acl(inode, acl, handler->flags);
out: out:
posix_acl_release(acl); posix_acl_release(acl);
return ret; return ret;
} }
static size_t static size_t
posix_acl_xattr_list(struct dentry *dentry, char *list, size_t list_size, posix_acl_xattr_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int type) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const char *xname; const char *xname = handler->prefix;
size_t size; size_t size;
if (!IS_POSIXACL(d_backing_inode(dentry))) if (!IS_POSIXACL(d_backing_inode(dentry)))
return -EOPNOTSUPP; return 0;
if (d_is_symlink(dentry))
return -EOPNOTSUPP;
if (type == ACL_TYPE_ACCESS)
xname = POSIX_ACL_XATTR_ACCESS;
else
xname = POSIX_ACL_XATTR_DEFAULT;
size = strlen(xname) + 1; size = strlen(xname) + 1;
if (list && size <= list_size) if (list && size <= list_size)
......
...@@ -778,7 +778,7 @@ reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, ...@@ -778,7 +778,7 @@ reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1) if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return handler->get(dentry, name, buffer, size, handler->flags); return handler->get(handler, dentry, name, buffer, size);
} }
/* /*
...@@ -797,7 +797,7 @@ reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, ...@@ -797,7 +797,7 @@ reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1) if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return handler->set(dentry, name, value, size, flags, handler->flags); return handler->set(handler, dentry, name, value, size, flags);
} }
/* /*
...@@ -814,7 +814,7 @@ int reiserfs_removexattr(struct dentry *dentry, const char *name) ...@@ -814,7 +814,7 @@ int reiserfs_removexattr(struct dentry *dentry, const char *name)
if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1) if (!handler || get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return handler->set(dentry, name, NULL, 0, XATTR_REPLACE, handler->flags); return handler->set(handler, dentry, name, NULL, 0, XATTR_REPLACE);
} }
struct listxattr_buf { struct listxattr_buf {
...@@ -842,14 +842,14 @@ static int listxattr_filler(struct dir_context *ctx, const char *name, ...@@ -842,14 +842,14 @@ static int listxattr_filler(struct dir_context *ctx, const char *name,
if (!handler) /* Unsupported xattr name */ if (!handler) /* Unsupported xattr name */
return 0; return 0;
if (b->buf) { if (b->buf) {
size = handler->list(b->dentry, b->buf + b->pos, size = handler->list(handler, b->dentry,
b->size, name, namelen, b->buf + b->pos, b->size, name,
handler->flags); namelen);
if (size > b->size) if (size > b->size)
return -ERANGE; return -ERANGE;
} else { } else {
size = handler->list(b->dentry, NULL, 0, name, size = handler->list(handler, b->dentry,
namelen, handler->flags); NULL, 0, name, namelen);
} }
b->pos += size; b->pos += size;
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
static int static int
security_get(struct dentry *dentry, const char *name, void *buffer, size_t size, security_get(const struct xattr_handler *handler, struct dentry *dentry,
int handler_flags) const char *name, void *buffer, size_t size)
{ {
if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
return -EINVAL; return -EINVAL;
...@@ -22,8 +22,8 @@ security_get(struct dentry *dentry, const char *name, void *buffer, size_t size, ...@@ -22,8 +22,8 @@ security_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
} }
static int static int
security_set(struct dentry *dentry, const char *name, const void *buffer, security_set(const struct xattr_handler *handler, struct dentry *dentry,
size_t size, int flags, int handler_flags) const char *name, const void *buffer, size_t size, int flags)
{ {
if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
return -EINVAL; return -EINVAL;
...@@ -34,8 +34,9 @@ security_set(struct dentry *dentry, const char *name, const void *buffer, ...@@ -34,8 +34,9 @@ security_set(struct dentry *dentry, const char *name, const void *buffer,
return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags); return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
} }
static size_t security_list(struct dentry *dentry, char *list, size_t list_len, static size_t security_list(const struct xattr_handler *handler,
const char *name, size_t namelen, int handler_flags) struct dentry *dentry, char *list, size_t list_len,
const char *name, size_t namelen)
{ {
const size_t len = namelen + 1; const size_t len = namelen + 1;
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
static int static int
trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size, trusted_get(const struct xattr_handler *handler, struct dentry *dentry,
int handler_flags) const char *name, void *buffer, size_t size)
{ {
if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
return -EINVAL; return -EINVAL;
...@@ -21,8 +21,8 @@ trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size, ...@@ -21,8 +21,8 @@ trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
} }
static int static int
trusted_set(struct dentry *dentry, const char *name, const void *buffer, trusted_set(const struct xattr_handler *handler, struct dentry *dentry,
size_t size, int flags, int handler_flags) const char *name, const void *buffer, size_t size, int flags)
{ {
if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
return -EINVAL; return -EINVAL;
...@@ -33,8 +33,9 @@ trusted_set(struct dentry *dentry, const char *name, const void *buffer, ...@@ -33,8 +33,9 @@ trusted_set(struct dentry *dentry, const char *name, const void *buffer,
return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags); return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
} }
static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size, static size_t trusted_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int handler_flags) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const size_t len = name_len + 1; const size_t len = name_len + 1;
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
static int static int
user_get(struct dentry *dentry, const char *name, void *buffer, size_t size, user_get(const struct xattr_handler *handler, struct dentry *dentry,
int handler_flags) const char *name, void *buffer, size_t size)
{ {
if (strlen(name) < sizeof(XATTR_USER_PREFIX)) if (strlen(name) < sizeof(XATTR_USER_PREFIX))
...@@ -19,8 +19,8 @@ user_get(struct dentry *dentry, const char *name, void *buffer, size_t size, ...@@ -19,8 +19,8 @@ user_get(struct dentry *dentry, const char *name, void *buffer, size_t size,
} }
static int static int
user_set(struct dentry *dentry, const char *name, const void *buffer, user_set(const struct xattr_handler *handler, struct dentry *dentry,
size_t size, int flags, int handler_flags) const char *name, const void *buffer, size_t size, int flags)
{ {
if (strlen(name) < sizeof(XATTR_USER_PREFIX)) if (strlen(name) < sizeof(XATTR_USER_PREFIX))
return -EINVAL; return -EINVAL;
...@@ -30,8 +30,9 @@ user_set(struct dentry *dentry, const char *name, const void *buffer, ...@@ -30,8 +30,9 @@ user_set(struct dentry *dentry, const char *name, const void *buffer,
return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags); return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
} }
static size_t user_list(struct dentry *dentry, char *list, size_t list_size, static size_t user_list(const struct xattr_handler *handler,
const char *name, size_t name_len, int handler_flags) struct dentry *dentry, char *list, size_t list_size,
const char *name, size_t name_len)
{ {
const size_t len = name_len + 1; const size_t len = name_len + 1;
......
...@@ -68,8 +68,8 @@ ssize_t squashfs_listxattr(struct dentry *d, char *buffer, ...@@ -68,8 +68,8 @@ ssize_t squashfs_listxattr(struct dentry *d, char *buffer,
name_size = le16_to_cpu(entry.size); name_size = le16_to_cpu(entry.size);
handler = squashfs_xattr_handler(le16_to_cpu(entry.type)); handler = squashfs_xattr_handler(le16_to_cpu(entry.type));
if (handler) if (handler)
prefix_size = handler->list(d, buffer, rest, NULL, prefix_size = handler->list(handler, d, buffer, rest,
name_size, handler->flags); NULL, name_size);
if (prefix_size) { if (prefix_size) {
if (buffer) { if (buffer) {
if (prefix_size + name_size + 1 > rest) { if (prefix_size + name_size + 1 > rest) {
...@@ -212,88 +212,68 @@ static int squashfs_xattr_get(struct inode *inode, int name_index, ...@@ -212,88 +212,68 @@ static int squashfs_xattr_get(struct inode *inode, int name_index,
} }
/* static size_t squashfs_xattr_handler_list(const struct xattr_handler *handler,
* User namespace support struct dentry *d, char *list,
*/ size_t list_size, const char *name,
static size_t squashfs_user_list(struct dentry *d, char *list, size_t list_size, size_t name_len)
const char *name, size_t name_len, int type)
{ {
if (list && XATTR_USER_PREFIX_LEN <= list_size) int len = strlen(handler->prefix);
memcpy(list, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
return XATTR_USER_PREFIX_LEN; if (list && len <= list_size)
memcpy(list, handler->prefix, len);
return len;
} }
static int squashfs_user_get(struct dentry *d, const char *name, void *buffer, static int squashfs_xattr_handler_get(const struct xattr_handler *handler,
size_t size, int type) struct dentry *d, const char *name,
void *buffer, size_t size)
{ {
if (name[0] == '\0') if (name[0] == '\0')
return -EINVAL; return -EINVAL;
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_USER, name, return squashfs_xattr_get(d_inode(d), handler->flags, name,
buffer, size); buffer, size);
} }
/*
* User namespace support
*/
static const struct xattr_handler squashfs_xattr_user_handler = { static const struct xattr_handler squashfs_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX, .prefix = XATTR_USER_PREFIX,
.list = squashfs_user_list, .flags = SQUASHFS_XATTR_USER,
.get = squashfs_user_get .list = squashfs_xattr_handler_list,
.get = squashfs_xattr_handler_get
}; };
/* /*
* Trusted namespace support * Trusted namespace support
*/ */
static size_t squashfs_trusted_list(struct dentry *d, char *list, static size_t squashfs_trusted_xattr_handler_list(const struct xattr_handler *handler,
size_t list_size, const char *name, size_t name_len, int type) struct dentry *d, char *list,
size_t list_size, const char *name,
size_t name_len)
{ {
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return 0; return 0;
return squashfs_xattr_handler_list(handler, d, list, list_size, name,
if (list && XATTR_TRUSTED_PREFIX_LEN <= list_size) name_len);
memcpy(list, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
return XATTR_TRUSTED_PREFIX_LEN;
}
static int squashfs_trusted_get(struct dentry *d, const char *name,
void *buffer, size_t size, int type)
{
if (name[0] == '\0')
return -EINVAL;
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_TRUSTED, name,
buffer, size);
} }
static const struct xattr_handler squashfs_xattr_trusted_handler = { static const struct xattr_handler squashfs_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX, .prefix = XATTR_TRUSTED_PREFIX,
.list = squashfs_trusted_list, .flags = SQUASHFS_XATTR_TRUSTED,
.get = squashfs_trusted_get .list = squashfs_trusted_xattr_handler_list,
.get = squashfs_xattr_handler_get
}; };
/* /*
* Security namespace support * Security namespace support
*/ */
static size_t squashfs_security_list(struct dentry *d, char *list,
size_t list_size, const char *name, size_t name_len, int type)
{
if (list && XATTR_SECURITY_PREFIX_LEN <= list_size)
memcpy(list, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN);
return XATTR_SECURITY_PREFIX_LEN;
}
static int squashfs_security_get(struct dentry *d, const char *name,
void *buffer, size_t size, int type)
{
if (name[0] == '\0')
return -EINVAL;
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_SECURITY, name,
buffer, size);
}
static const struct xattr_handler squashfs_xattr_security_handler = { static const struct xattr_handler squashfs_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX, .prefix = XATTR_SECURITY_PREFIX,
.list = squashfs_security_list, .flags = SQUASHFS_XATTR_SECURITY,
.get = squashfs_security_get .list = squashfs_xattr_handler_list,
.get = squashfs_xattr_handler_get
}; };
static const struct xattr_handler *squashfs_xattr_handler(int type) static const struct xattr_handler *squashfs_xattr_handler(int type)
......
...@@ -2040,7 +2040,6 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -2040,7 +2040,6 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
if (c->max_inode_sz > MAX_LFS_FILESIZE) if (c->max_inode_sz > MAX_LFS_FILESIZE)
sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE; sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE;
sb->s_op = &ubifs_super_operations; sb->s_op = &ubifs_super_operations;
sb->s_xattr = ubifs_xattr_handlers;
mutex_lock(&c->umount_mutex); mutex_lock(&c->umount_mutex);
err = mount_ubifs(c); err = mount_ubifs(c);
......
...@@ -1470,7 +1470,6 @@ extern spinlock_t ubifs_infos_lock; ...@@ -1470,7 +1470,6 @@ extern spinlock_t ubifs_infos_lock;
extern atomic_long_t ubifs_clean_zn_cnt; extern atomic_long_t ubifs_clean_zn_cnt;
extern struct kmem_cache *ubifs_inode_slab; extern struct kmem_cache *ubifs_inode_slab;
extern const struct super_operations ubifs_super_operations; extern const struct super_operations ubifs_super_operations;
extern const struct xattr_handler *ubifs_xattr_handlers[];
extern const struct address_space_operations ubifs_file_address_operations; extern const struct address_space_operations ubifs_file_address_operations;
extern const struct file_operations ubifs_file_operations; extern const struct file_operations ubifs_file_operations;
extern const struct inode_operations ubifs_file_inode_operations; extern const struct inode_operations ubifs_file_inode_operations;
......
...@@ -588,46 +588,6 @@ int ubifs_removexattr(struct dentry *dentry, const char *name) ...@@ -588,46 +588,6 @@ int ubifs_removexattr(struct dentry *dentry, const char *name)
return err; return err;
} }
static size_t security_listxattr(struct dentry *d, char *list, size_t list_size,
const char *name, size_t name_len, int flags)
{
const int prefix_len = XATTR_SECURITY_PREFIX_LEN;
const size_t total_len = prefix_len + name_len + 1;
if (list && total_len <= list_size) {
memcpy(list, XATTR_SECURITY_PREFIX, prefix_len);
memcpy(list + prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
}
return total_len;
}
static int security_getxattr(struct dentry *d, const char *name, void *buffer,
size_t size, int flags)
{
return ubifs_getxattr(d, name, buffer, size);
}
static int security_setxattr(struct dentry *d, const char *name,
const void *value, size_t size, int flags,
int handler_flags)
{
return ubifs_setxattr(d, name, value, size, flags);
}
static const struct xattr_handler ubifs_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX,
.list = security_listxattr,
.get = security_getxattr,
.set = security_setxattr,
};
const struct xattr_handler *ubifs_xattr_handlers[] = {
&ubifs_xattr_security_handler,
NULL,
};
static int init_xattrs(struct inode *inode, const struct xattr *xattr_array, static int init_xattrs(struct inode *inode, const struct xattr *xattr_array,
void *fs_info) void *fs_info)
{ {
......
...@@ -720,7 +720,7 @@ generic_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t s ...@@ -720,7 +720,7 @@ generic_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t s
handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name);
if (!handler) if (!handler)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return handler->get(dentry, name, buffer, size, handler->flags); return handler->get(handler, dentry, name, buffer, size);
} }
/* /*
...@@ -735,15 +735,15 @@ generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) ...@@ -735,15 +735,15 @@ generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
if (!buffer) { if (!buffer) {
for_each_xattr_handler(handlers, handler) { for_each_xattr_handler(handlers, handler) {
size += handler->list(dentry, NULL, 0, NULL, 0, size += handler->list(handler, dentry, NULL, 0,
handler->flags); NULL, 0);
} }
} else { } else {
char *buf = buffer; char *buf = buffer;
for_each_xattr_handler(handlers, handler) { for_each_xattr_handler(handlers, handler) {
size = handler->list(dentry, buf, buffer_size, size = handler->list(handler, dentry, buf, buffer_size,
NULL, 0, handler->flags); NULL, 0);
if (size > buffer_size) if (size > buffer_size)
return -ERANGE; return -ERANGE;
buf += size; buf += size;
...@@ -767,7 +767,7 @@ generic_setxattr(struct dentry *dentry, const char *name, const void *value, siz ...@@ -767,7 +767,7 @@ generic_setxattr(struct dentry *dentry, const char *name, const void *value, siz
handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name);
if (!handler) if (!handler)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return handler->set(dentry, name, value, size, flags, handler->flags); return handler->set(handler, dentry, name, value, size, flags);
} }
/* /*
...@@ -782,8 +782,7 @@ generic_removexattr(struct dentry *dentry, const char *name) ...@@ -782,8 +782,7 @@ generic_removexattr(struct dentry *dentry, const char *name)
handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name);
if (!handler) if (!handler)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return handler->set(dentry, name, NULL, 0, return handler->set(handler, dentry, name, NULL, 0, XATTR_REPLACE);
XATTR_REPLACE, handler->flags);
} }
EXPORT_SYMBOL(generic_getxattr); EXPORT_SYMBOL(generic_getxattr);
...@@ -791,6 +790,30 @@ EXPORT_SYMBOL(generic_listxattr); ...@@ -791,6 +790,30 @@ EXPORT_SYMBOL(generic_listxattr);
EXPORT_SYMBOL(generic_setxattr); EXPORT_SYMBOL(generic_setxattr);
EXPORT_SYMBOL(generic_removexattr); EXPORT_SYMBOL(generic_removexattr);
/**
* xattr_full_name - Compute full attribute name from suffix
*
* @handler: handler of the xattr_handler operation
* @name: name passed to the xattr_handler operation
*
* The get and set xattr handler operations are called with the remainder of
* the attribute name after skipping the handler's prefix: for example, "foo"
* is passed to the get operation of a handler with prefix "user." to get
* attribute "user.foo". The full name is still "there" in the name though.
*
* Note: the list xattr handler operation when called from the vfs is passed a
* NULL name; some file systems use this operation internally, with varying
* semantics.
*/
const char *xattr_full_name(const struct xattr_handler *handler,
const char *name)
{
size_t prefix_len = strlen(handler->prefix);
return name - prefix_len;
}
EXPORT_SYMBOL(xattr_full_name);
/* /*
* Allocate new xattr and copy in the value; but leave the name to callers. * Allocate new xattr and copy in the value; but leave the name to callers.
*/ */
......
...@@ -32,9 +32,10 @@ ...@@ -32,9 +32,10 @@
static int static int
xfs_xattr_get(struct dentry *dentry, const char *name, xfs_xattr_get(const struct xattr_handler *handler, struct dentry *dentry,
void *value, size_t size, int xflags) const char *name, void *value, size_t size)
{ {
int xflags = handler->flags;
struct xfs_inode *ip = XFS_I(d_inode(dentry)); struct xfs_inode *ip = XFS_I(d_inode(dentry));
int error, asize = size; int error, asize = size;
...@@ -76,9 +77,10 @@ xfs_forget_acl( ...@@ -76,9 +77,10 @@ xfs_forget_acl(
} }
static int static int
xfs_xattr_set(struct dentry *dentry, const char *name, const void *value, xfs_xattr_set(const struct xattr_handler *handler, struct dentry *dentry,
size_t size, int flags, int xflags) const char *name, const void *value, size_t size, int flags)
{ {
int xflags = handler->flags;
struct xfs_inode *ip = XFS_I(d_inode(dentry)); struct xfs_inode *ip = XFS_I(d_inode(dentry));
int error; int error;
......
...@@ -21,15 +21,19 @@ struct dentry; ...@@ -21,15 +21,19 @@ struct dentry;
struct xattr_handler { struct xattr_handler {
const char *prefix; const char *prefix;
int flags; /* fs private flags passed back to the handlers */ int flags; /* fs private flags */
size_t (*list)(struct dentry *dentry, char *list, size_t list_size, size_t (*list)(const struct xattr_handler *, struct dentry *dentry,
const char *name, size_t name_len, int handler_flags); char *list, size_t list_size, const char *name,
int (*get)(struct dentry *dentry, const char *name, void *buffer, size_t name_len);
size_t size, int handler_flags); int (*get)(const struct xattr_handler *, struct dentry *dentry,
int (*set)(struct dentry *dentry, const char *name, const void *buffer, const char *name, void *buffer, size_t size);
size_t size, int flags, int handler_flags); int (*set)(const struct xattr_handler *, struct dentry *dentry,
const char *name, const void *buffer, size_t size,
int flags);
}; };
const char *xattr_full_name(const struct xattr_handler *, const char *);
struct xattr { struct xattr {
const char *name; const char *name;
void *value; void *value;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment