Root/
1 | /* |
2 | * linux/fs/xattr_acl.c |
3 | * |
4 | * Almost all from linux/fs/ext2/acl.c: |
5 | * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org> |
6 | */ |
7 | |
8 | #include <linux/module.h> |
9 | #include <linux/fs.h> |
10 | #include <linux/posix_acl_xattr.h> |
11 | #include <linux/gfp.h> |
12 | |
13 | |
14 | /* |
15 | * Convert from extended attribute to in-memory representation. |
16 | */ |
17 | struct posix_acl * |
18 | posix_acl_from_xattr(const void *value, size_t size) |
19 | { |
20 | posix_acl_xattr_header *header = (posix_acl_xattr_header *)value; |
21 | posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end; |
22 | int count; |
23 | struct posix_acl *acl; |
24 | struct posix_acl_entry *acl_e; |
25 | |
26 | if (!value) |
27 | return NULL; |
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); |
32 | |
33 | count = posix_acl_xattr_count(size); |
34 | if (count < 0) |
35 | return ERR_PTR(-EINVAL); |
36 | if (count == 0) |
37 | return NULL; |
38 | |
39 | acl = posix_acl_alloc(count, GFP_NOFS); |
40 | if (!acl) |
41 | return ERR_PTR(-ENOMEM); |
42 | acl_e = acl->a_entries; |
43 | |
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); |
47 | |
48 | switch(acl_e->e_tag) { |
49 | case ACL_USER_OBJ: |
50 | case ACL_GROUP_OBJ: |
51 | case ACL_MASK: |
52 | case ACL_OTHER: |
53 | acl_e->e_id = ACL_UNDEFINED_ID; |
54 | break; |
55 | |
56 | case ACL_USER: |
57 | case ACL_GROUP: |
58 | acl_e->e_id = le32_to_cpu(entry->e_id); |
59 | break; |
60 | |
61 | default: |
62 | goto fail; |
63 | } |
64 | } |
65 | return acl; |
66 | |
67 | fail: |
68 | posix_acl_release(acl); |
69 | return ERR_PTR(-EINVAL); |
70 | } |
71 | EXPORT_SYMBOL (posix_acl_from_xattr); |
72 | |
73 | /* |
74 | * Convert from in-memory to extended attribute representation. |
75 | */ |
76 | int |
77 | posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size) |
78 | { |
79 | posix_acl_xattr_header *ext_acl = (posix_acl_xattr_header *)buffer; |
80 | posix_acl_xattr_entry *ext_entry = ext_acl->a_entries; |
81 | int real_size, n; |
82 | |
83 | real_size = posix_acl_xattr_size(acl->a_count); |
84 | if (!buffer) |
85 | return real_size; |
86 | if (real_size > size) |
87 | return -ERANGE; |
88 | |
89 | ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
90 | |
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); |
95 | } |
96 | return real_size; |
97 | } |
98 | EXPORT_SYMBOL (posix_acl_to_xattr); |
99 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9