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.
14 #include <sys/types.h>
15 #include "hw/virtio/virtio.h"
16 #include "virtio-9p.h"
17 #include "fsdev/file-op-9p.h"
18 #include "virtio-9p-xattr.h"
21 static ssize_t
mp_user_getxattr(FsContext
*ctx
, const char *path
,
22 const char *name
, void *value
, size_t size
)
27 if (strncmp(name
, "user.virtfs.", 12) == 0) {
29 * Don't allow fetch of user.virtfs namesapce
30 * in case of mapped security
35 buffer
= rpath(ctx
, path
);
36 ret
= lgetxattr(buffer
, name
, value
, size
);
41 static ssize_t
mp_user_listxattr(FsContext
*ctx
, const char *path
,
42 char *name
, void *value
, size_t size
)
44 int name_size
= strlen(name
) + 1;
45 if (strncmp(name
, "user.virtfs.", 12) == 0) {
47 /* check if it is a mapped posix acl */
48 if (strncmp(name
, "user.virtfs.system.posix_acl_", 29) == 0) {
49 /* adjust the name and size */
54 * Don't allow fetch of user.virtfs namesapce
55 * in case of mapped security
64 if (size
< name_size
) {
69 /* name_size includes the trailing NUL. */
70 memcpy(value
, name
, name_size
);
74 static int mp_user_setxattr(FsContext
*ctx
, const char *path
, const char *name
,
75 void *value
, size_t size
, int flags
)
80 if (strncmp(name
, "user.virtfs.", 12) == 0) {
82 * Don't allow fetch of user.virtfs namesapce
83 * in case of mapped security
88 buffer
= rpath(ctx
, path
);
89 ret
= lsetxattr(buffer
, name
, value
, size
, flags
);
94 static int mp_user_removexattr(FsContext
*ctx
,
95 const char *path
, const char *name
)
100 if (strncmp(name
, "user.virtfs.", 12) == 0) {
102 * Don't allow fetch of user.virtfs namesapce
103 * in case of mapped security
108 buffer
= rpath(ctx
, path
);
109 ret
= lremovexattr(buffer
, name
);
114 XattrOperations mapped_user_xattr
= {
116 .getxattr
= mp_user_getxattr
,
117 .setxattr
= mp_user_setxattr
,
118 .listxattr
= mp_user_listxattr
,
119 .removexattr
= mp_user_removexattr
,
122 XattrOperations passthrough_user_xattr
= {
124 .getxattr
= pt_getxattr
,
125 .setxattr
= pt_setxattr
,
126 .listxattr
= pt_listxattr
,
127 .removexattr
= pt_removexattr
,