Al Viro | f466c6f | 2012-03-17 01:16:43 -0400 | [diff] [blame] | 1 | #include "reiserfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/errno.h> |
| 3 | #include <linux/fs.h> |
| 4 | #include <linux/pagemap.h> |
| 5 | #include <linux/xattr.h> |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 6 | #include "xattr.h" |
Fabian Frederick | 1709399 | 2014-08-08 14:21:12 -0700 | [diff] [blame] | 7 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | static int |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 10 | user_get(const struct xattr_handler *handler, struct dentry *dentry, |
| 11 | const char *name, void *buffer, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | { |
| 13 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 14 | if (strlen(name) < sizeof(XATTR_USER_PREFIX)) |
| 15 | return -EINVAL; |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 16 | if (!reiserfs_xattrs_user(dentry->d_sb)) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 17 | return -EOPNOTSUPP; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 18 | return reiserfs_xattr_get(d_inode(dentry), name, buffer, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | static int |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 22 | user_set(const struct xattr_handler *handler, struct dentry *dentry, |
| 23 | const char *name, const void *buffer, size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 25 | if (strlen(name) < sizeof(XATTR_USER_PREFIX)) |
| 26 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 28 | if (!reiserfs_xattrs_user(dentry->d_sb)) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 29 | return -EOPNOTSUPP; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 30 | return reiserfs_xattr_set(d_inode(dentry), name, buffer, size, flags); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 33 | static 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 Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 36 | { |
Jeff Mahoney | 48b32a3 | 2009-03-30 14:02:38 -0400 | [diff] [blame] | 37 | const size_t len = name_len + 1; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 38 | |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 39 | if (!reiserfs_xattrs_user(dentry->d_sb)) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 40 | return 0; |
Jeff Mahoney | 48b32a3 | 2009-03-30 14:02:38 -0400 | [diff] [blame] | 41 | if (list && len <= list_size) { |
| 42 | memcpy(list, name, name_len); |
| 43 | list[name_len] = '\0'; |
| 44 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 45 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Stephen Hemminger | 94d09a9 | 2010-05-13 17:53:19 -0700 | [diff] [blame] | 48 | const struct xattr_handler reiserfs_xattr_user_handler = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | .prefix = XATTR_USER_PREFIX, |
| 50 | .get = user_get, |
| 51 | .set = user_set, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | .list = user_list, |
| 53 | }; |