posix_acl.c 2.31 KB
Newer Older
J. R. Okajima's avatar
J. R. Okajima committed
1
2
3
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2014-2019 Junjiro R. Okajima
4
5
6
7
8
9
10
11
12
13
14
15
16
 *
 * This program, aufs is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
J. R. Okajima's avatar
J. R. Okajima committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 */

/*
 * posix acl operations
 */

#include <linux/fs.h>
#include "aufs.h"

struct posix_acl *aufs_get_acl(struct inode *inode, int type)
{
	struct posix_acl *acl;
	int err;
	aufs_bindex_t bindex;
	struct inode *h_inode;
	struct super_block *sb;

	acl = NULL;
	sb = inode->i_sb;
	si_read_lock(sb, AuLock_FLUSH);
	ii_read_lock_child(inode);
	if (!(sb->s_flags & SB_POSIXACL))
		goto out;

	bindex = au_ibtop(inode);
	h_inode = au_h_iptr(inode, bindex);
	if (unlikely(!h_inode
		     || ((h_inode->i_mode & S_IFMT)
			 != (inode->i_mode & S_IFMT)))) {
		err = au_busy_or_stale();
		acl = ERR_PTR(err);
		goto out;
	}

	/* always topmost only */
	acl = get_acl(h_inode, type);
53
54
55
	if (IS_ERR(acl))
		forget_cached_acl(inode, type);
	else
J. R. Okajima's avatar
J. R. Okajima committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
		set_cached_acl(inode, type, acl);

out:
	ii_read_unlock(inode);
	si_read_unlock(sb);

	AuTraceErrPtr(acl);
	return acl;
}

int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
{
	int err;
	ssize_t ssz;
	struct dentry *dentry;
	struct au_sxattr arg = {
		.type = AU_ACL_SET,
		.u.acl_set = {
			.acl	= acl,
			.type	= type
		},
	};

	IMustLock(inode);

	if (inode->i_ino == AUFS_ROOT_INO)
		dentry = dget(inode->i_sb->s_root);
	else {
		dentry = d_find_alias(inode);
		if (!dentry)
			dentry = d_find_any_alias(inode);
		if (!dentry) {
			pr_warn("cannot handle this inode, "
				"please report to aufs-users ML\n");
			err = -ENOENT;
			goto out;
		}
	}

	ssz = au_sxattr(dentry, inode, &arg);
96
97
	/* forget even it if succeeds since the branch might set differently */
	forget_cached_acl(inode, type);
J. R. Okajima's avatar
J. R. Okajima committed
98
99
	dput(dentry);
	err = ssz;
100
	if (ssz >= 0)
J. R. Okajima's avatar
J. R. Okajima committed
101
102
103
104
105
		err = 0;

out:
	return err;
}