Commit b0a7ab57 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Al Viro

hfsplus: use generic posix ACL infrastructure

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarVyacheslav Dubeyko <slava@dubeyko.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent a6dda0e6
...@@ -12,16 +12,13 @@ ...@@ -12,16 +12,13 @@
/* posix_acl.c */ /* posix_acl.c */
struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type); struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type);
extern int hfsplus_posix_acl_chmod(struct inode *); int hfsplus_set_posix_acl(struct inode *inode, struct posix_acl *acl,
int type);
extern int hfsplus_init_posix_acl(struct inode *, struct inode *); extern int hfsplus_init_posix_acl(struct inode *, struct inode *);
#else /* CONFIG_HFSPLUS_FS_POSIX_ACL */ #else /* CONFIG_HFSPLUS_FS_POSIX_ACL */
#define hfsplus_get_posix_acl NULL #define hfsplus_get_posix_acl NULL
#define hfsplus_set_posix_acl NULL
static inline int hfsplus_posix_acl_chmod(struct inode *inode)
{
return 0;
}
static inline int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir) static inline int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
{ {
......
...@@ -532,6 +532,7 @@ const struct inode_operations hfsplus_dir_inode_operations = { ...@@ -532,6 +532,7 @@ const struct inode_operations hfsplus_dir_inode_operations = {
.removexattr = hfsplus_removexattr, .removexattr = hfsplus_removexattr,
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
.get_acl = hfsplus_get_posix_acl, .get_acl = hfsplus_get_posix_acl,
.set_acl = hfsplus_set_posix_acl,
#endif #endif
}; };
......
...@@ -319,7 +319,7 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -319,7 +319,7 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)
mark_inode_dirty(inode); mark_inode_dirty(inode);
if (attr->ia_valid & ATTR_MODE) { if (attr->ia_valid & ATTR_MODE) {
error = hfsplus_posix_acl_chmod(inode); error = posix_acl_chmod(inode, inode->i_mode);
if (unlikely(error)) if (unlikely(error))
return error; return error;
} }
...@@ -393,6 +393,7 @@ static const struct inode_operations hfsplus_file_inode_operations = { ...@@ -393,6 +393,7 @@ static const struct inode_operations hfsplus_file_inode_operations = {
.removexattr = hfsplus_removexattr, .removexattr = hfsplus_removexattr,
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
.get_acl = hfsplus_get_posix_acl, .get_acl = hfsplus_get_posix_acl,
.set_acl = hfsplus_set_posix_acl,
#endif #endif
}; };
......
...@@ -17,9 +17,7 @@ struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type) ...@@ -17,9 +17,7 @@ struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type)
char *value = NULL; char *value = NULL;
ssize_t size; ssize_t size;
acl = get_cached_acl(inode, type); hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
if (acl != ACL_NOT_CACHED)
return acl;
switch (type) { switch (type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
...@@ -56,17 +54,15 @@ struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type) ...@@ -56,17 +54,15 @@ struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type)
return acl; return acl;
} }
static int hfsplus_set_posix_acl(struct inode *inode, int hfsplus_set_posix_acl(struct inode *inode, struct posix_acl *acl,
int type, int type)
struct posix_acl *acl)
{ {
int err; int err;
char *xattr_name; char *xattr_name;
size_t size = 0; size_t size = 0;
char *value = NULL; char *value = NULL;
if (S_ISLNK(inode->i_mode)) hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
return -EOPNOTSUPP;
switch (type) { switch (type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
...@@ -115,7 +111,7 @@ static int hfsplus_set_posix_acl(struct inode *inode, ...@@ -115,7 +111,7 @@ static int hfsplus_set_posix_acl(struct inode *inode,
int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir) int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
{ {
int err = 0; int err = 0;
struct posix_acl *acl = NULL; struct posix_acl *default_acl, *acl;
hfs_dbg(ACL_MOD, hfs_dbg(ACL_MOD,
"[%s]: ino %lu, dir->ino %lu\n", "[%s]: ino %lu, dir->ino %lu\n",
...@@ -124,151 +120,21 @@ int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir) ...@@ -124,151 +120,21 @@ int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
if (S_ISLNK(inode->i_mode)) if (S_ISLNK(inode->i_mode))
return 0; return 0;
acl = hfsplus_get_posix_acl(dir, ACL_TYPE_DEFAULT); err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
if (IS_ERR(acl)) if (err)
return PTR_ERR(acl);
if (acl) {
if (S_ISDIR(inode->i_mode)) {
err = hfsplus_set_posix_acl(inode,
ACL_TYPE_DEFAULT,
acl);
if (unlikely(err))
goto init_acl_cleanup;
}
err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
if (unlikely(err < 0))
return err;
if (err > 0)
err = hfsplus_set_posix_acl(inode,
ACL_TYPE_ACCESS,
acl);
} else
inode->i_mode &= ~current_umask();
init_acl_cleanup:
posix_acl_release(acl);
return err;
}
int hfsplus_posix_acl_chmod(struct inode *inode)
{
int err;
struct posix_acl *acl;
hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
if (S_ISLNK(inode->i_mode))
return -EOPNOTSUPP;
acl = hfsplus_get_posix_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
err = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (unlikely(err))
return err;
err = hfsplus_set_posix_acl(inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
return err;
}
static int hfsplus_xattr_get_posix_acl(struct dentry *dentry,
const char *name,
void *buffer,
size_t size,
int type)
{
int err = 0;
struct posix_acl *acl;
hfs_dbg(ACL_MOD,
"[%s]: ino %lu, buffer %p, size %zu, type %#x\n",
__func__, dentry->d_inode->i_ino, buffer, size, type);
if (strcmp(name, "") != 0)
return -EINVAL;
acl = hfsplus_get_posix_acl(dentry->d_inode, type);
if (IS_ERR(acl))
return PTR_ERR(acl);
if (acl == NULL)
return -ENODATA;
err = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
posix_acl_release(acl);
return err; return err;
}
static int hfsplus_xattr_set_posix_acl(struct dentry *dentry,
const char *name,
const void *value,
size_t size,
int flags,
int type)
{
int err = 0;
struct inode *inode = dentry->d_inode;
struct posix_acl *acl = NULL;
hfs_dbg(ACL_MOD,
"[%s]: ino %lu, value %p, size %zu, flags %#x, type %#x\n",
__func__, inode->i_ino, value, size, flags, type);
if (strcmp(name, "") != 0) if (default_acl) {
return -EINVAL; err = hfsplus_set_posix_acl(inode, default_acl,
ACL_TYPE_DEFAULT);
if (!inode_owner_or_capable(inode)) posix_acl_release(default_acl);
return -EPERM;
if (value) {
acl = posix_acl_from_xattr(&init_user_ns, value, size);
if (IS_ERR(acl))
return PTR_ERR(acl);
else if (acl) {
err = posix_acl_valid(acl);
if (err)
goto end_xattr_set_acl;
} }
}
err = hfsplus_set_posix_acl(inode, type, acl);
end_xattr_set_acl: if (acl) {
if (!err)
err = hfsplus_set_posix_acl(inode, acl,
ACL_TYPE_ACCESS);
posix_acl_release(acl); posix_acl_release(acl);
}
return err; return err;
} }
static size_t hfsplus_xattr_list_posix_acl(struct dentry *dentry,
char *list,
size_t list_size,
const char *name,
size_t name_len,
int type)
{
/*
* This method is not used.
* It is used hfsplus_listxattr() instead of generic_listxattr().
*/
return -EOPNOTSUPP;
}
const struct xattr_handler hfsplus_xattr_acl_access_handler = {
.prefix = POSIX_ACL_XATTR_ACCESS,
.flags = ACL_TYPE_ACCESS,
.list = hfsplus_xattr_list_posix_acl,
.get = hfsplus_xattr_get_posix_acl,
.set = hfsplus_xattr_set_posix_acl,
};
const struct xattr_handler hfsplus_xattr_acl_default_handler = {
.prefix = POSIX_ACL_XATTR_DEFAULT,
.flags = ACL_TYPE_DEFAULT,
.list = hfsplus_xattr_list_posix_acl,
.get = hfsplus_xattr_get_posix_acl,
.set = hfsplus_xattr_set_posix_acl,
};
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
#include "hfsplus_fs.h" #include "hfsplus_fs.h"
#include <linux/posix_acl_xattr.h>
#include "xattr.h" #include "xattr.h"
#include "acl.h" #include "acl.h"
...@@ -15,8 +16,8 @@ const struct xattr_handler *hfsplus_xattr_handlers[] = { ...@@ -15,8 +16,8 @@ const struct xattr_handler *hfsplus_xattr_handlers[] = {
&hfsplus_xattr_user_handler, &hfsplus_xattr_user_handler,
&hfsplus_xattr_trusted_handler, &hfsplus_xattr_trusted_handler,
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
&hfsplus_xattr_acl_access_handler, &posix_acl_access_xattr_handler,
&hfsplus_xattr_acl_default_handler, &posix_acl_default_xattr_handler,
#endif #endif
&hfsplus_xattr_security_handler, &hfsplus_xattr_security_handler,
NULL NULL
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
extern const struct xattr_handler hfsplus_xattr_osx_handler; extern const struct xattr_handler hfsplus_xattr_osx_handler;
extern const struct xattr_handler hfsplus_xattr_user_handler; extern const struct xattr_handler hfsplus_xattr_user_handler;
extern const struct xattr_handler hfsplus_xattr_trusted_handler; extern const struct xattr_handler hfsplus_xattr_trusted_handler;
extern const struct xattr_handler hfsplus_xattr_acl_access_handler;
extern const struct xattr_handler hfsplus_xattr_acl_default_handler;
extern const struct xattr_handler hfsplus_xattr_security_handler; extern const struct xattr_handler hfsplus_xattr_security_handler;
extern const struct xattr_handler *hfsplus_xattr_handlers[]; extern const struct xattr_handler *hfsplus_xattr_handlers[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment