mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
Merge branch 'work.xattr' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs xattr updates from Al Viro: "Andreas' xattr cleanup series. It's a followup to his xattr work that went in last cycle; -0.5KLoC" * 'work.xattr' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: xattr handlers: Simplify list operation ocfs2: Replace list xattr handler operations nfs: Move call to security_inode_listsecurity into nfs_listxattr xfs: Change how listxattr generates synthetic attributes tmpfs: listxattr should include POSIX ACL xattrs tmpfs: Use xattr handler infrastructure btrfs: Use xattr handler infrastructure vfs: Distinguish between full xattr names and proper prefixes posix acls: Remove duplicate xattr name definitions gfs2: Remove gfs2_xattr_acl_chmod vfs: Remove vfs_xattr_cmp
This commit is contained in:
commit
ddf1d6238d
49 changed files with 516 additions and 1054 deletions
|
|
@ -37,10 +37,10 @@ struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
|
|||
|
||||
switch (type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
name = POSIX_ACL_XATTR_ACCESS;
|
||||
name = XATTR_NAME_POSIX_ACL_ACCESS;
|
||||
break;
|
||||
case ACL_TYPE_DEFAULT:
|
||||
name = POSIX_ACL_XATTR_DEFAULT;
|
||||
name = XATTR_NAME_POSIX_ACL_DEFAULT;
|
||||
break;
|
||||
default:
|
||||
BUG();
|
||||
|
|
@ -81,7 +81,7 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
|
|||
|
||||
switch (type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
name = POSIX_ACL_XATTR_ACCESS;
|
||||
name = XATTR_NAME_POSIX_ACL_ACCESS;
|
||||
if (acl) {
|
||||
ret = posix_acl_equiv_mode(acl, &inode->i_mode);
|
||||
if (ret < 0)
|
||||
|
|
@ -94,7 +94,7 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
|
|||
case ACL_TYPE_DEFAULT:
|
||||
if (!S_ISDIR(inode->i_mode))
|
||||
return acl ? -EINVAL : 0;
|
||||
name = POSIX_ACL_XATTR_DEFAULT;
|
||||
name = XATTR_NAME_POSIX_ACL_DEFAULT;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
|
|
|
|||
|
|
@ -3550,10 +3550,10 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
|
|||
int scanned = 0;
|
||||
|
||||
if (!xattr_access) {
|
||||
xattr_access = btrfs_name_hash(POSIX_ACL_XATTR_ACCESS,
|
||||
strlen(POSIX_ACL_XATTR_ACCESS));
|
||||
xattr_default = btrfs_name_hash(POSIX_ACL_XATTR_DEFAULT,
|
||||
strlen(POSIX_ACL_XATTR_DEFAULT));
|
||||
xattr_access = btrfs_name_hash(XATTR_NAME_POSIX_ACL_ACCESS,
|
||||
strlen(XATTR_NAME_POSIX_ACL_ACCESS));
|
||||
xattr_default = btrfs_name_hash(XATTR_NAME_POSIX_ACL_DEFAULT,
|
||||
strlen(XATTR_NAME_POSIX_ACL_DEFAULT));
|
||||
}
|
||||
|
||||
slot++;
|
||||
|
|
@ -9996,7 +9996,7 @@ static const struct inode_operations btrfs_dir_inode_operations = {
|
|||
.setattr = btrfs_setattr,
|
||||
.mknod = btrfs_mknod,
|
||||
.setxattr = btrfs_setxattr,
|
||||
.getxattr = btrfs_getxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = btrfs_listxattr,
|
||||
.removexattr = btrfs_removexattr,
|
||||
.permission = btrfs_permission,
|
||||
|
|
@ -10073,7 +10073,7 @@ static const struct inode_operations btrfs_file_inode_operations = {
|
|||
.getattr = btrfs_getattr,
|
||||
.setattr = btrfs_setattr,
|
||||
.setxattr = btrfs_setxattr,
|
||||
.getxattr = btrfs_getxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = btrfs_listxattr,
|
||||
.removexattr = btrfs_removexattr,
|
||||
.permission = btrfs_permission,
|
||||
|
|
@ -10087,7 +10087,7 @@ static const struct inode_operations btrfs_special_inode_operations = {
|
|||
.setattr = btrfs_setattr,
|
||||
.permission = btrfs_permission,
|
||||
.setxattr = btrfs_setxattr,
|
||||
.getxattr = btrfs_getxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = btrfs_listxattr,
|
||||
.removexattr = btrfs_removexattr,
|
||||
.get_acl = btrfs_get_acl,
|
||||
|
|
@ -10101,7 +10101,7 @@ static const struct inode_operations btrfs_symlink_inode_operations = {
|
|||
.setattr = btrfs_setattr,
|
||||
.permission = btrfs_permission,
|
||||
.setxattr = btrfs_setxattr,
|
||||
.getxattr = btrfs_getxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = btrfs_listxattr,
|
||||
.removexattr = btrfs_removexattr,
|
||||
.update_time = btrfs_update_time,
|
||||
|
|
|
|||
168
fs/btrfs/xattr.c
168
fs/btrfs/xattr.c
|
|
@ -351,137 +351,89 @@ err:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* List of handlers for synthetic system.* attributes. All real ondisk
|
||||
* attributes are handled directly.
|
||||
*/
|
||||
static int btrfs_xattr_handler_get(const struct xattr_handler *handler,
|
||||
struct dentry *dentry, const char *name,
|
||||
void *buffer, size_t size)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
|
||||
name = xattr_full_name(handler, name);
|
||||
return __btrfs_getxattr(inode, name, buffer, size);
|
||||
}
|
||||
|
||||
static int btrfs_xattr_handler_set(const struct xattr_handler *handler,
|
||||
struct dentry *dentry, const char *name,
|
||||
const void *buffer, size_t size,
|
||||
int flags)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
|
||||
name = xattr_full_name(handler, name);
|
||||
return __btrfs_setxattr(NULL, inode, name, buffer, size, flags);
|
||||
}
|
||||
|
||||
static int btrfs_xattr_handler_set_prop(const struct xattr_handler *handler,
|
||||
struct dentry *dentry,
|
||||
const char *name, const void *value,
|
||||
size_t size, int flags)
|
||||
{
|
||||
name = xattr_full_name(handler, name);
|
||||
return btrfs_set_prop(d_inode(dentry), name, value, size, flags);
|
||||
}
|
||||
|
||||
static const struct xattr_handler btrfs_security_xattr_handler = {
|
||||
.prefix = XATTR_SECURITY_PREFIX,
|
||||
.get = btrfs_xattr_handler_get,
|
||||
.set = btrfs_xattr_handler_set,
|
||||
};
|
||||
|
||||
static const struct xattr_handler btrfs_trusted_xattr_handler = {
|
||||
.prefix = XATTR_TRUSTED_PREFIX,
|
||||
.get = btrfs_xattr_handler_get,
|
||||
.set = btrfs_xattr_handler_set,
|
||||
};
|
||||
|
||||
static const struct xattr_handler btrfs_user_xattr_handler = {
|
||||
.prefix = XATTR_USER_PREFIX,
|
||||
.get = btrfs_xattr_handler_get,
|
||||
.set = btrfs_xattr_handler_set,
|
||||
};
|
||||
|
||||
static const struct xattr_handler btrfs_btrfs_xattr_handler = {
|
||||
.prefix = XATTR_BTRFS_PREFIX,
|
||||
.get = btrfs_xattr_handler_get,
|
||||
.set = btrfs_xattr_handler_set_prop,
|
||||
};
|
||||
|
||||
const struct xattr_handler *btrfs_xattr_handlers[] = {
|
||||
&btrfs_security_xattr_handler,
|
||||
#ifdef CONFIG_BTRFS_FS_POSIX_ACL
|
||||
&posix_acl_access_xattr_handler,
|
||||
&posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
&btrfs_trusted_xattr_handler,
|
||||
&btrfs_user_xattr_handler,
|
||||
&btrfs_btrfs_xattr_handler,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/*
|
||||
* Check if the attribute is in a supported namespace.
|
||||
*
|
||||
* This is applied after the check for the synthetic attributes in the system
|
||||
* namespace.
|
||||
*/
|
||||
static int btrfs_is_valid_xattr(const char *name)
|
||||
{
|
||||
int len = strlen(name);
|
||||
int prefixlen = 0;
|
||||
|
||||
if (!strncmp(name, XATTR_SECURITY_PREFIX,
|
||||
XATTR_SECURITY_PREFIX_LEN))
|
||||
prefixlen = XATTR_SECURITY_PREFIX_LEN;
|
||||
else if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
||||
prefixlen = XATTR_SYSTEM_PREFIX_LEN;
|
||||
else if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
|
||||
prefixlen = XATTR_TRUSTED_PREFIX_LEN;
|
||||
else if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
|
||||
prefixlen = XATTR_USER_PREFIX_LEN;
|
||||
else if (!strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN))
|
||||
prefixlen = XATTR_BTRFS_PREFIX_LEN;
|
||||
else
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
/*
|
||||
* The name cannot consist of just prefix
|
||||
*/
|
||||
if (len <= prefixlen)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t btrfs_getxattr(struct dentry *dentry, const char *name,
|
||||
void *buffer, size_t size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* If this is a request for a synthetic attribute in the system.*
|
||||
* namespace use the generic infrastructure to resolve a handler
|
||||
* for it via sb->s_xattr.
|
||||
*/
|
||||
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
||||
return generic_getxattr(dentry, name, buffer, size);
|
||||
|
||||
ret = btrfs_is_valid_xattr(name);
|
||||
if (ret)
|
||||
return ret;
|
||||
return __btrfs_getxattr(d_inode(dentry), name, buffer, size);
|
||||
}
|
||||
|
||||
int btrfs_setxattr(struct dentry *dentry, const char *name, const void *value,
|
||||
size_t size, int flags)
|
||||
{
|
||||
struct btrfs_root *root = BTRFS_I(d_inode(dentry))->root;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* The permission on security.* and system.* is not checked
|
||||
* in permission().
|
||||
*/
|
||||
if (btrfs_root_readonly(root))
|
||||
return -EROFS;
|
||||
|
||||
/*
|
||||
* If this is a request for a synthetic attribute in the system.*
|
||||
* namespace use the generic infrastructure to resolve a handler
|
||||
* for it via sb->s_xattr.
|
||||
*/
|
||||
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
||||
return generic_setxattr(dentry, name, value, size, flags);
|
||||
|
||||
ret = btrfs_is_valid_xattr(name);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN))
|
||||
return btrfs_set_prop(d_inode(dentry), name,
|
||||
value, size, flags);
|
||||
|
||||
if (size == 0)
|
||||
value = ""; /* empty EA, do not remove */
|
||||
|
||||
return __btrfs_setxattr(NULL, d_inode(dentry), name, value, size,
|
||||
flags);
|
||||
return generic_setxattr(dentry, name, value, size, flags);
|
||||
}
|
||||
|
||||
int btrfs_removexattr(struct dentry *dentry, const char *name)
|
||||
{
|
||||
struct btrfs_root *root = BTRFS_I(d_inode(dentry))->root;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* The permission on security.* and system.* is not checked
|
||||
* in permission().
|
||||
*/
|
||||
if (btrfs_root_readonly(root))
|
||||
return -EROFS;
|
||||
|
||||
/*
|
||||
* If this is a request for a synthetic attribute in the system.*
|
||||
* namespace use the generic infrastructure to resolve a handler
|
||||
* for it via sb->s_xattr.
|
||||
*/
|
||||
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
||||
return generic_removexattr(dentry, name);
|
||||
|
||||
ret = btrfs_is_valid_xattr(name);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!strncmp(name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN))
|
||||
return btrfs_set_prop(d_inode(dentry), name,
|
||||
NULL, 0, XATTR_REPLACE);
|
||||
|
||||
return __btrfs_setxattr(NULL, d_inode(dentry), name, NULL, 0,
|
||||
XATTR_REPLACE);
|
||||
return generic_removexattr(dentry, name);
|
||||
}
|
||||
|
||||
static int btrfs_initxattrs(struct inode *inode,
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ extern ssize_t __btrfs_getxattr(struct inode *inode, const char *name,
|
|||
extern int __btrfs_setxattr(struct btrfs_trans_handle *trans,
|
||||
struct inode *inode, const char *name,
|
||||
const void *value, size_t size, int flags);
|
||||
extern ssize_t btrfs_getxattr(struct dentry *dentry, const char *name,
|
||||
void *buffer, size_t size);
|
||||
extern int btrfs_setxattr(struct dentry *dentry, const char *name,
|
||||
const void *value, size_t size, int flags);
|
||||
extern int btrfs_removexattr(struct dentry *dentry, const char *name);
|
||||
|
|
|
|||
Loading…
Reference in a new issue