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)
23 char buffer[PATH_MAX];
24 if (strncmp(name, "user.virtfs.", 12) == 0) {
26 * Don't allow fetch of user.virtfs namesapce
27 * in case of mapped security
33 return lgetxattr(rpath(ctx, path, buffer), name, value, size);
35 return getxattr(rpath(ctx, path, buffer), name, value, size, 0, XATTR_NOFOLLOW);
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 */
52 * Don't allow fetch of user.virtfs namesapce
53 * in case of mapped security
62 if (size < name_size) {
67 /* name_size includes the trailing NUL. */
68 memcpy(value, name, 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 char buffer[PATH_MAX];
76 if (strncmp(name, "user.virtfs.", 12) == 0) {
78 * Don't allow fetch of user.virtfs namesapce
79 * in case of mapped security
85 return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags);
87 return setxattr(rpath(ctx, path, buffer), name, value, size, 0, flags | XATTR_NOFOLLOW);
91 static int mp_user_removexattr(FsContext *ctx,
92 const char *path, const char *name)
94 char buffer[PATH_MAX];
95 if (strncmp(name, "user.virtfs.", 12) == 0) {
97 * Don't allow fetch of user.virtfs namesapce
98 * in case of mapped security
104 return lremovexattr(rpath(ctx, path, buffer), name);
106 return removexattr(rpath(ctx, path, buffer), name, XATTR_NOFOLLOW);
110 XattrOperations mapped_user_xattr = {
112 .getxattr = mp_user_getxattr,
113 .setxattr = mp_user_setxattr,
114 .listxattr = mp_user_listxattr,
115 .removexattr = mp_user_removexattr,
118 XattrOperations passthrough_user_xattr = {
120 .getxattr = pt_getxattr,
121 .setxattr = pt_setxattr,
122 .listxattr = pt_listxattr,
123 .removexattr = pt_removexattr,