[NETFILTER]: nf_conntrack: add helper function for expectation initialization
[hh.org.git] / fs / xattr_acl.c
blob789a2559bd54a6da7a8166a60e27489e53d29938
1 /*
2 * linux/fs/xattr_acl.c
4 * Almost all from linux/fs/ext2/acl.c:
5 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
6 */
8 #include <linux/module.h>
9 #include <linux/sched.h>
10 #include <linux/slab.h>
11 #include <linux/fs.h>
12 #include <linux/posix_acl_xattr.h>
16 * Convert from extended attribute to in-memory representation.
18 struct posix_acl *
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;
23 int count;
24 struct posix_acl *acl;
25 struct posix_acl_entry *acl_e;
27 if (!value)
28 return NULL;
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);
35 if (count < 0)
36 return ERR_PTR(-EINVAL);
37 if (count == 0)
38 return NULL;
40 acl = posix_acl_alloc(count, GFP_KERNEL);
41 if (!acl)
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) {
50 case ACL_USER_OBJ:
51 case ACL_GROUP_OBJ:
52 case ACL_MASK:
53 case ACL_OTHER:
54 acl_e->e_id = ACL_UNDEFINED_ID;
55 break;
57 case ACL_USER:
58 case ACL_GROUP:
59 acl_e->e_id = le32_to_cpu(entry->e_id);
60 break;
62 default:
63 goto fail;
66 return acl;
68 fail:
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.
77 int
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;
82 int real_size, n;
84 real_size = posix_acl_xattr_size(acl->a_count);
85 if (!buffer)
86 return real_size;
87 if (real_size > size)
88 return -ERANGE;
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);
97 return real_size;
99 EXPORT_SYMBOL (posix_acl_to_xattr);