]> Pileus Git - ~andy/linux/commitdiff
fs: merge xattr_acl.c into posix_acl.c
authorChristoph Hellwig <hch@infradead.org>
Fri, 20 Dec 2013 13:16:37 +0000 (05:16 -0800)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 26 Jan 2014 04:58:16 +0000 (23:58 -0500)
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/Makefile
fs/posix_acl.c
fs/xattr_acl.c [deleted file]

index 4fe6df3ec28fe5392b680e853b0fbfef6313179a..f2c1843820e34007f16ebaad405db3ea5ef3ca0f 100644 (file)
@@ -42,7 +42,7 @@ obj-$(CONFIG_BINFMT_SOM)      += binfmt_som.o
 obj-$(CONFIG_BINFMT_FLAT)      += binfmt_flat.o
 
 obj-$(CONFIG_FS_MBCACHE)       += mbcache.o
-obj-$(CONFIG_FS_POSIX_ACL)     += posix_acl.o xattr_acl.o
+obj-$(CONFIG_FS_POSIX_ACL)     += posix_acl.o
 obj-$(CONFIG_NFS_COMMON)       += nfs_common/
 obj-$(CONFIG_GENERIC_ACL)      += generic_acl.o
 obj-$(CONFIG_COREDUMP)         += coredump.o
