driver core: add devname module aliases to allow module on-demand auto-loading
[safe/jmp/linux-2.6] / fs / jffs2 / acl.c
index 8ec9323..a33aab6 100644 (file)
@@ -38,12 +38,12 @@ static int jffs2_acl_count(size_t size)
        size_t s;
 
        size -= sizeof(struct jffs2_acl_header);
-       s = size - 4 * sizeof(struct jffs2_acl_entry_short);
-       if (s < 0) {
+       if (size < 4 * sizeof(struct jffs2_acl_entry_short)) {
                if (size % sizeof(struct jffs2_acl_entry_short))
                        return -1;
                return size / sizeof(struct jffs2_acl_entry_short);
        } else {
+               s = size - 4 * sizeof(struct jffs2_acl_entry_short);
                if (s % sizeof(struct jffs2_acl_entry))
                        return -1;
                return s / sizeof(struct jffs2_acl_entry) + 4;
@@ -156,48 +156,25 @@ static void *jffs2_acl_to_medium(const struct posix_acl *acl, size_t *size)
        return ERR_PTR(-EINVAL);
 }
 
-static struct posix_acl *jffs2_iget_acl(struct inode *inode, struct posix_acl **i_acl)
+static struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
 {
-       struct posix_acl *acl = JFFS2_ACL_NOT_CACHED;
-
-       spin_lock(&inode->i_lock);
-       if (*i_acl != JFFS2_ACL_NOT_CACHED)
-               acl = posix_acl_dup(*i_acl);
-       spin_unlock(&inode->i_lock);
-       return acl;
-}
-
-static void jffs2_iset_acl(struct inode *inode, struct posix_acl **i_acl, struct posix_acl *acl)
-{
-       spin_lock(&inode->i_lock);
-       if (*i_acl != JFFS2_ACL_NOT_CACHED)
-               posix_acl_release(*i_acl);
-       *i_acl = posix_acl_dup(acl);
-       spin_unlock(&inode->i_lock);
-}
-
-struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
-{
-       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
        struct posix_acl *acl;
        char *value = NULL;
        int rc, xprefix;
 
+       acl = get_cached_acl(inode, type);
+       if (acl != ACL_NOT_CACHED)
+               return acl;
+
        switch (type) {
        case ACL_TYPE_ACCESS:
-               acl = jffs2_iget_acl(inode, &f->i_acl_access);
-               if (acl != JFFS2_ACL_NOT_CACHED)
-                       return acl;
                xprefix = JFFS2_XPREFIX_ACL_ACCESS;
                break;
        case ACL_TYPE_DEFAULT:
-               acl = jffs2_iget_acl(inode, &f->i_acl_default);
-               if (acl != JFFS2_ACL_NOT_CACHED)
-                       return acl;
                xprefix = JFFS2_XPREFIX_ACL_DEFAULT;
                break;
        default:
-               return ERR_PTR(-EINVAL);
+               BUG();
        }
        rc = do_jffs2_getxattr(inode, xprefix, "", NULL, 0);
        if (rc > 0) {
@@ -215,24 +192,32 @@ struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
        }
        if (value)
                kfree(value);
-       if (!IS_ERR(acl)) {
-               switch (type) {
-               case ACL_TYPE_ACCESS:
-                       jffs2_iset_acl(inode, &f->i_acl_access, acl);
-                       break;
-               case ACL_TYPE_DEFAULT:
-                       jffs2_iset_acl(inode, &f->i_acl_default, acl);
-                       break;
-               }
-       }
+       if (!IS_ERR(acl))
+               set_cached_acl(inode, type, acl);
        return acl;
 }
 
-static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+static int __jffs2_set_acl(struct inode *inode, int xprefix, struct posix_acl *acl)
 {
-       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
-       size_t size = 0;
        char *value = NULL;
+       size_t size = 0;
+       int rc;
+
+       if (acl) {
+               value = jffs2_acl_to_medium(acl, &size);
+               if (IS_ERR(value))
+                       return PTR_ERR(value);
+       }
+       rc = do_jffs2_setxattr(inode, xprefix, "", value, size, 0);
+       if (!value && rc == -ENODATA)
+               rc = 0;
+       kfree(value);
+
+       return rc;
+}
+
+static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+{
        int rc, xprefix;
 
        if (S_ISLNK(inode->i_mode))
@@ -267,31 +252,13 @@ static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
        default:
                return -EINVAL;
        }
-       if (acl) {
-               value = jffs2_acl_to_medium(acl, &size);
-               if (IS_ERR(value))
-                       return PTR_ERR(value);
-       }
-
-       rc = do_jffs2_setxattr(inode, xprefix, "", value, size, 0);
-       if (!value && rc == -ENODATA)
-               rc = 0;
-       if (value)
-               kfree(value);
-       if (!rc) {
-               switch(type) {
-               case ACL_TYPE_ACCESS:
-                       jffs2_iset_acl(inode, &f->i_acl_access, acl);
-                       break;
-               case ACL_TYPE_DEFAULT:
-                       jffs2_iset_acl(inode, &f->i_acl_default, acl);
-                       break;
-               }
-       }
+       rc = __jffs2_set_acl(inode, xprefix, acl);
+       if (!rc)
+               set_cached_acl(inode, type, acl);
        return rc;
 }
 
