4 * Almost all from linux/fs/ext2/acl.c:
5 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
8 #include <linux/module.h>
9 #include <linux/sched.h>
10 #include <linux/slab.h>
12 #include <linux/posix_acl_xattr.h>
16 * Convert from extended attribute to in-memory representation.
19 posix_acl_from_xattr(const void *value, size_t size)
21 posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
22 posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
24 struct posix_acl *acl;
25 struct posix_acl_entry *acl_e;
29 if (size < sizeof(posix_acl_xattr_header))
30 return ERR_PTR(-EINVAL);
31 if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
32 return ERR_PTR(-EOPNOTSUPP);
34 count = posix_acl_xattr_count(size);
36 return ERR_PTR(-EINVAL);
40 acl = posix_acl_alloc(count, GFP_KERNEL);
42 return ERR_PTR(-ENOMEM);
43 acl_e = acl->a_entries;
45 for (end = entry + count; entry != end; acl_e++, entry++) {
46 acl_e->e_tag = le16_to_cpu(entry->e_tag);
47 acl_e->e_perm = le16_to_cpu(entry->e_perm);
49 switch(acl_e->e_tag) {
54 acl_e->e_id = ACL_UNDEFINED_ID;
59 acl_e->e_id = le32_to_cpu(entry->e_id);
69 posix_acl_release(acl);
70 return ERR_PTR(-EINVAL);
72 EXPORT_SYMBOL (posix_acl_from_xattr);
75 * Convert from in-memory to extended attribute representation.
78 posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size)
80 posix_acl_xattr_header *ext_acl = (posix_acl_xattr_header *)buffer;
81 posix_acl_xattr_entry *ext_entry = ext_acl->a_entries;
84 real_size = posix_acl_xattr_size(acl->a_count);
90 ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION);
92 for (n=0; n < acl->a_count; n++, ext_entry++) {
93 ext_entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
94 ext_entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
95 ext_entry->e_id = cpu_to_le32(acl->a_entries[n].e_id);
99 EXPORT_SYMBOL (posix_acl_to_xattr);