blob: 021508ad16168c465c12324459c798837606f3e0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/ext3/xattr_user.c
3 * Handler for extended user attributes.
4 *
5 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
6 */
7
Al Viro4613ad12012-03-29 22:30:07 -04008#include "ext3.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include "xattr.h"
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011static size_t
Christoph Hellwig431547b2009-11-13 09:52:56 +000012ext3_xattr_user_list(struct dentry *dentry, char *list, size_t list_size,
13 const char *name, size_t name_len, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014{
Shen Fengef1afd32008-07-25 01:46:23 -070015 const size_t prefix_len = XATTR_USER_PREFIX_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 const size_t total_len = prefix_len + name_len + 1;
17
Christoph Hellwig431547b2009-11-13 09:52:56 +000018 if (!test_opt(dentry->d_sb, XATTR_USER))
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 return 0;
20
21 if (list && total_len <= list_size) {
22 memcpy(list, XATTR_USER_PREFIX, prefix_len);
23 memcpy(list+prefix_len, name, name_len);
24 list[prefix_len + name_len] = '\0';
25 }
26 return total_len;
27}
28
29static int
Christoph Hellwig431547b2009-11-13 09:52:56 +000030ext3_xattr_user_get(struct dentry *dentry, const char *name, void *buffer,
31 size_t size, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 if (strcmp(name, "") == 0)
34 return -EINVAL;
Christoph Hellwig431547b2009-11-13 09:52:56 +000035 if (!test_opt(dentry->d_sb, XATTR_USER))
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 return -EOPNOTSUPP;
David Howells2b0143b2015-03-17 22:25:59 +000037 return ext3_xattr_get(d_inode(dentry), EXT3_XATTR_INDEX_USER,
Christoph Hellwig431547b2009-11-13 09:52:56 +000038 name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
41static int
Christoph Hellwig431547b2009-11-13 09:52:56 +000042ext3_xattr_user_set(struct dentry *dentry, const char *name,
43 const void *value, size_t size, int flags, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 if (strcmp(name, "") == 0)
46 return -EINVAL;
Christoph Hellwig431547b2009-11-13 09:52:56 +000047 if (!test_opt(dentry->d_sb, XATTR_USER))
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return -EOPNOTSUPP;
David Howells2b0143b2015-03-17 22:25:59 +000049 return ext3_xattr_set(d_inode(dentry), EXT3_XATTR_INDEX_USER,
Christoph Hellwig431547b2009-11-13 09:52:56 +000050 name, value, size, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Stephen Hemmingerd1f21042010-05-13 17:53:17 -070053const struct xattr_handler ext3_xattr_user_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .prefix = XATTR_USER_PREFIX,
55 .list = ext3_xattr_user_list,
56 .get = ext3_xattr_user_get,
57 .set = ext3_xattr_user_set,
58};