Posix ACL support for ext 2/3 filesystems
PATCH 3/5 Posix ACL support for ext 2/3 filesystems
his patch provides converts extended attributes passed in from user space to a generic Posix ACL representation.
- Ted
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.799 -> 1.800 # fs/Makefile 1.43 -> 1.44 # (new) -> 1.1 include/linux/xattr_acl.h # (new) -> 1.1 fs/xattr_acl.c
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/10/16 [email protected] 1.800
# Port 0.8.50 acl-xattr patch to 2.5
#
# This patch provides converts extended attributes passed in from user
# space to a generic Posix ACL representation. # -------------------------------------------- # diff -Nru a/fs/Makefile b/fs/Makefile --- a/fs/Makefile Wed Oct 16 23:02:20 2002 +++ b/fs/Makefile Wed Oct 16 23:02:20 2002 @@ -6,7 +6,7 @@ #
export-objs := open.o dcache.o buffer.o bio.o inode.o dquot.o mpage.o aio.o \
- fcntl.o read_write.o dcookies.o mbcache.o
+ fcntl.o read_write.o dcookies.o mbcache.o xattr_acl.o
obj-y := open.o read_write.o devices.o file_table.o buffer.o \
bio.o super.o block_dev.o char_dev.o stat.o exec.o pipe.o \
@@ -31,7 +31,7 @@
obj-$(CONFIG_BINFMT_ELF) += binfmt_elf.o
obj-$(CONFIG_FS_MBCACHE) += mbcache.o
-obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
+obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o xattr_acl.o
obj-$(CONFIG_QUOTA) += dquot.o
obj-$(CONFIG_QFMT_V1) += quota_v1.o
fs/xattr_acl.c new file +99 -0
@@ -0,0 +1,99 @@ +/* +* linux/fs/xattr_acl.c +* +* Almost all from linux/fs/ext2/acl.c: +* Copyright (C) 2001 by Andreas Gruenbacher, <[email protected]> +*/ + +#include <linux/module.h> +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/fs.h> +#include <linux/xattr_acl.h> + + +/* +* Convert from extended attribute to in-memory representation. +*/ +struct posix_acl * +posix_acl_from_xattr (const void *value,size_t size) +{ +xattr_acl_header *header = (xattr_acl_header *)value; +xattr_acl_entry *entry = (xattr_acl_entry *)(header+1 ), *end; +int count; +struct posix_acl *acl; +struct posix_acl_entry *acl_e; + +if (!value) +return NULL ; +if (size <sizeof (xattr_acl_header)) +return ERR_PTR (-EINVAL ); +if (header->a_version !=cpu_to_le32 (XATTR_ACL_VERSION )) +return ERR_PTR (-EINVAL ); + + count =xattr_acl_count (size); +if (count <0 ) +return ERR_PTR (-EINVAL ); +if (count ==0 ) +return NULL ; + + acl =posix_acl_alloc (count,GFP_KERNEL ); +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 : + acl_e->e_id =ACL_UNDEFINED_ID ; +break ; + +case ACL_USER : +case ACL_GROUP : + acl_e->e_id =le32_to_cpu (entry->e_id); +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 (const struct posix_acl *acl,void *buffer,size_t size) +{ +xattr_acl_header *ext_acl = (xattr_acl_header *)buffer; +xattr_acl_entry *ext_entry = ext_acl->a_entries; +int real_size, n; + + real_size =xattr_acl_size (acl->a_count); +if (!buffer) +return real_size; +if (real_size > size) +return -ERANGE ; + + ext_acl->a_version =cpu_to_le32 (XATTR_ACL_VERSION ); + +for (n=0 ; n < acl->a_count; n++, ext_entry++) { + ext_entry->e_tag =cpu_to_le16 (acl->a_entries[n].e_tag); + ext_entry->e_perm =cpu_to_le16 (acl->a_entries[n].e_perm); + ext_entry->e_id =cpu_to_le32 (acl->a_entries[n].e_id); + } +return real_size; +} +EXPORT_SYMBOL (posix_acl_to_xattr);
include/linux/xattr_acl.h new file +50 -0
50 lines not on this page · raw message