Merge remote-tracking branch 'remotes/aurel/tags/pull-tcg-mips-20150921' into staging
[qemu/cris-port.git] / hw / 9pfs / virtio-9p-xattr-user.c
blob46133e06dbdfbc05a199911c7d5dae8d32d6675c
1 /*
2 * Virtio 9p user. xattr callback
4 * Copyright IBM, Corp. 2010
6 * Authors:
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)
24 char *buffer;
25 ssize_t ret;
27 if (strncmp(name, "user.virtfs.", 12) == 0) {
29 * Don't allow fetch of user.virtfs namesapce
30 * in case of mapped security
32 errno = ENOATTR;
33 return -1;
35 buffer = rpath(ctx, path);
36 ret = lgetxattr(buffer, name, value, size);
37 g_free(buffer);
38 return ret;
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 */
50 name += 12;
51 name_size -= 12;
52 } else {
54 * Don't allow fetch of user.virtfs namesapce
55 * in case of mapped security
57 return 0;
60 if (!value) {
61 return name_size;
64 if (size < name_size) {
65 errno = ERANGE;
66 return -1;
69 /* name_size includes the trailing NUL. */
70 memcpy(value, name, name_size);
71 return name_size;
74 static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name,
75 void *value, size_t size, int flags)
77 char *buffer;
78 int ret;
80 if (strncmp(name, "user.virtfs.", 12) == 0) {
82 * Don't allow fetch of user.virtfs namesapce
83 * in case of mapped security
85 errno = EACCES;
86 return -1;
88 buffer = rpath(ctx, path);
89 ret = lsetxattr(buffer, name, value, size, flags);
90 g_free(buffer);
91 return ret;
94 static int mp_user_removexattr(FsContext *ctx,
95 const char *path, const char *name)
97 char *buffer;
98 int ret;
100 if (strncmp(name, "user.virtfs.", 12) == 0) {
102 * Don't allow fetch of user.virtfs namesapce
103 * in case of mapped security
105 errno = EACCES;
106 return -1;
108 buffer = rpath(ctx, path);
109 ret = lremovexattr(buffer, name);
110 g_free(buffer);
111 return ret;
114 XattrOperations mapped_user_xattr = {
115 .name = "user.",
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 = {
123 .name = "user.",
124 .getxattr = pt_getxattr,
125 .setxattr = pt_setxattr,
126 .listxattr = pt_listxattr,
127 .removexattr = pt_removexattr,