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.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
)
24 char buffer
[PATH_MAX
];
25 if (strncmp(name
, "user.virtfs.", 12) == 0) {
27 * Don't allow fetch of user.virtfs namesapce
28 * in case of mapped security
33 return lgetxattr(rpath(ctx
, path
, buffer
), name
, value
, size
);
36 static ssize_t
mp_user_listxattr(FsContext
*ctx
, const char *path
,
37 char *name
, void *value
, size_t size
)
39 int name_size
= strlen(name
) + 1;
40 if (strncmp(name
, "user.virtfs.", 12) == 0) {
42 /* check if it is a mapped posix acl */
43 if (strncmp(name
, "user.virtfs.system.posix_acl_", 29) == 0) {
44 /* adjust the name and size */
49 * Don't allow fetch of user.virtfs namesapce
50 * in case of mapped security
59 if (size
< name_size
) {
64 strncpy(value
, name
, name_size
);
68 static int mp_user_setxattr(FsContext
*ctx
, const char *path
, const char *name
,
69 void *value
, size_t size
, int flags
)
71 char buffer
[PATH_MAX
];
72 if (strncmp(name
, "user.virtfs.", 12) == 0) {
74 * Don't allow fetch of user.virtfs namesapce
75 * in case of mapped security
80 return lsetxattr(rpath(ctx
, path
, buffer
), name
, value
, size
, flags
);
83 static int mp_user_removexattr(FsContext
*ctx
,
84 const char *path
, const char *name
)
86 char buffer
[PATH_MAX
];
87 if (strncmp(name
, "user.virtfs.", 12) == 0) {
89 * Don't allow fetch of user.virtfs namesapce
90 * in case of mapped security
95 return lremovexattr(rpath(ctx
, path
, buffer
), name
);
98 XattrOperations mapped_user_xattr
= {
100 .getxattr
= mp_user_getxattr
,
101 .setxattr
= mp_user_setxattr
,
102 .listxattr
= mp_user_listxattr
,
103 .removexattr
= mp_user_removexattr
,
106 XattrOperations passthrough_user_xattr
= {
108 .getxattr
= pt_getxattr
,
109 .setxattr
= pt_setxattr
,
110 .listxattr
= pt_listxattr
,
111 .removexattr
= pt_removexattr
,