ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / fs / ext3 / xattr_security.c
1 /*
2  * linux/fs/ext3/xattr_security.c
3  * Handler for storing security labels as extended attributes.
4  */
5
6 #include <linux/module.h>
7 #include <linux/string.h>
8 #include <linux/fs.h>
9 #include <linux/smp_lock.h>
10 #include <linux/ext3_jbd.h>
11 #include <linux/ext3_fs.h>
12 #include "xattr.h"
13
14 static size_t
15 ext3_xattr_security_list(char *list, struct inode *inode,
16                     const char *name, int name_len)
17 {
18         const int prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1;
19
20         if (list) {
21                 memcpy(list, XATTR_SECURITY_PREFIX, prefix_len);
22                 memcpy(list+prefix_len, name, name_len);
23                 list[prefix_len + name_len] = '\0';
24         }
25         return prefix_len + name_len + 1;
26 }
27
28 static int
29 ext3_xattr_security_get(struct inode *inode, const char *name,
30                        void *buffer, size_t size)
31 {
32         if (strcmp(name, "") == 0)
33                 return -EINVAL;
34         return ext3_xattr_get(inode, EXT3_XATTR_INDEX_SECURITY, name,
35                               buffer, size);
36 }
37
38 static int
39 ext3_xattr_security_set(struct inode *inode, const char *name,
40                        const void *value, size_t size, int flags)
41 {
42         if (strcmp(name, "") == 0)
43                 return -EINVAL;
44         return ext3_xattr_set(inode, EXT3_XATTR_INDEX_SECURITY, name,
45                               value, size, flags);
46 }
47
48 struct ext3_xattr_handler ext3_xattr_security_handler = {
49         .prefix = XATTR_SECURITY_PREFIX,
50         .list   = ext3_xattr_security_list,
51         .get    = ext3_xattr_security_get,
52         .set    = ext3_xattr_security_set,
53 };