-static int jffs2_check_acl(struct inode *inode, int mask)
+int jffs2_check_acl(struct inode *inode, int mask)
 {
        struct posix_acl *acl;
        int rc;
@@ -307,55 +274,59 @@ static int jffs2_check_acl(struct inode *inode, int mask)
        return -EAGAIN;
 }
 
-int jffs2_permission(struct inode *inode, int mask, struct nameidata *nd)
+int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, int *i_mode)
 {
-       return generic_permission(inode, mask, jffs2_check_acl);
-}
+       struct posix_acl *acl, *clone;
+       int rc;
 
-int jffs2_init_acl(struct inode *inode, struct posix_acl *acl)
-{
-       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
-       struct posix_acl *clone;
-       mode_t mode;
-       int rc = 0;
+       cache_no_acl(inode);
 
-       f->i_acl_access = JFFS2_ACL_NOT_CACHED;
-       f->i_acl_default = JFFS2_ACL_NOT_CACHED;
+       if (S_ISLNK(*i_mode))
+               return 0;       /* Symlink always has no-ACL */
+
+       acl = jffs2_get_acl(dir_i, ACL_TYPE_DEFAULT);
+       if (IS_ERR(acl))
+               return PTR_ERR(acl);
+
+       if (!acl) {
+               *i_mode &= ~current_umask();
+       } else {
+               if (S_ISDIR(*i_mode))
+                       set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
 
-       if (acl) {
-               if (S_ISDIR(inode->i_mode)) {
-                       rc = jffs2_set_acl(inode, ACL_TYPE_DEFAULT, acl);
-                       if (rc)
-                               goto cleanup;
-               }
                clone = posix_acl_clone(acl, GFP_KERNEL);
-               rc = -ENOMEM;
                if (!clone)
-                       goto cleanup;
-               mode = inode->i_mode;
-               rc = posix_acl_create_masq(clone, &mode);
-               if (rc >= 0) {
-                       inode->i_mode = mode;
-                       if (rc > 0)
-                               rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, clone);
+                       return -ENOMEM;
+               rc = posix_acl_create_masq(clone, (mode_t *)i_mode);
+               if (rc < 0) {
+                       posix_acl_release(clone);
+                       return rc;
                }
+               if (rc > 0)
+                       set_cached_acl(inode, ACL_TYPE_ACCESS, clone);
+
                posix_acl_release(clone);
        }
- cleanup:
-       posix_acl_release(acl);
-       return rc;
+       return 0;
 }
 
-void jffs2_clear_acl(struct jffs2_inode_info *f)
+int jffs2_init_acl_post(struct inode *inode)
 {
-       if (f->i_acl_access && f->i_acl_access != JFFS2_ACL_NOT_CACHED) {
-               posix_acl_release(f->i_acl_access);
-               f->i_acl_access = JFFS2_ACL_NOT_CACHED;
+       int rc;
+
+       if (inode->i_default_acl) {
+               rc = __jffs2_set_acl(inode, JFFS2_XPREFIX_ACL_DEFAULT, inode->i_default_acl);
+               if (rc)
+                       return rc;
        }
-       if (f->i_acl_default && f->i_acl_default != JFFS2_ACL_NOT_CACHED) {
-               posix_acl_release(f->i_acl_default);
-               f->i_acl_default = JFFS2_ACL_NOT_CACHED;
+
+       if (inode->i_acl) {
+               rc = __jffs2_set_acl(inode, JFFS2_XPREFIX_ACL_ACCESS, inode->i_acl);
+               if (rc)
+                       return rc;
        }
+
+       return 0;
 }
 
 int jffs2_acl_chmod(struct inode *inode)
@@ -379,8 +350,8 @@ int jffs2_acl_chmod(struct inode *inode)
        return rc;
 }
 
-static size_t jffs2_acl_access_listxattr(struct inode *inode, char *list, size_t list_size,
-                                        const char *name, size_t name_len)
+static size_t jffs2_acl_access_listxattr(struct dentry *dentry, char *list,
+               size_t list_size, const char *name, size_t name_len, int type)
 {
        const int retlen = sizeof(POSIX_ACL_XATTR_ACCESS);
 
@@ -389,8 +360,8 @@ static size_t jffs2_acl_access_listxattr(struct inode *inode, char *list, size_t
        return retlen;
 }
 
-static size_t jffs2_acl_default_listxattr(struct inode *inode, char *list, size_t list_size,
-                                         const char *name, size_t name_len)
+static size_t jffs2_acl_default_listxattr(struct dentry *dentry, char *list,
+               size_t list_size, const char *name, size_t name_len, int type)
 {
        const int retlen = sizeof(POSIX_ACL_XATTR_DEFAULT);
 
@@ -399,12 +370,16 @@ static size_t jffs2_acl_default_listxattr(struct inode *inode, char *list, size_
        return retlen;
 }
 
-static int jffs2_acl_getxattr(struct inode *inode, int type, void *buffer, size_t size)
+static int jffs2_acl_getxattr(struct dentry *dentry, const char *name,
+               void *buffer, size_t size, int type)
 {
        struct posix_acl *acl;
        int rc;
 
-       acl = jffs2_get_acl(inode, type);
+       if (name[0] != '\0')
+               return -EINVAL;
+
+       acl = jffs2_get_acl(dentry->d_inode, type);
        if (IS_ERR(acl))
                return PTR_ERR(acl);
        if (!acl)
@@ -415,26 +390,15 @@ static int jffs2_acl_getxattr(struct inode *inode, int type, void *buffer, size_
        return rc;
 }
 
-static int jffs2_acl_access_getxattr(struct inode *inode, const char *name, void *buffer, size_t size)
-{
-       if (name[0] != '\0')
-               return -EINVAL;
-       return jffs2_acl_getxattr(inode, ACL_TYPE_ACCESS, buffer, size);
-}
-
-static int jffs2_acl_default_getxattr(struct inode *inode, const char *name, void *buffer, size_t size)
-{
-       if (name[0] != '\0')
-               return -EINVAL;
-       return jffs2_acl_getxattr(inode, ACL_TYPE_DEFAULT, buffer, size);
-}
-
-static int jffs2_acl_setxattr(struct inode *inode, int type, const void *value, size_t size)
+static int jffs2_acl_setxattr(struct dentry *dentry, const char *name,
+               const void *value, size_t size, int flags, int type)
 {
        struct posix_acl *acl;
        int rc;
 
-       if (!is_owner_or_cap(inode))
+       if (name[0] != '\0')
+               return -EINVAL;
+       if (!is_owner_or_cap(dentry->d_inode))
                return -EPERM;
 
        if (value) {
@@ -449,38 +413,24 @@ static int jffs2_acl_setxattr(struct inode *inode, int type, const void *value,
        } else {
                acl = NULL;
        }
-       rc = jffs2_set_acl(inode, type, acl);
+       rc = jffs2_set_acl(dentry->d_inode, type, acl);
  out:
        posix_acl_release(acl);
        return rc;
 }
 
-static int jffs2_acl_access_setxattr(struct inode *inode, const char *name,
-                                    const void *buffer, size_t size, int flags)
-{
-       if (name[0] != '\0')
-               return -EINVAL;
-       return jffs2_acl_setxattr(inode, ACL_TYPE_ACCESS, buffer, size);
-}
-
-static int jffs2_acl_default_setxattr(struct inode *inode, const char *name,
-                                     const void *buffer, size_t size, int flags)
-{
-       if (name[0] != '\0')
-               return -EINVAL;
-       return jffs2_acl_setxattr(inode, ACL_TYPE_DEFAULT, buffer, size);
-}
-
-struct xattr_handler jffs2_acl_access_xattr_handler = {
+const struct xattr_handler jffs2_acl_access_xattr_handler = {
        .prefix = POSIX_ACL_XATTR_ACCESS,
+       .flags  = ACL_TYPE_DEFAULT,
        .list   = jffs2_acl_access_listxattr,
-       .get    = jffs2_acl_access_getxattr,
-       .set    = jffs2_acl_access_setxattr,
+       .get    = jffs2_acl_getxattr,
+       .set    = jffs2_acl_setxattr,
 };
 
-struct xattr_handler jffs2_acl_default_xattr_handler = {
+const struct xattr_handler jffs2_acl_default_xattr_handler = {
        .prefix = POSIX_ACL_XATTR_DEFAULT,
+       .flags  = ACL_TYPE_DEFAULT,
        .list   = jffs2_acl_default_listxattr,
-       .get    = jffs2_acl_default_getxattr,
-       .set    = jffs2_acl_default_setxattr,
+       .get    = jffs2_acl_getxattr,
+       .set    = jffs2_acl_setxattr,
 };