]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/btrfs/acl.c
Btrfs: Add basic lockfs calls
[net-next-2.6.git] / fs / btrfs / acl.c
CommitLineData
5103e947
JB
1/*
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"
fb4bc1e0
Y
25#ifndef is_owner_or_cap
26#define is_owner_or_cap(inode) \
27 ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER))
28#endif
29
744f52f9
Y
30static int btrfs_xattr_set_acl(struct inode *inode, int type,
31 const void *value, size_t size)
32{
33 int ret = 0;
34 struct posix_acl *acl;
5103e947 35
744f52f9
Y
36 if (!is_owner_or_cap(inode))
37 return -EPERM;
38 if (value) {
39 acl = posix_acl_from_xattr(value, size);
40 if (acl == NULL) {
41 value = NULL;
42 size = 0;
43 } else if (IS_ERR(acl)) {
44 ret = PTR_ERR(acl);
45 } else {
46 ret = posix_acl_valid(acl);
47 posix_acl_release(acl);
48 }
49 if (ret)
50 return ret;
51 }
52 return btrfs_xattr_set(inode, type, "", value, size, 0);
53}
1caf9342 54
744f52f9
Y
55static int btrfs_xattr_get_acl(struct inode *inode, int type,
56 void *value, size_t size)
57{
58 return btrfs_xattr_get(inode, type, "", value, size);
59}
5103e947
JB
60static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name,
61 void *value, size_t size)
62{
744f52f9
Y
63 if (*name != '\0')
64 return -EINVAL;
65 return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
66 value, size);
5103e947 67}
5103e947
JB
68static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name,
69 const void *value, size_t size, int flags)
70{
744f52f9
Y
71 if (*name != '\0')
72 return -EINVAL;
73 return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_ACCESS,
74 value, size);
5103e947 75}
5103e947
JB
76static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name,
77 void *value, size_t size)
78{
744f52f9
Y
79 if (*name != '\0')
80 return -EINVAL;
81 return btrfs_xattr_get_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
82 value, size);
5103e947 83}
5103e947
JB
84static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name,
85 const void *value, size_t size, int flags)
86{
744f52f9
Y
87 if (*name != '\0')
88 return -EINVAL;
89 return btrfs_xattr_set_acl(inode, BTRFS_XATTR_INDEX_POSIX_ACL_DEFAULT,
90 value, size);
5103e947 91}
5103e947
JB
92struct 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,
97};
98
99struct 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,
104};