index 8bd2135b7f82ce181445f8e4804d4b226dca4891..359d70b0e947d332ffd716479ac36f406ba39749 100644 (file)
@@ -1,10 +1,8 @@
 /*
- * linux/fs/posix_acl.c
+ * Copyright (C) 2002,2003 by Andreas Gruenbacher <a.gruenbacher@computer.org>
  *
- *  Copyright (C) 2002 by Andreas Gruenbacher <a.gruenbacher@computer.org>
- *
- *  Fixes from William Schumacher incorporated on 15 March 2001.
- *     (Reported by Charles Bertsch, <CBertsch@microtest.com>).
+ * Fixes from William Schumacher incorporated on 15 March 2001.
+ *    (Reported by Charles Bertsch, <CBertsch@microtest.com>).
  */
 
 /*
@@ -18,9 +16,9 @@
 #include <linux/fs.h>
 #include <linux/sched.h>
 #include <linux/posix_acl.h>
+#include <linux/posix_acl_xattr.h>
 #include <linux/export.h>
-
-#include <linux/errno.h>
+#include <linux/user_namespace.h>
 
 EXPORT_SYMBOL(posix_acl_init);
 EXPORT_SYMBOL(posix_acl_alloc);
@@ -418,3 +416,171 @@ posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, umode_t mode)
        return err;
 }
 EXPORT_SYMBOL(posix_acl_chmod);
+
+/*
+ * Fix up the uids and gids in posix acl extended attributes in place.
+ */
+static void posix_acl_fix_xattr_userns(
+       struct user_namespace *to, struct user_namespace *from,
+       void *value, size_t size)
+{
+       posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
+       posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
+       int count;
+       kuid_t uid;
+       kgid_t gid;
+
+       if (!value)
+               return;
+       if (size < sizeof(posix_acl_xattr_header))
+               return;
+       if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
+               return;
+
+       count = posix_acl_xattr_count(size);
+       if (count < 0)
+               return;
+       if (count == 0)
+               return;
+
+       for (end = entry + count; entry != end; entry++) {
+               switch(le16_to_cpu(entry->e_tag)) {
+               case ACL_USER:
+                       uid = make_kuid(from, le32_to_cpu(entry->e_id));
+                       entry->e_id = cpu_to_le32(from_kuid(to, uid));
+                       break;
+               case ACL_GROUP:
+                       gid = make_kgid(from, le32_to_cpu(entry->e_id));
+                       entry->e_id = cpu_to_le32(from_kgid(to, gid));
+                       break;
+               default:
+                       break;
+               }
+       }
+}
+
+void posix_acl_fix_xattr_from_user(void *value, size_t size)
+{
+       struct user_namespace *user_ns = current_user_ns();
+       if (user_ns == &init_user_ns)
+               return;
+       posix_acl_fix_xattr_userns(&init_user_ns, user_ns, value, size);
+}
+
+void posix_acl_fix_xattr_to_user(void *value, size_t size)
+{
+       struct user_namespace *user_ns = current_user_ns();
+       if (user_ns == &init_user_ns)
+               return;
+       posix_acl_fix_xattr_userns(user_ns, &init_user_ns, value, size);
+}
+
+/*
+ * Convert from extended attribute to in-memory representation.
+ */
+struct posix_acl *
+posix_acl_from_xattr(struct user_namespace *user_ns,
+                    const void *value, size_t size)
+{
+       posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
+       posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
+       int count;
+       struct posix_acl *acl;
+       struct posix_acl_entry *acl_e;
+
+       if (!value)
+               return NULL;
+       if (size < sizeof(posix_acl_xattr_header))
+                return ERR_PTR(-EINVAL);
+       if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
+               return ERR_PTR(-EOPNOTSUPP);
+
+       count = posix_acl_xattr_count(size);
+       if (count < 0)
+               return ERR_PTR(-EINVAL);
+       if (count == 0)
+               return NULL;
+       
+       acl = posix_acl_alloc(count, GFP_NOFS);
+       if (!acl)
+               return ERR_PTR(-ENOMEM);
+       acl_e = acl->a_entries;
+       
+       for (end = entry + count; entry != end; acl_e++, entry++) {
+               acl_e->e_tag  = le16_to_cpu(entry->e_tag);
+               acl_e->e_perm = le16_to_cpu(entry->e_perm);
+
+               switch(acl_e->e_tag) {
+                       case ACL_USER_OBJ:
+                       case ACL_GROUP_OBJ:
+                       case ACL_MASK:
+                       case ACL_OTHER:
+                               break;
+
+                       case ACL_USER:
+                               acl_e->e_uid =
+                                       make_kuid(user_ns,
+                                                 le32_to_cpu(entry->e_id));
+                               if (!uid_valid(acl_e->e_uid))
+                                       goto fail;
+                               break;
+                       case ACL_GROUP:
+                               acl_e->e_gid =
+                                       make_kgid(user_ns,
+                                                 le32_to_cpu(entry->e_id));
+                               if (!gid_valid(acl_e->e_gid))
+                                       goto fail;
+                               break;
+
+                       default:
+                               goto fail;
+               }
+       }
+       return acl;
+
+fail:
+       posix_acl_release(acl);
+       return ERR_PTR(-EINVAL);
+}
+EXPORT_SYMBOL (posix_acl_from_xattr);
+
+/*
+ * Convert from in-memory to extended attribute representation.
+ */
+int
+posix_acl_to_xattr(struct user_namespace *user_ns, const struct posix_acl *acl,
+                  void *buffer, size_t size)
+{
+       posix_acl_xattr_header *ext_acl = (posix_acl_xattr_header *)buffer;
+       posix_acl_xattr_entry *ext_entry = ext_acl->a_entries;
+       int real_size, n;
+
+       real_size = posix_acl_xattr_size(acl->a_count);
+       if (!buffer)
+               return real_size;
+       if (real_size > size)
+               return -ERANGE;
+       
+       ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION);
+
+       for (n=0; n < acl->a_count; n++, ext_entry++) {
+               const struct posix_acl_entry *acl_e = &acl->a_entries[n];
+               ext_entry->e_tag  = cpu_to_le16(acl_e->e_tag);
+               ext_entry->e_perm = cpu_to_le16(acl_e->e_perm);
+               switch(acl_e->e_tag) {
+               case ACL_USER:
+                       ext_entry->e_id =
+                               cpu_to_le32(from_kuid(user_ns, acl_e->e_uid));
+                       break;
+               case ACL_GROUP:
+                       ext_entry->e_id =
+                               cpu_to_le32(from_kgid(user_ns, acl_e->e_gid));
+                       break;
+               default:
+                       ext_entry->e_id = cpu_to_le32(ACL_UNDEFINED_ID);
+                       break;
+               }
+       }
+       return real_size;
+}
+EXPORT_SYMBOL (posix_acl_to_xattr);
diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
deleted file mode 100644 (file)
index 9fbea87..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * linux/fs/xattr_acl.c
- *
- * Almost all from linux/fs/ext2/acl.c:
- * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
- */
-
-#include <linux/export.h>
-#include <linux/fs.h>
-#include <linux/posix_acl_xattr.h>
-#include <linux/gfp.h>
-#include <linux/user_namespace.h>
-
-/*
- * Fix up the uids and gids in posix acl extended attributes in place.
- */
-static void posix_acl_fix_xattr_userns(
-       struct user_namespace *to, struct user_namespace *from,
-       void *value, size_t size)
-{
-       posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
-       posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
-       int count;
-       kuid_t uid;
-       kgid_t gid;
-
-       if (!value)
-               return;
-       if (size < sizeof(posix_acl_xattr_header))
-               return;
-       if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
-               return;
-
-       count = posix_acl_xattr_count(size);
-       if (count < 0)
-               return;
-       if (count == 0)
-               return;
-
-       for (end = entry + count; entry != end; entry++) {
-               switch(le16_to_cpu(entry->e_tag)) {
-               case ACL_USER:
-                       uid = make_kuid(from, le32_to_cpu(entry->e_id));
-                       entry->e_id = cpu_to_le32(from_kuid(to, uid));
-                       break;
-               case ACL_GROUP:
-                       gid = make_kgid(from, le32_to_cpu(entry->e_id));
-                       entry->e_id = cpu_to_le32(from_kgid(to, gid));
-                       break;
-               default:
-                       break;
-               }
-       }
-}
-
-void posix_acl_fix_xattr_from_user(void *value, size_t size)
-{
-       struct user_namespace *user_ns = current_user_ns();
-       if (user_ns == &init_user_ns)
-               return;
-       posix_acl_fix_xattr_userns(&init_user_ns, user_ns, value, size);
-}
-
-void posix_acl_fix_xattr_to_user(void *value, size_t size)
-{
-       struct user_namespace *user_ns = current_user_ns();
-       if (user_ns == &init_user_ns)
-               return;
-       posix_acl_fix_xattr_userns(user_ns, &init_user_ns, value, size);
-}
-
-/*
- * Convert from extended attribute to in-memory representation.
- */
-struct posix_acl *
-posix_acl_from_xattr(struct user_namespace *user_ns,
-                    const void *value, size_t size)
-{
-       posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
-       posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
-       int count;
-       struct posix_acl *acl;
-       struct posix_acl_entry *acl_e;
-
-       if (!value)
-               return NULL;
-       if (size < sizeof(posix_acl_xattr_header))
-                return ERR_PTR(-EINVAL);
-       if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
-               return ERR_PTR(-EOPNOTSUPP);
-
-       count = posix_acl_xattr_count(size);
-       if (count < 0)
-               return ERR_PTR(-EINVAL);
-       if (count == 0)
-               return NULL;
-       
-       acl = posix_acl_alloc(count, GFP_NOFS);
-       if (!acl)
-               return ERR_PTR(-ENOMEM);
-       acl_e = acl->a_entries;
-       
-       for (end = entry + count; entry != end; acl_e++, entry++) {
-               acl_e->e_tag  = le16_to_cpu(entry->e_tag);
-               acl_e->e_perm = le16_to_cpu(entry->e_perm);
-
-               switch(acl_e->e_tag) {
-                       case ACL_USER_OBJ:
-                       case ACL_GROUP_OBJ:
-                       case ACL_MASK:
-                       case ACL_OTHER:
-                               break;
-
-                       case ACL_USER:
-                               acl_e->e_uid =
-                                       make_kuid(user_ns,
-                                                 le32_to_cpu(entry->e_id));
-                               if (!uid_valid(acl_e->e_uid))
-                                       goto fail;
-                               break;
-                       case ACL_GROUP:
-                               acl_e->e_gid =
-                                       make_kgid(user_ns,
-                                                 le32_to_cpu(entry->e_id));
-                               if (!gid_valid(acl_e->e_gid))
-                                       goto fail;
-                               break;
-
-                       default:
-                               goto fail;
-               }
-       }
-       return acl;
-
-fail:
-       posix_acl_release(acl);
-       return ERR_PTR(-EINVAL);
-}
-EXPORT_SYMBOL (posix_acl_from_xattr);
-
-/*
- * Convert from in-memory to extended attribute representation.
- */
-int
-posix_acl_to_xattr(struct user_namespace *user_ns, const struct posix_acl *acl,
-                  void *buffer, size_t size)
-{
-       posix_acl_xattr_header *ext_acl = (posix_acl_xattr_header *)buffer;
-       posix_acl_xattr_entry *ext_entry = ext_acl->a_entries;
-       int real_size, n;
-
-       real_size = posix_acl_xattr_size(acl->a_count);
-       if (!buffer)
-               return real_size;
-       if (real_size > size)
-               return -ERANGE;
-       
-       ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION);
-
-       for (n=0; n < acl->a_count; n++, ext_entry++) {
-               const struct posix_acl_entry *acl_e = &acl->a_entries[n];
-               ext_entry->e_tag  = cpu_to_le16(acl_e->e_tag);
-               ext_entry->e_perm = cpu_to_le16(acl_e->e_perm);
-               switch(acl_e->e_tag) {
-               case ACL_USER:
-                       ext_entry->e_id =
-                               cpu_to_le32(from_kuid(user_ns, acl_e->e_uid));
-                       break;
-               case ACL_GROUP:
-                       ext_entry->e_id =
-                               cpu_to_le32(from_kgid(user_ns, acl_e->e_gid));
-                       break;
-               default:
-                       ext_entry->e_id = cpu_to_le32(ACL_UNDEFINED_ID);
-                       break;
-               }
-       }
-       return real_size;
-}
-EXPORT_SYMBOL (posix_acl_to_xattr);