]>
Commit | Line | Data |
---|---|---|
e14748e8 SF |
1 | /* |
2 | * Copyright (C) 2014-2016 Junjiro R. Okajima | |
3 | * | |
4 | * This program, aufs is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
18 | /* | |
19 | * posix acl operations | |
20 | */ | |
21 | ||
22 | #include <linux/fs.h> | |
23 | #include "aufs.h" | |
24 | ||
25 | struct posix_acl *aufs_get_acl(struct inode *inode, int type) | |
26 | { | |
27 | struct posix_acl *acl; | |
28 | int err; | |
29 | aufs_bindex_t bindex; | |
30 | struct inode *h_inode; | |
31 | struct super_block *sb; | |
32 | ||
33 | acl = NULL; | |
34 | sb = inode->i_sb; | |
35 | si_read_lock(sb, AuLock_FLUSH); | |
36 | ii_read_lock_child(inode); | |
37 | if (!(sb->s_flags & MS_POSIXACL)) | |
38 | goto out; | |
39 | ||
40 | bindex = au_ibtop(inode); | |
41 | h_inode = au_h_iptr(inode, bindex); | |
42 | if (unlikely(!h_inode | |
43 | || ((h_inode->i_mode & S_IFMT) | |
44 | != (inode->i_mode & S_IFMT)))) { | |
45 | err = au_busy_or_stale(); | |
46 | acl = ERR_PTR(err); | |
47 | goto out; | |
48 | } | |
49 | ||
50 | /* always topmost only */ | |
51 | acl = get_acl(h_inode, type); | |
52 | if (!IS_ERR_OR_NULL(acl)) | |
53 | set_cached_acl(inode, type, acl); | |
54 | ||
55 | out: | |
56 | ii_read_unlock(inode); | |
57 | si_read_unlock(sb); | |
58 | ||
59 | AuTraceErrPtr(acl); | |
60 | return acl; | |
61 | } | |
62 | ||
63 | int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |
64 | { | |
65 | int err; | |
66 | ssize_t ssz; | |
67 | struct dentry *dentry; | |
68 | struct au_sxattr arg = { | |
69 | .type = AU_ACL_SET, | |
70 | .u.acl_set = { | |
71 | .acl = acl, | |
72 | .type = type | |
73 | }, | |
74 | }; | |
75 | ||
76 | IMustLock(inode); | |
77 | ||
78 | if (inode->i_ino == AUFS_ROOT_INO) | |
79 | dentry = dget(inode->i_sb->s_root); | |
80 | else { | |
81 | dentry = d_find_alias(inode); | |
82 | if (!dentry) | |
83 | dentry = d_find_any_alias(inode); | |
84 | if (!dentry) { | |
85 | pr_warn("cannot handle this inode, " | |
86 | "please report to aufs-users ML\n"); | |
87 | err = -ENOENT; | |
88 | goto out; | |
89 | } | |
90 | } | |
91 | ||
92 | ssz = au_sxattr(dentry, inode, &arg); | |
93 | dput(dentry); | |
94 | err = ssz; | |
95 | if (ssz >= 0) { | |
96 | err = 0; | |
97 | set_cached_acl(inode, type, acl); | |
98 | } | |
99 | ||
100 | out: | |
101 | return err; | |
102 | } |