Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/ext2/xattr_user.c |
| 4 | * Handler for extended user attributes. |
| 5 | * |
| 6 | * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/string.h> |
| 11 | #include "ext2.h" |
| 12 | #include "xattr.h" |
| 13 | |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 14 | static bool |
| 15 | ext2_xattr_user_list(struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | { |
Andreas Gruenbacher | 764a5c6 | 2015-12-02 14:44:43 +0100 | [diff] [blame] | 17 | return test_opt(dentry->d_sb, XATTR_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | static int |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 21 | ext2_xattr_user_get(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 22 | struct dentry *unused, struct inode *inode, |
| 23 | const char *name, void *buffer, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 25 | if (!test_opt(inode->i_sb, XATTR_USER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | return -EOPNOTSUPP; |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 27 | return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 28 | name, buffer, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static int |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 32 | ext2_xattr_user_set(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 33 | struct dentry *unused, struct inode *inode, |
| 34 | const char *name, const void *value, |
| 35 | size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 37 | if (!test_opt(inode->i_sb, XATTR_USER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 40 | return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 41 | name, value, size, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Stephen Hemminger | 749c72ef | 2010-05-13 17:53:16 -0700 | [diff] [blame] | 44 | const struct xattr_handler ext2_xattr_user_handler = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | .prefix = XATTR_USER_PREFIX, |
| 46 | .list = ext2_xattr_user_list, |
| 47 | .get = ext2_xattr_user_get, |
| 48 | .set = ext2_xattr_user_set, |
| 49 | }; |