blob: 3c5f27e4746a918a208946691699c81cf76da8cf [file] [log] [blame]
Vyacheslav Dubeyko127e5f52013-02-27 17:03:03 -08001/*
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 Leungbf29e882014-06-06 14:36:22 -07009#include <linux/nls.h>
10
Vyacheslav Dubeyko127e5f52013-02-27 17:03:03 -080011#include "hfsplus_fs.h"
12#include "xattr.h"
13
14static int hfsplus_trusted_getxattr(struct dentry *dentry, const char *name,
15 void *buffer, size_t size, int type)
16{
Hin-Tak Leungbf29e882014-06-06 14:36:22 -070017 char *xattr_name;
18 int res;
Vyacheslav Dubeyko127e5f52013-02-27 17:03:03 -080019
20 if (!strcmp(name, ""))
21 return -EINVAL;
22
Hin-Tak Leungbf29e882014-06-06 14:36:22 -070023 xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
24 GFP_KERNEL);
25 if (!xattr_name)
26 return -ENOMEM;
Vyacheslav Dubeyko127e5f52013-02-27 17:03:03 -080027 strcpy(xattr_name, XATTR_TRUSTED_PREFIX);
28 strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name);
29
Hin-Tak Leungbf29e882014-06-06 14:36:22 -070030 res = hfsplus_getxattr(dentry, xattr_name, buffer, size);
31 kfree(xattr_name);
32 return res;
Vyacheslav Dubeyko127e5f52013-02-27 17:03:03 -080033}
34
35static int hfsplus_trusted_setxattr(struct dentry *dentry, const char *name,
36 const void *buffer, size_t size, int flags, int type)
37{
Hin-Tak Leungbf29e882014-06-06 14:36:22 -070038 char *xattr_name;
39 int res;
Vyacheslav Dubeyko127e5f52013-02-27 17:03:03 -080040
41 if (!strcmp(name, ""))
42 return -EINVAL;
43
Hin-Tak Leungbf29e882014-06-06 14:36:22 -070044 xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
45 GFP_KERNEL);
46 if (!xattr_name)
47 return -ENOMEM;
Vyacheslav Dubeyko127e5f52013-02-27 17:03:03 -080048 strcpy(xattr_name, XATTR_TRUSTED_PREFIX);
49 strcpy(xattr_name + XATTR_TRUSTED_PREFIX_LEN, name);
50
Hin-Tak Leungbf29e882014-06-06 14:36:22 -070051 res = hfsplus_setxattr(dentry, xattr_name, buffer, size, flags);
52 kfree(xattr_name);
53 return res;
Vyacheslav Dubeyko127e5f52013-02-27 17:03:03 -080054}
55
56static size_t hfsplus_trusted_listxattr(struct dentry *dentry, char *list,
57 size_t list_size, const char *name, size_t name_len, int type)
58{
59 /*
60 * This method is not used.
61 * It is used hfsplus_listxattr() instead of generic_listxattr().
62 */
63 return -EOPNOTSUPP;
64}
65
66const struct xattr_handler hfsplus_xattr_trusted_handler = {
67 .prefix = XATTR_TRUSTED_PREFIX,
68 .list = hfsplus_trusted_listxattr,
69 .get = hfsplus_trusted_getxattr,
70 .set = hfsplus_trusted_setxattr,
71};