diff options
Diffstat (limited to 'fs/ocfs2/xattr_user.c')
-rw-r--r-- | fs/ocfs2/xattr_user.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/fs/ocfs2/xattr_user.c b/fs/ocfs2/xattr_user.c new file mode 100644 index 000000000000..93ba71637788 --- /dev/null +++ b/fs/ocfs2/xattr_user.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* -*- mode: c; c-basic-offset: 8; -*- | ||
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | ||
3 | * | ||
4 | * xattr_user.c | ||
5 | * | ||
6 | * Copyright (C) 2008 Oracle. All rights reserved. | ||
7 | * | ||
8 | * CREDITS: | ||
9 | * Lots of code in this file is taken from ext3. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public | ||
13 | * License as published by the Free Software Foundation; either | ||
14 | * version 2 of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public | ||
22 | * License along with this program; if not, write to the | ||
23 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
24 | * Boston, MA 021110-1307, USA. | ||
25 | */ | ||
26 | |||
27 | #include <linux/init.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/string.h> | ||
30 | |||
31 | #define MLOG_MASK_PREFIX ML_INODE | ||
32 | #include <cluster/masklog.h> | ||
33 | |||
34 | #include "ocfs2.h" | ||
35 | #include "alloc.h" | ||
36 | #include "dlmglue.h" | ||
37 | #include "file.h" | ||
38 | #include "ocfs2_fs.h" | ||
39 | #include "xattr.h" | ||
40 | |||
41 | #define XATTR_USER_PREFIX "user." | ||
42 | |||
43 | static size_t ocfs2_xattr_user_list(struct inode *inode, char *list, | ||
44 | size_t list_size, const char *name, | ||
45 | size_t name_len) | ||
46 | { | ||
47 | const size_t prefix_len = sizeof(XATTR_USER_PREFIX) - 1; | ||
48 | const size_t total_len = prefix_len + name_len + 1; | ||
49 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
50 | |||
51 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | ||
52 | return 0; | ||
53 | |||
54 | if (list && total_len <= list_size) { | ||
55 | memcpy(list, XATTR_USER_PREFIX, prefix_len); | ||
56 | memcpy(list + prefix_len, name, name_len); | ||
57 | list[prefix_len + name_len] = '\0'; | ||
58 | } | ||
59 | return total_len; | ||
60 | } | ||
61 | |||
62 | static int ocfs2_xattr_user_get(struct inode *inode, const char *name, | ||
63 | void *buffer, size_t size) | ||
64 | { | ||
65 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
66 | |||
67 | if (strcmp(name, "") == 0) | ||
68 | return -EINVAL; | ||
69 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | ||
70 | return -EOPNOTSUPP; | ||
71 | return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_USER, name, | ||
72 | buffer, size); | ||
73 | } | ||
74 | |||
75 | static int ocfs2_xattr_user_set(struct inode *inode, const char *name, | ||
76 | const void *value, size_t size, int flags) | ||
77 | { | ||
78 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
79 | |||
80 | if (strcmp(name, "") == 0) | ||
81 | return -EINVAL; | ||
82 | if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) | ||
83 | return -EOPNOTSUPP; | ||
84 | |||
85 | return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_USER, name, value, | ||
86 | size, flags); | ||
87 | } | ||
88 | |||
89 | struct xattr_handler ocfs2_xattr_user_handler = { | ||
90 | .prefix = XATTR_USER_PREFIX, | ||
91 | .list = ocfs2_xattr_user_list, | ||
92 | .get = ocfs2_xattr_user_get, | ||
93 | .set = ocfs2_xattr_user_set, | ||
94 | }; | ||