Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/reiserfs_fs.h> |
| 2 | #include <linux/errno.h> |
| 3 | #include <linux/fs.h> |
| 4 | #include <linux/pagemap.h> |
| 5 | #include <linux/xattr.h> |
| 6 | #include <linux/reiserfs_xattr.h> |
| 7 | #include <asm/uaccess.h> |
| 8 | |
| 9 | #ifdef CONFIG_REISERFS_FS_POSIX_ACL |
| 10 | # include <linux/reiserfs_acl.h> |
| 11 | #endif |
| 12 | |
| 13 | #define XATTR_USER_PREFIX "user." |
| 14 | |
| 15 | static int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 16 | user_get(struct inode *inode, const char *name, void *buffer, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | { |
| 18 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 19 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 21 | if (strlen(name) < sizeof(XATTR_USER_PREFIX)) |
| 22 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 24 | if (!reiserfs_xattrs_user(inode->i_sb)) |
| 25 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 27 | error = reiserfs_permission_locked(inode, MAY_READ, NULL); |
| 28 | if (error) |
| 29 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 31 | return reiserfs_xattr_get(inode, name, buffer, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 35 | user_set(struct inode *inode, const char *name, const void *buffer, |
| 36 | size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
| 38 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 39 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 41 | if (strlen(name) < sizeof(XATTR_USER_PREFIX)) |
| 42 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 44 | if (!reiserfs_xattrs_user(inode->i_sb)) |
| 45 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 47 | if (!S_ISREG(inode->i_mode) && |
| 48 | (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX)) |
| 49 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 51 | error = reiserfs_permission_locked(inode, MAY_WRITE, NULL); |
| 52 | if (error) |
| 53 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 55 | return reiserfs_xattr_set(inode, name, buffer, size, flags); |
| 56 | } |
| 57 | |
| 58 | static int user_del(struct inode *inode, const char *name) |
| 59 | { |
| 60 | int error; |
| 61 | |
| 62 | if (strlen(name) < sizeof(XATTR_USER_PREFIX)) |
| 63 | return -EINVAL; |
| 64 | |
| 65 | if (!reiserfs_xattrs_user(inode->i_sb)) |
| 66 | return -EOPNOTSUPP; |
| 67 | |
| 68 | if (!S_ISREG(inode->i_mode) && |
| 69 | (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX)) |
| 70 | return -EPERM; |
| 71 | |
| 72 | error = reiserfs_permission_locked(inode, MAY_WRITE, NULL); |
| 73 | if (error) |
| 74 | return error; |
| 75 | |
| 76 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static int |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 80 | user_list(struct inode *inode, const char *name, int namelen, char *out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 82 | int len = namelen; |
| 83 | if (!reiserfs_xattrs_user(inode->i_sb)) |
| 84 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 86 | if (out) |
| 87 | memcpy(out, name, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 89 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | struct reiserfs_xattr_handler user_handler = { |
| 93 | .prefix = XATTR_USER_PREFIX, |
| 94 | .get = user_get, |
| 95 | .set = user_set, |
| 96 | .del = user_del, |
| 97 | .list = user_list, |
| 98 | }; |