Skip to content

Commit b0a7ab5

Browse files
Christoph HellwigAl Viro
authored andcommitted
hfsplus: use generic posix ACL infrastructure
Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Vyacheslav Dubeyko <slava@dubeyko.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a6dda0e commit b0a7ab5

File tree

6 files changed

+26
-162
lines changed

6 files changed

+26
-162
lines changed

fs/hfsplus/acl.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212

1313
/* posix_acl.c */
1414
struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type);
15-
extern int hfsplus_posix_acl_chmod(struct inode *);
15+
int hfsplus_set_posix_acl(struct inode *inode, struct posix_acl *acl,
16+
int type);
1617
extern int hfsplus_init_posix_acl(struct inode *, struct inode *);
1718

1819
#else /* CONFIG_HFSPLUS_FS_POSIX_ACL */
1920
#define hfsplus_get_posix_acl NULL
20-
21-
static inline int hfsplus_posix_acl_chmod(struct inode *inode)
22-
{
23-
return 0;
24-
}
21+
#define hfsplus_set_posix_acl NULL
2522

2623
static inline int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
2724
{

fs/hfsplus/dir.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ const struct inode_operations hfsplus_dir_inode_operations = {
532532
.removexattr = hfsplus_removexattr,
533533
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
534534
.get_acl = hfsplus_get_posix_acl,
535+
.set_acl = hfsplus_set_posix_acl,
535536
#endif
536537
};
537538

fs/hfsplus/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)
319319
mark_inode_dirty(inode);
320320

321321
if (attr->ia_valid & ATTR_MODE) {
322-
error = hfsplus_posix_acl_chmod(inode);
322+
error = posix_acl_chmod(inode, inode->i_mode);
323323
if (unlikely(error))
324324
return error;
325325
}
@@ -393,6 +393,7 @@ static const struct inode_operations hfsplus_file_inode_operations = {
393393
.removexattr = hfsplus_removexattr,
394394
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
395395
.get_acl = hfsplus_get_posix_acl,
396+
.set_acl = hfsplus_set_posix_acl,
396397
#endif
397398
};
398399

fs/hfsplus/posix_acl.c

Lines changed: 17 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type)
1717
char *value = NULL;
1818
ssize_t size;
1919

20-
acl = get_cached_acl(inode, type);
21-
if (acl != ACL_NOT_CACHED)
22-
return acl;
20+
hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
2321

2422
switch (type) {
2523
case ACL_TYPE_ACCESS:
@@ -56,17 +54,15 @@ struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type)
5654
return acl;
5755
}
5856

