blob: b4f85ebe1bd6fa154746bc6cf1277b3fa1e3c811 [file] [log] [blame]
Josef Bacik5103e942007-11-16 11:45:54 -05001/*
2 * Copyright (C) 2007 Red Hat. All rights reserved.
3 *
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.
7 *
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.
12 *
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.
17 */
18
19#include <linux/fs.h>
20#include <linux/string.h>
21#include <linux/xattr.h>
22#include <linux/posix_acl_xattr.h>
23#include "ctree.h"
24#include "xattr.h"
Yan744f52f2008-01-14 13:26:08 -050025static int btrfs_xattr_set_acl(struct inode *inode, int type,
26 const void *value, size_t size)
27{
28 int ret = 0;
29 struct posix_acl *acl;
Josef Bacik5103e942007-11-16 11:45:54 -050030
Yan744f52f2008-01-14 13:26:08 -050031 if (!is_owner_or_cap(inode))
32 return -EPERM;
33 if (value) {
34 acl = posix_acl_from_xattr(value, size);
35 if (acl == NULL) {
36 value = NULL;
37 size = 0;
38 } else if (IS_ERR(acl)) {
39 ret = PTR_ERR(acl);
40 } else {
41 ret = posix_acl_valid(acl);
42 posix_acl_release(acl);
43 }
44 if (ret)
45 return ret;
46 }
47 return btrfs_xattr_set(inode, type, "", value, size, 0);
48}
Josef Bacik1caf9342007-11-19 10:18:17 -050049
Yan744f52f2008-01-14 13:26:08 -050050static int btrfs_xattr_get_acl(struct inode *inode, int type,
51 void *value, size_t size)
52{
53 return btrfs_xattr_get(inode, type, "", value, size);
54}
Josef Bacik5103e942007-11-16 11:45:54 -050055static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name,
56 void *value, size_t size)
57{
Yan744f52f2008-01-14 13:26:08 -050058 if (*name != '\0')
59 return -EINVAL;
60 return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
61 value, size);
Josef Bacik5103e942007-11-16 11:45:54 -050062}
Josef Bacik5103e942007-11-16 11:45:54 -050063static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name,
64 const void *value, size_t size, int flags)
65{
Yan744f52f2008-01-14 13:26:08 -050066 if (*name != '\0')
67 return -EINVAL;
68 return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
69 value, size);
Josef Bacik5103e942007-11-16 11:45:54 -050070}
Josef Bacik5103e942007-11-16 11:45:54 -050071static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name,
72 void *value, size_t size)
73{
Yan744f52f2008-01-14 13:26:08 -050074 if (*name != '\0')
75 return -EINVAL;
76 return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
77 value, size);
Josef Bacik5103e942007-11-16 11:45:54 -050078}
Josef Bacik5103e942007-11-16 11:45:54 -050079static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name,
80 const void *value, size_t size, int flags)
81{
Yan744f52f2008-01-14 13:26:08 -050082 if (*name != '\0')
83 return -EINVAL;
84 return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
85 value, size);
Josef Bacik5103e942007-11-16 11:45:54 -050086}
Josef Bacik5103e942007-11-16 11:45:54 -050087struct xattr_handler btrfs_xattr_acl_default_handler = {
88 .prefix = POSIX_ACL_XATTR_DEFAULT,
89 .list = btrfs_xattr_generic_list,
90 .get = btrfs_xattr_acl_default_get,
91 .set = btrfs_xattr_acl_default_set,
92};
93
94struct xattr_handler btrfs_xattr_acl_access_handler = {
95 .prefix = POSIX_ACL_XATTR_ACCESS,
96 .list = btrfs_xattr_generic_list,
97 .get = btrfs_xattr_acl_access_get,
98 .set = btrfs_xattr_acl_access_set,
99};