Skip to content

Commit f2963d4

Browse files
Christoph HellwigAl Viro
authored andcommitted
jffs2: use generic posix ACL infrastructure
Also don't bother to set up a .get_acl method for symlinks as we do not support access control (ACLs or even mode bits) for symlinks in Linux. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent b0a7ab5 commit f2963d4

File tree

7 files changed

+24
-143
lines changed

7 files changed

+24
-143
lines changed

fs/jffs2/acl.c

Lines changed: 11 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
178178
char *value = NULL;
179179
int rc, xprefix;
180180

181-
acl = get_cached_acl(inode, type);
182-
if (acl != ACL_NOT_CACHED)
183-
return acl;
184-
185181
switch (type) {
186182
case ACL_TYPE_ACCESS:
187183
xprefix = JFFS2_XPREFIX_ACL_ACCESS;
@@ -232,13 +228,10 @@ static int __jffs2_set_acl(struct inode *inode, int xprefix, struct posix_acl *a
232228
return rc;
233229
}
234230

235-
static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
231+
int jffs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
236232
{
237233
int rc, xprefix;
238234

239-
if (S_ISLNK(inode->i_mode))
240-
return -EOPNOTSUPP;
241-
242235
switch (type) {
243236
case ACL_TYPE_ACCESS:
244237
xprefix = JFFS2_XPREFIX_ACL_ACCESS;
@@ -277,30 +270,21 @@ static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
277270

278271
int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, umode_t *i_mode)
279272
{
280-
struct posix_acl *acl;
273+
struct posix_acl *default_acl, *acl;
281274
int rc;
282275

283276
cache_no_acl(inode);
284277

285-
if (S_ISLNK(*i_mode))
286-
return 0; /* Symlink always has no-ACL */
287-
288-
acl = jffs2_get_acl(dir_i, ACL_TYPE_DEFAULT);
289-
if (IS_ERR(acl))
290-
return PTR_ERR(acl);
291-
292-
if (!acl) {
293-
*i_mode &= ~current_umask();
294-
} else {
295-
if (S_ISDIR(*i_mode))
296-
set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
297-
298-
rc = __posix_acl_create(&acl, GFP_KERNEL, i_mode);
299-
if (rc < 0)
300-
return rc;
301-
if (rc > 0)
302-
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
278+
rc = posix_acl_create(dir_i, i_mode, &default_acl, &acl);
279+
if (rc)
280+
return rc;
303281

282+
if (default_acl) {
283+
set_cached_acl(inode, ACL_TYPE_DEFAULT, default_acl);
284+
posix_acl_release(default_acl);
285+
}
286+
if (acl) {
287+
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
304288
posix_acl_release(acl);
305289
}
306290
return 0;
@@ -324,106 +308,3 @@ int jffs2_init_acl_post(struct inode *inode)
324308

325309
return 0;
326310
}
327-
328-
int jffs2_acl_chmod(struct inode *inode)
329-
{
330-
struct posix_acl *acl;
331-
int rc;
332-
333-
if (S_ISLNK(inode->i_mode))
334-
return -EOPNOTSUPP;
335-
acl = jffs2_get_acl(inode, ACL_TYPE_ACCESS);
336-
if (IS_ERR(acl) || !acl)
337-
return PTR_ERR(acl);
338-
rc = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
339-
if (rc)
340-
return rc;
341-
rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, acl);
342-
posix_acl_release(acl);
343-
return rc;
344-
}
345-
346-
static size_t jffs2_acl_access_listxattr(struct dentry *dentry, char *list,
347-
size_t list_size, const char *name, size_t name_len, int type)
348-
{
349-
const int retlen = sizeof(POSIX_ACL_XATTR_ACCESS);
350-
351-
if (list && retlen <= list_size)
352-
strcpy(list, POSIX_ACL_XATTR_ACCESS);
353-
return retlen;
354-
}
355-
356-
static size_t jffs2_acl_default_listxattr(struct dentry *dentry, char *list,
357-
size_t list_size, const char *name, size_t name_len, int type)
358-
{
359-
const int retlen = sizeof(POSIX_ACL_XATTR_DEFAULT);
360-
361-
if (list && retlen <= list_size)
362-
strcpy(list, POSIX_ACL_XATTR_DEFAULT);
363-
return retlen;
364-
}
365-
366-
static int jffs2_acl_getxattr(struct dentry *dentry, const char *name,
367-
void *buffer, size_t size, int type)
368-
{
369-
struct posix_acl *acl;
370-
int rc;
371-
372-
if (name[0] != '\0')
373-
return -EINVAL;
374-
375-
acl = jffs2_get_acl(dentry->d_inode, type);
376-
if (IS_ERR(acl))
377-
return PTR_ERR(acl);
378-
if (!acl)
379-
return -ENODATA;
380-
rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
381-
posix_acl_release(acl);
382-
383-
return rc;
384-
}
385-
386-
static int jffs2_acl_setxattr(struct dentry *dentry, const char *name,
387-
const void *value, size_t size, int flags, int type)
388-
{
389-
struct posix_acl *acl;
390-
int rc;
391-
392-
if (name[0] != '\0')
393-
return -EINVAL;
394-
if (!inode_owner_or_capable(dentry->d_inode))
395-
return -EPERM;
396-
397-
if (value) {
398-
acl = posix_acl_from_xattr(&init_user_ns, value, size);
399-
if (IS_ERR(acl))
400-
return PTR_ERR(acl);
401-
if (acl) {
402-
rc = posix_acl_valid(acl);
403-
if (rc)
404-
goto out;
405-
}
406-
} else {
407-
acl = NULL;
408-
}
409-
rc = jffs2_set_acl(dentry->d_inode, type, acl);
410-
out:
411-
posix_acl_release(acl);
412-
return rc;
413-
}
414-
415-
const struct xattr_handler jffs2_acl_access_xattr_handler = {
416-
.prefix = POSIX_ACL_XATTR_ACCESS,
417-
.flags = ACL_TYPE_DEFAULT,
418-
.list = jffs2_acl_access_listxattr,
419-
.get = jffs2_acl_getxattr,
420-
.set = jffs2_acl_setxattr,
421-
};
422-
423-
const struct xattr_handler jffs2_acl_default_xattr_handler = {
424-
.prefix = POSIX_ACL_XATTR_DEFAULT,
425-
.flags = ACL_TYPE_DEFAULT,
426-
.list = jffs2_acl_default_listxattr,
427-
.get = jffs2_acl_getxattr,
428-
.set = jffs2_acl_setxattr,
429-
};

fs/jffs2/acl.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ struct jffs2_acl_header {
2727
#ifdef CONFIG_JFFS2_FS_POSIX_ACL
2828

2929
struct posix_acl *jffs2_get_acl(struct inode *inode, int type);
30-
extern int jffs2_acl_chmod(struct inode *);
30+
int jffs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
3131
extern int jffs2_init_acl_pre(struct inode *, struct inode *, umode_t *);
3232
extern int jffs2_init_acl_post(struct inode *);
3333

34-
extern const struct xattr_handler jffs2_acl_access_xattr_handler;
35-
extern const struct xattr_handler jffs2_acl_default_xattr_handler;
36-
3734
#else
3835

3936
#define jffs2_get_acl (NULL)
40-
#define jffs2_acl_chmod(inode) (0)
37+
#define jffs2_set_acl (NULL)
4138
#define jffs2_init_acl_pre(dir_i,inode,mode) (0)
4239
#define jffs2_init_acl_post(inode) (0)
4340

fs/jffs2/dir.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const struct inode_operations jffs2_dir_inode_operations =
5959
.mknod = jffs2_mknod,
6060
.rename = jffs2_rename,
6161
.get_acl = jffs2_get_acl,
62+
.set_acl = jffs2_set_acl,
6263
.setattr = jffs2_setattr,
6364
.setxattr = jffs2_setxattr,
6465
.getxattr = jffs2_getxattr,

fs/jffs2/file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const struct file_operations jffs2_file_operations =
6666
const struct inode_operations jffs2_file_inode_operations =
6767
{
6868
.get_acl = jffs2_get_acl,
69+
.set_acl = jffs2_set_acl,
6970
.setattr = jffs2_setattr,
7071
.setxattr = jffs2_setxattr,
7172
.getxattr = jffs2_getxattr,

fs/jffs2/fs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,16 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
190190

191191
int jffs2_setattr(struct dentry *dentry, struct iattr *iattr)
192192
{
193+
struct inode *inode = dentry->d_inode;
193194
int rc;
194195

195-
rc = inode_change_ok(dentry->d_inode, iattr);
196+
rc = inode_change_ok(inode, iattr);
196197
if (rc)
197198
return rc;
198199

199-
rc = jffs2_do_setattr(dentry->d_inode, iattr);
200+
rc = jffs2_do_setattr(inode, iattr);
200201
if (!rc && (iattr->ia_valid & ATTR_MODE))
201-
rc = jffs2_acl_chmod(dentry->d_inode);
202+
rc = posix_acl_chmod(inode, inode->i_mode);
202203

203204
return rc;
204205
}

fs/jffs2/symlink.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const struct inode_operations jffs2_symlink_inode_operations =
2222
{
2323
.readlink = generic_readlink,
2424
.follow_link = jffs2_follow_link,
25-
.get_acl = jffs2_get_acl,
2625
.setattr = jffs2_setattr,
2726
.setxattr = jffs2_setxattr,
2827
.getxattr = jffs2_getxattr,

fs/jffs2/xattr.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/crc32.h>
2323
#include <linux/jffs2.h>
2424
#include <linux/xattr.h>
25+
#include <linux/posix_acl_xattr.h>
2526
#include <linux/mtd/mtd.h>
2627
#include "nodelist.h"
2728
/* -------- xdatum related functions ----------------
@@ -921,8 +922,8 @@ const struct xattr_handler *jffs2_xattr_handlers[] = {
921922
&jffs2_security_xattr_handler,
922923
#endif
923924
#ifdef CONFIG_JFFS2_FS_POSIX_ACL
924-
&jffs2_acl_access_xattr_handler,
925-
&jffs2_acl_default_xattr_handler,
925+
&posix_acl_access_xattr_handler,
926+
&posix_acl_default_xattr_handler,
926927
#endif
927928
&jffs2_trusted_xattr_handler,
928929
NULL
@@ -942,10 +943,10 @@ static const struct xattr_handler *xprefix_to_handler(int xprefix) {
942943
#endif
943944
#ifdef CONFIG_JFFS2_FS_POSIX_ACL
944945
case JFFS2_XPREFIX_ACL_ACCESS:
945-
ret = &jffs2_acl_access_xattr_handler;
946+
ret = &posix_acl_access_xattr_handler;
946947
break;
947948
case JFFS2_XPREFIX_ACL_DEFAULT:
948-
ret = &jffs2_acl_default_xattr_handler;
949+
ret = &posix_acl_default_xattr_handler;
949950
break;
950951
#endif
951952
case JFFS2_XPREFIX_TRUSTED:

0 commit comments

Comments
 (0)