aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xattr_acl.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/xattr_acl.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/xattr_acl.c')
-rw-r--r--fs/xattr_acl.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
new file mode 100644
index 000000000000..789a2559bd54
--- /dev/null
+++ b/fs/xattr_acl.c
@@ -0,0 +1,99 @@
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/sched.h>
10#include <linux/slab.h>
11#include <linux/fs.h>
12#include <linux/posix_acl_xattr.h>
13
14
15/*
16 * Convert from extended attribute to in-memory representation.
17 */
18struct posix_acl *
19posix_acl_from_xattr(const void *value, size_t size)
20{
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;
26
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);
33
34 count = posix_acl_xattr_count(size);
35 if (count < 0)
36 return ERR_PTR(-EINVAL);
37 if (count == 0)
38 return NULL;
39
40 acl = posix_acl_alloc(count, GFP_KERNEL);
41 if (!acl)
42 return ERR_PTR(-ENOMEM);
43 acl_e = acl->a_entries;
44
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);
48
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;
56
57 case ACL_USER:
58 case ACL_GROUP:
59 acl_e->e_id = le32_to_cpu(entry->e_id);
60 break;
61
62 default:
63 goto fail;
64 }
65 }
66 return acl;
67
68fail:
69 posix_acl_release(acl);
70 return ERR_PTR(-EINVAL);
71}
72EXPORT_SYMBOL (posix_acl_from_xattr);
73
74/*
75 * Convert from in-memory to extended attribute representation.
76 */
77int
78posix_acl_to_xattr(const struct posix_acl *acl, void *buffer, size_t size)
79{
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;
83
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;
89
90 ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION);
91
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);
96 }
97 return real_size;
98}
99EXPORT_SYMBOL (posix_acl_to_xattr);