1
2
3
4
5
6
7
8
9
10
11
12
13
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"
19
20
21static ssize_t mp_user_getxattr(FsContext *ctx, const char *path,
22 const char *name, void *value, size_t size)
23{
24 char buffer[PATH_MAX];
25 if (strncmp(name, "user.virtfs.", 12) == 0) {
26
27
28
29
30 errno = ENOATTR;
31 return -1;
32 }
33 return lgetxattr(rpath(ctx, path, buffer), name, value, size);
34}
35
36static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
37 char *name, void *value, size_t size)
38{
39 int name_size = strlen(name) + 1;
40 if (strncmp(name, "user.virtfs.", 12) == 0) {
41
42
43 if (strncmp(name, "user.virtfs.system.posix_acl_", 29) == 0) {
44
45 name += 12;
46 name_size -= 12;
47 } else {
48
49
50
51
52 return 0;
53 }
54 }
55 if (!value) {
56 return name_size;
57 }
58
59 if (size < name_size) {
60 errno = ERANGE;
61 return -1;
62 }
63
64
65 memcpy(value, name, name_size);
66 return name_size;
67}
68
69static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
70 void *value, size_t size, int flags)
71{
72 char buffer[PATH_MAX];
73 if (strncmp(name, "user.virtfs.", 12) == 0) {
74
75
76
77
78 errno = EACCES;
79 return -1;
80 }
81 return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags);
82}
83
84static int mp_user_removexattr(FsContext *ctx,
85 const char *path, const char *name)
86{
87 char buffer[PATH_MAX];
88 if (strncmp(name, "user.virtfs.", 12) == 0) {
89
90
91
92
93 errno = EACCES;
94 return -1;
95 }
96 return lremovexattr(rpath(ctx, path, buffer), name);
97}
98
99XattrOperations mapped_user_xattr = {
100 .name = "user.",
101 .getxattr = mp_user_getxattr,
102 .setxattr = mp_user_setxattr,
103 .listxattr = mp_user_listxattr,
104 .removexattr = mp_user_removexattr,
105};
106
107XattrOperations passthrough_user_xattr = {
108 .name = "user.",
109 .getxattr = pt_getxattr,
110 .setxattr = pt_setxattr,
111 .listxattr = pt_listxattr,
112 .removexattr = pt_removexattr,
113};
114