Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / hw / 9pfs / 9p-xattr-user.c
blob535677ed609b44df5d16a2e6bdff57e0a9252fc8
1 /*
2 * 9p user. xattr callback
4 * Copyright IBM, Corp. 2010
6 * Authors:
7 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
15 * Not so fast! You might want to read the 9p developer docs first:
16 * https://wiki.qemu.org/Documentation/9p
19 #include "qemu/osdep.h"
20 #include "9p.h"
21 #include "fsdev/file-op-9p.h"
22 #include "9p-xattr.h"
25 static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
26 const char *name, void *value, size_t size)
28 if (strncmp(name, "user.virtfs.", 12) == 0) {
30 * Don't allow fetch of user.virtfs namespace
31 * in case of mapped security
33 errno = ENOATTR;
34 return -1;
36 return local_getxattr_nofollow(ctx, path, name, value, size);
39 static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
40 char *name, void *value, size_t size)
42 int name_size = strlen(name) + 1;
43 if (strncmp(name, "user.virtfs.", 12) == 0) {
45 /* check if it is a mapped posix acl */
46 if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) {
47 /* adjust the name and size */
48 name += 12;
49 name_size -= 12;
50 } else {
52 * Don't allow fetch of user.virtfs namespace
53 * in case of mapped security
55 return 0;
58 if (!value) {
59 return name_size;
62 if (size < name_size) {
63 errno = ERANGE;
64 return -1;
67 /* name_size includes the trailing NUL. */
68 memcpy(value, name, name_size);
69 return name_size;
72 static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
73 void *value, size_t size, int flags)
75 if (strncmp(name, "user.virtfs.", 12) == 0) {
77 * Don't allow fetch of user.virtfs namespace
78 * in case of mapped security
80 errno = EACCES;
81 return -1;
83 return local_setxattr_nofollow(ctx, path, name, value, size, flags);
86 static int mp_user_removexattr(FsContext *ctx,
87 const char *path, const char *name)
89 if (strncmp(name, "user.virtfs.", 12) == 0) {
91 * Don't allow fetch of user.virtfs namespace
92 * in case of mapped security
94 errno = EACCES;
95 return -1;
97 return local_removexattr_nofollow(ctx, path, name);
100 XattrOperations mapped_user_xattr = {
101 .name = "user.",
102 .getxattr = mp_user_getxattr,
103 .setxattr = mp_user_setxattr,
104 .listxattr = mp_user_listxattr,
105 .removexattr = mp_user_removexattr,
108 XattrOperations passthrough_user_xattr = {
109 .name = "user.",
110 .getxattr = pt_getxattr,
111 .setxattr = pt_setxattr,
112 .listxattr = pt_listxattr,
113 .removexattr = pt_removexattr,