59-
static int hfsplus_set_posix_acl(struct inode *inode,
60-
int type,
61-
struct posix_acl *acl)
57+
int hfsplus_set_posix_acl(struct inode *inode, struct posix_acl *acl,
58+
int type)
6259
{
6360
int err;
6461
char *xattr_name;
6562
size_t size = 0;
6663
char *value = NULL;
6764

68-
if (S_ISLNK(inode->i_mode))
69-
return -EOPNOTSUPP;
65+
hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
7066

7167
switch (type) {
7268
case ACL_TYPE_ACCESS:
@@ -115,7 +111,7 @@ static int hfsplus_set_posix_acl(struct inode *inode,
115111
int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
116112
{
117113
int err = 0;
118-
struct posix_acl *acl = NULL;
114+
struct posix_acl *default_acl, *acl;
119115

120116
hfs_dbg(ACL_MOD,
121117
"[%s]: ino %lu, dir->ino %lu\n",
@@ -124,151 +120,21 @@ int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
124120
if (S_ISLNK(inode->i_mode))
125121
return 0;
126122

127-
acl = hfsplus_get_posix_acl(dir, ACL_TYPE_DEFAULT);
128-
if (IS_ERR(acl))
129-
return PTR_ERR(acl);
130-
131-
if (acl) {
132-
if (S_ISDIR(inode->i_mode)) {
133-
err = hfsplus_set_posix_acl(inode,
134-
ACL_TYPE_DEFAULT,
135-
acl);
136-
if (unlikely(err))
137-
goto init_acl_cleanup;
138-
}
139-
140-
err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
141-
if (unlikely(err < 0))
142-
return err;
143-
144-
if (err > 0)
145-
err = hfsplus_set_posix_acl(inode,
146-
ACL_TYPE_ACCESS,
147-
acl);
148-
} else
149-
inode->i_mode &= ~current_umask();
150-
151-
init_acl_cleanup:
152-
posix_acl_release(acl);
153-
return err;
154-
}
155-
156-
int hfsplus_posix_acl_chmod(struct inode *inode)
157-
{
158-
int err;
159-
struct posix_acl *acl;
160-
161-
hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
162-
163-
if (S_ISLNK(inode->i_mode))
164-
return -EOPNOTSUPP;
165-
166-
acl = hfsplus_get_posix_acl(inode, ACL_TYPE_ACCESS);
167-
if (IS_ERR(acl) || !acl)
168-
return PTR_ERR(acl);
169-
170-
err = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
171-
if (unlikely(err))
123+
err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
124+
if (err)
172125
return err;
173126

174-
err = hfsplus_set_posix_acl(inode, ACL_TYPE_ACCESS, acl);
175-
posix_acl_release(acl);
176-
return err;
177-
}
178-
179-
static int hfsplus_xattr_get_posix_acl(struct dentry *dentry,
180-
const char *name,
181-
void *buffer,
182-
size_t size,
183-
int type)
184-
{
185-
int err = 0;
186-
struct posix_acl *acl;
187-
188-
hfs_dbg(ACL_MOD,
189-
"[%s]: ino %lu, buffer %p, size %zu, type %#x\n",
190-
__func__, dentry->d_inode->i_ino, buffer, size, type);
191-
192-
if (strcmp(name, "") != 0)
193-
return -EINVAL;
194-
195-
acl = hfsplus_get_posix_acl(dentry->d_inode, type);
196-
if (IS_ERR(acl))
197-
return PTR_ERR(acl);
198-
if (acl == NULL)
199-
return -ENODATA;
200-
201-
err = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
202-
posix_acl_release(acl);
203-
204-
return err;
205-
}
206-
207-
static int hfsplus_xattr_set_posix_acl(struct dentry *dentry,
208-
const char *name,
209-
const void *value,
210-
size_t size,
211-
int flags,
212-
int type)
213-
{
214-
int err = 0;
215-
struct inode *inode = dentry->d_inode;
216-
struct posix_acl *acl = NULL;
217-
218-
hfs_dbg(ACL_MOD,
219-
"[%s]: ino %lu, value %p, size %zu, flags %#x, type %#x\n",
220-
__func__, inode->i_ino, value, size, flags, type);
221-
222-
if (strcmp(name, "") != 0)
223-
return -EINVAL;
224-
225-
if (!inode_owner_or_capable(inode))
226-
return -EPERM;
227-
228-
if (value) {
229-
acl = posix_acl_from_xattr(&init_user_ns, value, size);
230-
if (IS_ERR(acl))
231-
return PTR_ERR(acl);
232-
else if (acl) {
233-
err = posix_acl_valid(acl);
234-
if (err)
235-
goto end_xattr_set_acl;
236-
}
127+
if (default_acl) {
128+
err = hfsplus_set_posix_acl(inode, default_acl,
129+
ACL_TYPE_DEFAULT);
130+
posix_acl_release(default_acl);
237131
}
238132

239-
err = hfsplus_set_posix_acl(inode, type, acl);
240-
241-
end_xattr_set_acl:
242-
posix_acl_release(acl);
133+
if (acl) {
134+
if (!err)
135+
err = hfsplus_set_posix_acl(inode, acl,
136+
ACL_TYPE_ACCESS);
137+
posix_acl_release(acl);
138+
}
243139
return err;
244140
}
245-
246-
static size_t hfsplus_xattr_list_posix_acl(struct dentry *dentry,
247-
char *list,
248-
size_t list_size,
249-
const char *name,
250-
size_t name_len,
251-
int type)
252-
{
253-
/*
254-
* This method is not used.
255-
* It is used hfsplus_listxattr() instead of generic_listxattr().
256-
*/
257-
return -EOPNOTSUPP;
258-
}
259-
260-
const struct xattr_handler hfsplus_xattr_acl_access_handler = {
261-
.prefix = POSIX_ACL_XATTR_ACCESS,
262-
.flags = ACL_TYPE_ACCESS,
263-
.list = hfsplus_xattr_list_posix_acl,
264-
.get = hfsplus_xattr_get_posix_acl,
265-
.set = hfsplus_xattr_set_posix_acl,
266-
};
267-
268-
const struct xattr_handler hfsplus_xattr_acl_default_handler = {
269-
.prefix = POSIX_ACL_XATTR_DEFAULT,
270-
.flags = ACL_TYPE_DEFAULT,
271-
.list = hfsplus_xattr_list_posix_acl,
272-
.get = hfsplus_xattr_get_posix_acl,
273-
.set = hfsplus_xattr_set_posix_acl,
274-
};

fs/hfsplus/xattr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "hfsplus_fs.h"
10+
#include <linux/posix_acl_xattr.h>
1011
#include "xattr.h"
1112
#include "acl.h"
1213

@@ -15,8 +16,8 @@ const struct xattr_handler *hfsplus_xattr_handlers[] = {
1516
&hfsplus_xattr_user_handler,
1617
&hfsplus_xattr_trusted_handler,
1718
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
18-
&hfsplus_xattr_acl_access_handler,
19-
&hfsplus_xattr_acl_default_handler,
19+
&posix_acl_access_xattr_handler,
20+
&posix_acl_default_xattr_handler,
2021
#endif
2122
&hfsplus_xattr_security_handler,
2223
NULL

fs/hfsplus/xattr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
extern const struct xattr_handler hfsplus_xattr_osx_handler;
1515
extern const struct xattr_handler hfsplus_xattr_user_handler;
1616
extern const struct xattr_handler hfsplus_xattr_trusted_handler;
17-
extern const struct xattr_handler hfsplus_xattr_acl_access_handler;
18-
extern const struct xattr_handler hfsplus_xattr_acl_default_handler;
1917
extern const struct xattr_handler hfsplus_xattr_security_handler;
2018

2119
extern const struct xattr_handler *hfsplus_xattr_handlers[];

0 commit comments

Comments
 (0)