]> Pileus Git - ~andy/linux/blobdiff - fs/ext2/acl.c
Merge tag 'for-usb-linus-2014-02-04' of git://git.kernel.org/pub/scm/linux/kernel...
[~andy/linux] / fs / ext2 / acl.c
index 110b6b371a4edc353fc1904bcc79299580087184..1b8001bbe94778ec09cfab5ecd8d08136d384a5a 100644 (file)
@@ -148,13 +148,6 @@ ext2_get_acl(struct inode *inode, int type)
        struct posix_acl *acl;
        int retval;
 
-       if (!test_opt(inode->i_sb, POSIX_ACL))
-               return NULL;
-
-       acl = get_cached_acl(inode, type);
-       if (acl != ACL_NOT_CACHED)
-               return acl;
-
        switch (type) {
        case ACL_TYPE_ACCESS:
                name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
@@ -189,19 +182,14 @@ ext2_get_acl(struct inode *inode, int type)
 /*
  * inode->i_mutex: down
  */
-static int
-ext2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+int
+ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
        int name_index;
        void *value = NULL;
        size_t size = 0;
        int error;
 
-       if (S_ISLNK(inode->i_mode))
-               return -EOPNOTSUPP;
-       if (!test_opt(inode->i_sb, POSIX_ACL))
-               return 0;
-
        switch(type) {
                case ACL_TYPE_ACCESS:
                        name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
@@ -250,169 +238,21 @@ ext2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
 int
 ext2_init_acl(struct inode *inode, struct inode *dir)
 {
-       struct posix_acl *acl = NULL;
-       int error = 0;
-
-       if (!S_ISLNK(inode->i_mode)) {
-               if (test_opt(dir->i_sb, POSIX_ACL)) {
-                       acl = ext2_get_acl(dir, ACL_TYPE_DEFAULT);
-                       if (IS_ERR(acl))
-                               return PTR_ERR(acl);
-               }
-               if (!acl)
-                       inode->i_mode &= ~current_umask();
-       }
-       if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
-               if (S_ISDIR(inode->i_mode)) {
-                       error = ext2_set_acl(inode, ACL_TYPE_DEFAULT, acl);
-                       if (error)
-                               goto cleanup;
-               }
-               error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
-               if (error < 0)
-                       return error;
-               if (error > 0) {
-                       /* This is an extended ACL */
-                       error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
-               }
-       }
-cleanup:
-       posix_acl_release(acl);
-       return error;
-}
-
-/*
- * Does chmod for an inode that may have an Access Control List. The
- * inode->i_mode field must be updated to the desired value by the caller
- * before calling this function.
- * Returns 0 on success, or a negative error number.
- *
- * We change the ACL rather than storing some ACL entries in the file
- * mode permission bits (which would be more efficient), because that
- * would break once additional permissions (like  ACL_APPEND, ACL_DELETE
- * for directories) are added. There are no more bits available in the
- * file mode.
- *
- * inode->i_mutex: down
- */
-int
-ext2_acl_chmod(struct inode *inode)
-{
-       struct posix_acl *acl;
-        int error;
+       struct posix_acl *default_acl, *acl;
+       int error;
 
-       if (!test_opt(inode->i_sb, POSIX_ACL))
-               return 0;
-       if (S_ISLNK(inode->i_mode))
-               return -EOPNOTSUPP;
-       acl = ext2_get_acl(inode, ACL_TYPE_ACCESS);
-       if (IS_ERR(acl) || !acl)
-               return PTR_ERR(acl);
-       error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+       error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
        if (error)
                return error;
-       error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
-       posix_acl_release(acl);
-       return error;
-}
 
-/*
- * Extended attribut handlers
- */
-static size_t
-ext2_xattr_list_acl_access(struct dentry *dentry, char *list, size_t list_size,
-                          const char *name, size_t name_len, int type)
-{
-       const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
-
-       if (!test_opt(dentry->d_sb, POSIX_ACL))
-               return 0;
-       if (list && size <= list_size)
-               memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
-       return size;
-}
-
-static size_t
-ext2_xattr_list_acl_default(struct dentry *dentry, char *list, size_t list_size,
-                           const char *name, size_t name_len, int type)
-{
-       const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
-
-       if (!test_opt(dentry->d_sb, POSIX_ACL))
-               return 0;
-       if (list && size <= list_size)
-               memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
-       return size;
-}
-
-static int
-ext2_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer,
-                  size_t size, int type)
-{
-       struct posix_acl *acl;
-       int error;
-
-       if (strcmp(name, "") != 0)
-               return -EINVAL;
-       if (!test_opt(dentry->d_sb, POSIX_ACL))
-               return -EOPNOTSUPP;
-
-       acl = ext2_get_acl(dentry->d_inode, type);
-       if (IS_ERR(acl))
-               return PTR_ERR(acl);
-       if (acl == NULL)
-               return -ENODATA;
-       error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
-       posix_acl_release(acl);
-
-       return error;
-}
-
-static int
-ext2_xattr_set_acl(struct dentry *dentry, const char *name, const void *value,
-                  size_t size, int flags, int type)
-{
-       struct posix_acl *acl;
-       int error;
-
-       if (strcmp(name, "") != 0)
-               return -EINVAL;
-       if (!test_opt(dentry->d_sb, POSIX_ACL))
-               return -EOPNOTSUPP;
-       if (!inode_owner_or_capable(dentry->d_inode))
-               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) {
-                       error = posix_acl_valid(acl);
-                       if (error)
-                               goto release_and_out;
-               }
-       } else
-               acl = NULL;
-
-       error = ext2_set_acl(dentry->d_inode, type, acl);
-
-release_and_out:
-       posix_acl_release(acl);
+       if (default_acl) {
+               error = ext2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
+               posix_acl_release(default_acl);
+       }
+       if (acl) {
+               if (!error)
+                       error = ext2_set_acl(inode, acl, ACL_TYPE_ACCESS);
+               posix_acl_release(acl);
+       }
        return error;
 }
-
-const struct xattr_handler ext2_xattr_acl_access_handler = {
-       .prefix = POSIX_ACL_XATTR_ACCESS,
-       .flags  = ACL_TYPE_ACCESS,
-       .list   = ext2_xattr_list_acl_access,
-       .get    = ext2_xattr_get_acl,
-       .set    = ext2_xattr_set_acl,
-};
-
-const struct xattr_handler ext2_xattr_acl_default_handler = {
-       .prefix = POSIX_ACL_XATTR_DEFAULT,
-       .flags  = ACL_TYPE_DEFAULT,
-       .list   = ext2_xattr_list_acl_default,
-       .get    = ext2_xattr_get_acl,
-       .set    = ext2_xattr_set_acl,
-};