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>
10 #include <linux/posix_acl_xattr.h>
11 #include <linux/gfp.h>
15 * Convert from extended attribute to in-memory representation.
18 posix_acl_from_xattr(const void *value, size_t size)
20 posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
21 posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
23 struct posix_acl *acl;
24 struct posix_acl_entry *acl_e;
28 if (size < sizeof(posix_acl_xattr_header))
29 return ERR_PTR(-EINVAL);
30 if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
31 return ERR_PTR(-EOPNOTSUPP);
33 count = posix_acl_xattr_count(size);
35 return ERR_PTR(-EINVAL);
39 acl = posix_acl_alloc(count, GFP_NOFS);
41 return ERR_PTR(-ENOMEM);
42 acl_e = acl->a_entries;
44 for (end = entry + count; entry != end; acl_e++, entry++) {
45 acl_e->e_tag = le16_to_cpu(entry->e_tag);
46 acl_e->e_perm = le16_to_cpu(entry->e_perm);
48 switch(acl_e->e_tag) {
53 acl_e->e_id = ACL_UNDEFINED_ID;
58 acl_e->e_id = le32_to_cpu(entry->e_id);
68 posix_acl_release(acl);
69 return ERR_PTR(-EINVAL);
71 EXPORT_SYMBOL (posix_acl_from_xattr);
74 * Convert from in-memory to extended attribute representation.
77 posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size)
79 posix_acl_xattr_header *ext_acl = (posix_acl_xattr_header *)buffer;
80 posix_acl_xattr_entry *ext_entry = ext_acl->a_entries;
83 real_size = posix_acl_xattr_size(acl->a_count);
89 ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION);
91 for (n=0; n < acl->a_count; n++, ext_entry++) {
92 ext_entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
93 ext_entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
94 ext_entry->e_id = cpu_to_le32(acl->a_entries[n].e_id);
98 EXPORT_SYMBOL (posix_acl_to_xattr);