2 * Copyright IBM Corporation, 2010
3 * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2.1 of the GNU Lesser General Public License
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 #include <linux/module.h>
17 #include <net/9p/9p.h>
18 #include <net/9p/client.h>
19 #include <linux/slab.h>
20 #include <linux/posix_acl_xattr.h>
24 static struct posix_acl *__v9fs_get_acl(struct p9_fid *fid, char *name)
28 struct posix_acl *acl = NULL;;
30 size = v9fs_fid_xattr_get(fid, name, NULL, 0);
32 value = kzalloc(size, GFP_NOFS);
34 return ERR_PTR(-ENOMEM);
35 size = v9fs_fid_xattr_get(fid, name, value, size);
37 acl = posix_acl_from_xattr(value, size);
41 } else if (size == -ENODATA || size == 0 ||
42 size == -ENOSYS || size == -EOPNOTSUPP) {
52 int v9fs_get_acl(struct inode *inode, struct p9_fid *fid)
55 struct posix_acl *pacl, *dacl;
57 /* get the default/access acl values and cache them */
58 dacl = __v9fs_get_acl(fid, POSIX_ACL_XATTR_DEFAULT);
59 pacl = __v9fs_get_acl(fid, POSIX_ACL_XATTR_ACCESS);
61 if (!IS_ERR(dacl) && !IS_ERR(pacl)) {
62 set_cached_acl(inode, ACL_TYPE_DEFAULT, dacl);
63 set_cached_acl(inode, ACL_TYPE_ACCESS, pacl);
64 posix_acl_release(dacl);
65 posix_acl_release(pacl);
72 static struct posix_acl *v9fs_get_cached_acl(struct inode *inode, int type)
74 struct posix_acl *acl;
76 * 9p Always cache the acl value when
77 * instantiating the inode (v9fs_inode_from_fid)
79 acl = get_cached_acl(inode, type);
80 BUG_ON(acl == ACL_NOT_CACHED);
84 int v9fs_check_acl(struct inode *inode, int mask)
86 struct posix_acl *acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
91 int error = posix_acl_permission(inode, acl, mask);
92 posix_acl_release(acl);