]> err.no Git - linux-2.6/blobdiff - fs/jffs2/acl.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/kyle/parisc-2.6
[linux-2.6] / fs / jffs2 / acl.c
index de173df84a83cb8054bfe8ac3bdbd65c3fd20455..73f0d60f73a51ff1898d7740e7dd28c68ae856c2 100644 (file)
@@ -1,15 +1,17 @@
-/*-------------------------------------------------------------------------*
- *  File: fs/jffs2/acl.c
- *  POSIX ACL support on JFFS2 FileSystem
+/*
+ * JFFS2 -- Journalling Flash File System, Version 2.
  *
- *  Implemented by KaiGai Kohei <kaigai@ak.jp.nec.com>
- *  Copyright (C) 2006 NEC Corporation
+ * Copyright (C) 2006  NEC Corporation
  *
- *  For licensing information, see the file 'LICENCE' in the jffs2 directory.
- *-------------------------------------------------------------------------*/
+ * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
+ *
+ * For licensing information, see the file 'LICENCE' in this directory.
+ *
+ */
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
+#include <linux/sched.h>
 #include <linux/time.h>
 #include <linux/crc32.h>
 #include <linux/jffs2.h>
@@ -47,9 +49,11 @@ static int jffs2_acl_count(size_t size)
        }
 }
 
-static struct posix_acl *jffs2_acl_from_medium(const void *value, size_t size)
+static struct posix_acl *jffs2_acl_from_medium(void *value, size_t size)
 {
-       const char *end = (char *)value + size;
+       void *end = value + size;
+       struct jffs2_acl_header *header = value;
+       struct jffs2_acl_entry *entry;
        struct posix_acl *acl;
        uint32_t ver;
        int i, count;
@@ -58,13 +62,13 @@ static struct posix_acl *jffs2_acl_from_medium(const void *value, size_t size)
                return NULL;
        if (size < sizeof(struct jffs2_acl_header))
                return ERR_PTR(-EINVAL);
-       ver = je32_to_cpu(((struct jffs2_acl_header *)value)->a_version);
+       ver = je32_to_cpu(header->a_version);
        if (ver != JFFS2_ACL_VERSION) {
                JFFS2_WARNING("Invalid ACL version. (=%u)\n", ver);
                return ERR_PTR(-EINVAL);
        }
 
-       value = (char *)value + sizeof(struct jffs2_acl_header);
+       value += sizeof(struct jffs2_acl_header);
        count = jffs2_acl_count(size);
        if (count < 0)
                return ERR_PTR(-EINVAL);
@@ -76,8 +80,8 @@ static struct posix_acl *jffs2_acl_from_medium(const void *value, size_t size)
                return ERR_PTR(-ENOMEM);
 
        for (i=0; i < count; i++) {
-               struct jffs2_acl_entry *entry = (struct jffs2_acl_entry *)value;
-               if ((char *)value + sizeof(struct jffs2_acl_entry_short) > end)
+               entry = value;
+               if (value + sizeof(struct jffs2_acl_entry_short) > end)
                        goto fail;
                acl->a_entries[i].e_tag = je16_to_cpu(entry->e_tag);
                acl->a_entries[i].e_perm = je16_to_cpu(entry->e_perm);
@@ -86,14 +90,14 @@ static struct posix_acl *jffs2_acl_from_medium(const void *value, size_t size)
                        case ACL_GROUP_OBJ:
                        case ACL_MASK:
                        case ACL_OTHER:
-                               value = (char *)value + sizeof(struct jffs2_acl_entry_short);
+                               value += sizeof(struct jffs2_acl_entry_short);
                                acl->a_entries[i].e_id = ACL_UNDEFINED_ID;
                                break;
 
                        case ACL_USER:
                        case ACL_GROUP:
-                               value = (char *)value + sizeof(struct jffs2_acl_entry);
-                               if ((char *)value > end)
+                               value += sizeof(struct jffs2_acl_entry);
+                               if (value > end)
                                        goto fail;
                                acl->a_entries[i].e_id = je32_to_cpu(entry->e_id);
                                break;
@@ -112,20 +116,19 @@ static struct posix_acl *jffs2_acl_from_medium(const void *value, size_t size)
 
 static void *jffs2_acl_to_medium(const struct posix_acl *acl, size_t *size)
 {
-       struct jffs2_acl_header *jffs2_acl;
-       char *e;
+       struct jffs2_acl_header *header;
+       struct jffs2_acl_entry *entry;
+       void *e;
        size_t i;
 
        *size = jffs2_acl_size(acl->a_count);
-       jffs2_acl = kmalloc(sizeof(struct jffs2_acl_header)
-                            + acl->a_count * sizeof(struct jffs2_acl_entry),
-                           GFP_KERNEL);
-       if (!jffs2_acl)
+       header = kmalloc(sizeof(*header) + acl->a_count * sizeof(*entry), GFP_KERNEL);
+       if (!header)
                return ERR_PTR(-ENOMEM);
-       jffs2_acl->a_version = cpu_to_je32(JFFS2_ACL_VERSION);
-       e = (char *)jffs2_acl + sizeof(struct jffs2_acl_header);
+       header->a_version = cpu_to_je32(JFFS2_ACL_VERSION);
+       e = header + 1;
        for (i=0; i < acl->a_count; i++) {
-               struct jffs2_acl_entry *entry = (struct jffs2_acl_entry *)e;
+               entry = e;
                entry->e_tag = cpu_to_je16(acl->a_entries[i].e_tag);
                entry->e_perm = cpu_to_je16(acl->a_entries[i].e_perm);
                switch(acl->a_entries[i].e_tag) {
@@ -146,9 +149,9 @@ static void *jffs2_acl_to_medium(const struct posix_acl *acl, size_t *size)
                                goto fail;
                }
        }
-       return (char *)jffs2_acl;
+       return header;
  fail:
-       kfree(jffs2_acl);
+       kfree(header);
        return ERR_PTR(-EINVAL);
 }
 
@@ -265,6 +268,8 @@ static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
        }
 
        rc = do_jffs2_setxattr(inode, xprefix, "", value, size, 0);
+       if (!value && rc == -ENODATA)
+               rc = 0;
        if (value)
                kfree(value);
        if (!rc) {
@@ -341,10 +346,8 @@ int jffs2_init_acl(struct inode *inode, struct inode *dir)
        return rc;
 }
 
-void jffs2_clear_acl(struct inode *inode)
+void jffs2_clear_acl(struct jffs2_inode_info *f)
 {
-       struct jffs2_inode_info *f = JFFS2_INODE_INFO(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;