aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext2/xattr_user.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/ext2/xattr_user.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/ext2/xattr_user.c')
-rw-r--r--fs/ext2/xattr_user.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/fs/ext2/xattr_user.c b/fs/ext2/xattr_user.c
new file mode 100644
index 000000000000..0c03ea131a94
--- /dev/null
+++ b/fs/ext2/xattr_user.c
@@ -0,0 +1,77 @@
1/*
2 * linux/fs/ext2/xattr_user.c
3 * Handler for extended user attributes.
4 *
5 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
6 */
7
8#include <linux/init.h>
9#include <linux/module.h>
10#include <linux/string.h>
11#include "ext2.h"
12#include "xattr.h"
13
14#define XATTR_USER_PREFIX "user."
15
16static size_t
17ext2_xattr_user_list(struct inode *inode, char *list, size_t list_size,
18 const char *name, size_t name_len)
19{
20 const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1;
21 const size_t total_len = prefix_len + name_len + 1;
22
23 if (!test_opt(inode->i_sb, XATTR_USER))
24 return 0;
25
26 if (list && total_len <= list_size) {
27 memcpy(list, XATTR_USER_PREFIX, prefix_len);
28 memcpy(list+prefix_len, name, name_len);
29 list[prefix_len + name_len] = '\0';
30 }
31 return total_len;
32}
33
34static int
35ext2_xattr_user_get(struct inode *inode, const char *name,
36 void *buffer, size_t size)
37{
38 int error;
39
40 if (strcmp(name, "") == 0)
41 return -EINVAL;
42 if (!test_opt(inode->i_sb, XATTR_USER))
43 return -EOPNOTSUPP;
44 error = permission(inode, MAY_READ, NULL);
45 if (error)
46 return error;
47
48 return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name, buffer, size);
49}
50
51static int
52ext2_xattr_user_set(struct inode *inode, const char *name,
53 const void *value, size_t size, int flags)
54{
55 int error;
56
57 if (strcmp(name, "") == 0)
58 return -EINVAL;
59 if (!test_opt(inode->i_sb, XATTR_USER))
60 return -EOPNOTSUPP;
61 if ( !S_ISREG(inode->i_mode) &&
62 (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
63 return -EPERM;
64 error = permission(inode, MAY_WRITE, NULL);
65 if (error)
66 return error;
67
68 return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
69 value, size, flags);
70}
71
72struct xattr_handler ext2_xattr_user_handler = {
73 .prefix = XATTR_USER_PREFIX,
74 .list = ext2_xattr_user_list,
75 .get = ext2_xattr_user_get,
76 .set = ext2_xattr_user_set,
77};