2 * linux/fs/ext2/xattr_user.c
3 * Handler for extended user attributes.
5 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
8 #include <linux/init.h>
9 #include <linux/module.h>
10 #include <linux/string.h>
14 #define XATTR_USER_PREFIX "user."
17 ext2_xattr_user_list(struct inode
*inode
, char *list
, size_t list_size
,
18 const char *name
, size_t name_len
)
20 const size_t prefix_len
= sizeof(XATTR_USER_PREFIX
)-1;
21 const size_t total_len
= prefix_len
+ name_len
+ 1;
23 if (!test_opt(inode
->i_sb
, XATTR_USER
))
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';
35 ext2_xattr_user_get(struct inode
*inode
, const char *name
,
36 void *buffer
, size_t size
)
40 if (strcmp(name
, "") == 0)
42 if (!test_opt(inode
->i_sb
, XATTR_USER
))
44 error
= permission(inode
, MAY_READ
, NULL
);
48 return ext2_xattr_get(inode
, EXT2_XATTR_INDEX_USER
, name
, buffer
, size
);
52 ext2_xattr_user_set(struct inode
*inode
, const char *name
,
53 const void *value
, size_t size
, int flags
)
57 if (strcmp(name
, "") == 0)
59 if (!test_opt(inode
->i_sb
, XATTR_USER
))
61 if ( !S_ISREG(inode
->i_mode
) &&
62 (!S_ISDIR(inode
->i_mode
) || inode
->i_mode
& S_ISVTX
))
64 error
= permission(inode
, MAY_WRITE
, NULL
);
68 return ext2_xattr_set(inode
, EXT2_XATTR_INDEX_USER
, name
,
72 struct 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
,