Vyacheslav Dubeyko | 127e5f5 | 2013-02-27 17:03:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/hfsplus/xattr_trusted.c |
| 3 | * |
| 4 | * Vyacheslav Dubeyko <slava@dubeyko.com> |
| 5 | * |
| 6 | * Handler for trusted extended attributes. |
| 7 | */ |
| 8 | |
Hin-Tak Leung | bf29e88 | 2014-06-06 14:36:22 -0700 | [diff] [blame] | 9 | #include <linux/nls.h> |
| 10 | |
Vyacheslav Dubeyko | 127e5f5 | 2013-02-27 17:03:03 -0800 | [diff] [blame] | 11 | #include "hfsplus_fs.h" |
| 12 | #include "xattr.h" |
| 13 | |
| 14 | static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name, |
| 15 | void *buffer, size_t size, int type) |
| 16 | { |
Fabian Frederick | a3cef4c | 2015-04-16 12:46:58 -0700 | [diff] [blame^] | 17 | return hfsplus_getxattr(dentry, name, buffer, size, |
| 18 | XATTR_TRUSTED_PREFIX, |
| 19 | XATTR_TRUSTED_PREFIX_LEN); |
Vyacheslav Dubeyko | 127e5f5 | 2013-02-27 17:03:03 -0800 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name, |
| 23 | const void *buffer, size_t size, int flags, int type) |
| 24 | { |
Hin-Tak Leung | bf29e88 | 2014-06-06 14:36:22 -0700 | [diff] [blame] | 25 | char *xattr_name; |
| 26 | int res; |
Vyacheslav Dubeyko | 127e5f5 | 2013-02-27 17:03:03 -0800 | [diff] [blame] | 27 | |
| 28 | if (!strcmp(name, "")) |
| 29 | return -EINVAL; |
| 30 | |
Hin-Tak Leung | bf29e88 | 2014-06-06 14:36:22 -0700 | [diff] [blame] | 31 | xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, |
| 32 | GFP_KERNEL); |
| 33 | if (!xattr_name) |
| 34 | return -ENOMEM; |
Vyacheslav Dubeyko | 127e5f5 | 2013-02-27 17:03:03 -0800 | [diff] [blame] | 35 | strcpy(xattr_name, XATTR_TRUSTED_PREFIX); |
| 36 | strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name); |
| 37 | |
Hin-Tak Leung | bf29e88 | 2014-06-06 14:36:22 -0700 | [diff] [blame] | 38 | res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags); |
| 39 | kfree(xattr_name); |
| 40 | return res; |
Vyacheslav Dubeyko | 127e5f5 | 2013-02-27 17:03:03 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list, |
| 44 | size_t list_size, const char *name, size_t name_len, int type) |
| 45 | { |
| 46 | /* |
| 47 | * This method is not used. |
| 48 | * It is used hfsplus_listxattr() instead of generic_listxattr(). |
| 49 | */ |
| 50 | return -EOPNOTSUPP; |
| 51 | } |
| 52 | |
| 53 | const struct xattr_handler hfsplus_xattr_trusted_handler = { |
| 54 | .prefix = XATTR_TRUSTED_PREFIX, |
| 55 | .list = hfsplus_trusted_listxattr, |
| 56 | .get = hfsplus_trusted_getxattr, |
| 57 | .set = hfsplus_trusted_setxattr, |
| 58 | }; |