blob: 39c9667191c5db5b3c930e538d81799b96bea6fb [file] [log] [blame]
Al Virof466c6f2012-03-17 01:16:43 -04001#include "reiserfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/errno.h>
3#include <linux/fs.h>
4#include <linux/pagemap.h>
5#include <linux/xattr.h>
Al Viroc45ac882012-03-17 00:59:06 -04006#include "xattr.h"
Fabian Frederick17093992014-08-08 14:21:12 -07007#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020010user_get(const struct xattr_handler *handler, struct dentry *dentry,
11 const char *name, void *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012{
13
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070014 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
15 return -EINVAL;
Christoph Hellwig431547b2009-11-13 09:52:56 +000016 if (!reiserfs_xattrs_user(dentry->d_sb))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070017 return -EOPNOTSUPP;
David Howells2b0143b2015-03-17 22:25:59 +000018 return reiserfs_xattr_get(d_inode(dentry), name, buffer, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019}
20
21static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020022user_set(const struct xattr_handler *handler, struct dentry *dentry,
23 const char *name, const void *buffer, size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070025 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
26 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Christoph Hellwig431547b2009-11-13 09:52:56 +000028 if (!reiserfs_xattrs_user(dentry->d_sb))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070029 return -EOPNOTSUPP;
David Howells2b0143b2015-03-17 22:25:59 +000030 return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070031}
32
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020033static size_t user_list(const struct xattr_handler *handler,
34 struct dentry *dentry, char *list, size_t list_size,
35 const char *name, size_t name_len)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070036{
Jeff Mahoney48b32a32009-03-30 14:02:38 -040037 const size_t len = name_len + 1;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070038
Christoph Hellwig431547b2009-11-13 09:52:56 +000039 if (!reiserfs_xattrs_user(dentry->d_sb))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070040 return 0;
Jeff Mahoney48b32a32009-03-30 14:02:38 -040041 if (list && len <= list_size) {
42 memcpy(list, name, name_len);
43 list[name_len] = '\0';
44 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070045 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Stephen Hemminger94d09a92010-05-13 17:53:19 -070048const struct xattr_handler reiserfs_xattr_user_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 .prefix = XATTR_USER_PREFIX,
50 .get = user_get,
51 .set = user_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 .list = user_list,
53};