2 * Virtio 9p user. xattr callback
4 * Copyright IBM, Corp. 2010
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.
13 #include <sys/types.h>
14 #include "hw/virtio/virtio.h"
15 #include "virtio-9p.h"
16 #include "fsdev/file-op-9p.h"
17 #include "virtio-9p-xattr.h"
20 static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
21 const char *name, void *value, size_t size)
26 if (strncmp(name, "user.virtfs.", 12) == 0) {
28 * Don't allow fetch of user.virtfs namesapce
29 * in case of mapped security
34 buffer = rpath(ctx, path);
36 ret = lgetxattr(buffer, name, value, size);
38 ret = getxattr(buffer, name, value, size, 0, XATTR_NOFOLLOW);
44 static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
45 char *name, void *value, size_t size)
47 int name_size = strlen(name) + 1;
48 if (strncmp(name, "user.virtfs.", 12) == 0) {
50 /* check if it is a mapped posix acl */
51 if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) {
52 /* adjust the name and size */
57 * Don't allow fetch of user.virtfs namesapce
58 * in case of mapped security
67 if (size < name_size) {
72 /* name_size includes the trailing NUL. */
73 memcpy(value, name, name_size);
77 static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
78 void *value, size_t size, int flags)
83 if (strncmp(name, "user.virtfs.", 12) == 0) {
85 * Don't allow fetch of user.virtfs namesapce
86 * in case of mapped security
91 buffer = rpath(ctx, path);
93 ret = lsetxattr(buffer, name, value, size, flags);
95 ret = setxattr(buffer, name, value, size, 0, flags | XATTR_NOFOLLOW);
101 static int mp_user_removexattr(FsContext *ctx,
102 const char *path, const char *name)
107 if (strncmp(name, "user.virtfs.", 12) == 0) {
109 * Don't allow fetch of user.virtfs namesapce
110 * in case of mapped security
115 buffer = rpath(ctx, path);
117 ret = lremovexattr(buffer, name);
119 ret = removexattr(buffer, name, XATTR_NOFOLLOW);
125 XattrOperations mapped_user_xattr = {
127 .getxattr = mp_user_getxattr,
128 .setxattr = mp_user_setxattr,
129 .listxattr = mp_user_listxattr,
130 .removexattr = mp_user_removexattr,
133 XattrOperations passthrough_user_xattr = {
135 .getxattr = pt_getxattr,
136 .setxattr = pt_setxattr,
137 .listxattr = pt_listxattr,
138 .removexattr = pt_removexattr,