blob: f383e7c3a7b5bd18b8ca0bd43026c12ed689ce41 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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{
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 if (strcmp(name, "") == 0)
39 return -EINVAL;
40 if (!test_opt(inode->i_sb, XATTR_USER))
41 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name, buffer, size);
43}
44
45static int
46ext2_xattr_user_set(struct inode *inode, const char *name,
47 const void *value, size_t size, int flags)
48{
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 if (strcmp(name, "") == 0)
50 return -EINVAL;
51 if (!test_opt(inode->i_sb, XATTR_USER))
52 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name,
55 value, size, flags);
56}
57
58struct xattr_handler ext2_xattr_user_handler = {
59 .prefix = XATTR_USER_PREFIX,
60 .list = ext2_xattr_user_list,
61 .get = ext2_xattr_user_get,
62 .set = ext2_xattr_user_set,
63};