Commit 744f52f9 authored by Yan's avatar Yan Committed by Chris Mason

Btrfs: Implement ACLs setting and getting

ACLs are stored but not used for permission checks (yet)
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent b3a0d8d2
...@@ -22,53 +22,68 @@ ...@@ -22,53 +22,68 @@
#include <linux/posix_acl_xattr.h> #include <linux/posix_acl_xattr.h>
#include "ctree.h" #include "ctree.h"
#include "xattr.h" #include "xattr.h"
static int btrfs_xattr_set_acl(struct inode *inode, int type,
const void *value, size_t size)
{
int ret = 0;
struct posix_acl *acl;
/* if (!is_owner_or_cap(inode))
* FIXME: At this point this is all place holder stuff, we just return return -EPERM;
* -EOPNOTSUPP so cp won't complain when it tries to copy over a file with an if (value) {
* acl on it. acl = posix_acl_from_xattr(value, size);
*/ if (acl == NULL) {
value = NULL;
size = 0;
} else if (IS_ERR(acl)) {
ret = PTR_ERR(acl);
} else {
ret = posix_acl_valid(acl);
posix_acl_release(acl);
}
if (ret)
return ret;
}
return btrfs_xattr_set(inode, type, "", value, size, 0);
}
static int btrfs_xattr_get_acl(struct inode *inode, int type,
void *value, size_t size)
{
return btrfs_xattr_get(inode, type, "", value, size);
}
static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name, static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name,
void *value, size_t size) void *value, size_t size)
{ {
/* if (*name != '\0')
return btrfs_xattr_get(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS, name, return -EINVAL;
return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
value, size); value, size);
*/
return -EOPNOTSUPP;
} }
static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name, static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
/* if (*name != '\0')
return btrfs_xattr_set(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS, name, return -EINVAL;
value, size, flags); return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
*/ value, size);
return -EOPNOTSUPP;
} }
static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name, static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name,
void *value, size_t size) void *value, size_t size)
{ {
/* if (*name != '\0')
return btrfs_xattr_get(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT, return -EINVAL;
name, value, size); return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
*/ value, size);
return -EOPNOTSUPP;
} }
static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name, static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
/* if (*name != '\0')
return btrfs_xattr_set(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT, return -EINVAL;
name, value, size, flags); return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
*/ value, size);
return -EOPNOTSUPP;
} }
struct xattr_handler btrfs_xattr_acl_default_handler = { struct xattr_handler btrfs_xattr_acl_default_handler = {
.prefix = POSIX_ACL_XATTR_DEFAULT, .prefix = POSIX_ACL_XATTR_DEFAULT,
.list = btrfs_xattr_generic_list, .list = btrfs_xattr_generic_list,
......
...@@ -76,6 +76,9 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, ...@@ -76,6 +76,9 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
if (name_len + data_len + sizeof(struct btrfs_dir_item) >
BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item))
return -ENOSPC;
data_size = sizeof(*dir_item) + name_len + data_len; data_size = sizeof(*dir_item) + name_len + data_len;
dir_item = insert_with_overflow(trans, root, path, &key, data_size, dir_item = insert_with_overflow(trans, root, path, &key, data_size,
......
...@@ -141,11 +141,6 @@ ssize_t btrfs_xattr_get(struct inode *inode, int name_index, ...@@ -141,11 +141,6 @@ ssize_t btrfs_xattr_get(struct inode *inode, int name_index,
if (!handler) if (!handler)
return -EOPNOTSUPP; return -EOPNOTSUPP;
/* just in case... */
if (*attr_name == '\0')
return -EINVAL;
name = get_name(attr_name, name_index); name = get_name(attr_name, name_index);
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
...@@ -201,14 +196,8 @@ int btrfs_xattr_set(struct inode *inode, int name_index, ...@@ -201,14 +196,8 @@ int btrfs_xattr_set(struct inode *inode, int name_index,
struct xattr_handler *handler = btrfs_xattr_handler(name_index); struct xattr_handler *handler = btrfs_xattr_handler(name_index);
char *name; char *name;
int ret = 0, mod = 0; int ret = 0, mod = 0;
if (!handler) if (!handler)
return -EOPNOTSUPP; return -EOPNOTSUPP;
/* just in case... */
if (*attr_name == '\0')
return -EINVAL;
name = get_name(attr_name, name_index); name = get_name(attr_name, name_index);
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
...@@ -454,15 +443,18 @@ static int btrfs_xattr_##name##_get(struct inode *inode, \ ...@@ -454,15 +443,18 @@ static int btrfs_xattr_##name##_get(struct inode *inode, \
const char *name, void *value, \ const char *name, void *value, \
size_t size) \ size_t size) \
{ \ { \
if (*name == '\0') \
return -EINVAL; \
return btrfs_xattr_get(inode, index, name, value, size); \ return btrfs_xattr_get(inode, index, name, value, size); \
} \ } \
static int btrfs_xattr_##name##_set(struct inode *inode, \ static int btrfs_xattr_##name##_set(struct inode *inode, \
const char *name, const void *value,\ const char *name, const void *value,\
size_t size, int flags) \ size_t size, int flags) \
{ \ { \
if (*name == '\0') \
return -EINVAL; \
return btrfs_xattr_set(inode, index, name, value, size, flags); \ return btrfs_xattr_set(inode, index, name, value, size, flags); \
} \ } \
BTRFS_XATTR_SETGET_FUNCS(security, BTRFS_XATTR_INDEX_SECURITY); BTRFS_XATTR_SETGET_FUNCS(security, BTRFS_XATTR_INDEX_SECURITY);
BTRFS_XATTR_SETGET_FUNCS(system, BTRFS_XATTR_INDEX_SYSTEM); BTRFS_XATTR_SETGET_FUNCS(system, BTRFS_XATTR_INDEX_SYSTEM);
BTRFS_XATTR_SETGET_FUNCS(user, BTRFS_XATTR_INDEX_USER); BTRFS_XATTR_SETGET_FUNCS(user, BTRFS_XATTR_INDEX_USER);
......
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