2 * Copyright (C) 2007 Red Hat. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
20 #include <linux/string.h>
21 #include <linux/xattr.h>
22 #include <linux/posix_acl_xattr.h>
25 #ifndef is_owner_or_cap
26 #define is_owner_or_cap(inode) \
27 ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER))
30 static int btrfs_xattr_set_acl(struct inode *inode, int type,
31 const void *value, size_t size)
34 struct posix_acl *acl;
36 if (!is_owner_or_cap(inode))
39 acl = posix_acl_from_xattr(value, size);
43 } else if (IS_ERR(acl)) {
46 ret = posix_acl_valid(acl);
47 posix_acl_release(acl);
52 return btrfs_xattr_set(inode, type, "", value, size, 0);
55 static int btrfs_xattr_get_acl(struct inode *inode, int type,
56 void *value, size_t size)
58 return btrfs_xattr_get(inode, type, "", value, size);
60 static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name,
61 void *value, size_t size)
65 return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
68 static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name,
69 const void *value, size_t size, int flags)
73 return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
76 static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name,
77 void *value, size_t size)
81 return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
84 static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name,
85 const void *value, size_t size, int flags)
89 return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
92 struct xattr_handler btrfs_xattr_acl_default_handler = {
93 .prefix = POSIX_ACL_XATTR_DEFAULT,
94 .list = btrfs_xattr_generic_list,
95 .get = btrfs_xattr_acl_default_get,
96 .set = btrfs_xattr_acl_default_set,
99 struct xattr_handler btrfs_xattr_acl_access_handler = {
100 .prefix = POSIX_ACL_XATTR_ACCESS,
101 .list = btrfs_xattr_generic_list,
102 .get = btrfs_xattr_acl_access_get,
103 .set = btrfs_xattr_acl_access_set,