balloon: Separate out stat and balloon handling
[qemu/agraf.git] / hw / 9pfs / virtio-9p-posix-acl.c
blobf5b392e1804e6c51c6fd635bf2ccf1161475e945
1 /*
2 * Virtio 9p system.posix* 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 <attr/xattr.h>
16 #include "hw/virtio.h"
17 #include "virtio-9p.h"
18 #include "fsdev/file-op-9p.h"
19 #include "virtio-9p-xattr.h"
21 #define MAP_ACL_ACCESS "user.virtfs.system.posix_acl_access"
22 #define MAP_ACL_DEFAULT "user.virtfs.system.posix_acl_default"
23 #define ACL_ACCESS "system.posix_acl_access"
24 #define ACL_DEFAULT "system.posix_acl_default"
26 static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
27 const char *name, void *value, size_t size)
29 char buffer[PATH_MAX];
30 return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size);
33 static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
34 char *name, void *value, size_t osize)
36 ssize_t len = sizeof(ACL_ACCESS);
38 if (!value) {
39 return len;
42 if (osize < len) {
43 errno = ERANGE;
44 return -1;
47 strncpy(value, ACL_ACCESS, len);
48 return 0;
51 static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
52 void *value, size_t size, int flags)
54 char buffer[PATH_MAX];
55 return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value,
56 size, flags);
59 static int mp_pacl_removexattr(FsContext *ctx,
60 const char *path, const char *name)
62 int ret;
63 char buffer[PATH_MAX];
64 ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS);
65 if (ret == -1 && errno == ENODATA) {
67 * We don't get ENODATA error when trying to remove a
68 * posix acl that is not present. So don't throw the error
69 * even in case of mapped security model
71 errno = 0;
72 ret = 0;
74 return ret;
77 static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
78 const char *name, void *value, size_t size)
80 char buffer[PATH_MAX];
81 return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size);
84 static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
85 char *name, void *value, size_t osize)
87 ssize_t len = sizeof(ACL_DEFAULT);
89 if (!value) {
90 return len;
93 if (osize < len) {
94 errno = ERANGE;
95 return -1;
98 strncpy(value, ACL_DEFAULT, len);
99 return 0;
102 static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
103 void *value, size_t size, int flags)
105 char buffer[PATH_MAX];
106 return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value,
107 size, flags);
110 static int mp_dacl_removexattr(FsContext *ctx,
111 const char *path, const char *name)
113 int ret;
114 char buffer[PATH_MAX];
115 ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT);
116 if (ret == -1 && errno == ENODATA) {
118 * We don't get ENODATA error when trying to remove a
119 * posix acl that is not present. So don't throw the error
120 * even in case of mapped security model
122 errno = 0;
123 ret = 0;
125 return ret;
129 XattrOperations mapped_pacl_xattr = {
130 .name = "system.posix_acl_access",
131 .getxattr = mp_pacl_getxattr,
132 .setxattr = mp_pacl_setxattr,
133 .listxattr = mp_pacl_listxattr,
134 .removexattr = mp_pacl_removexattr,
137 XattrOperations mapped_dacl_xattr = {
138 .name = "system.posix_acl_default",
139 .getxattr = mp_dacl_getxattr,
140 .setxattr = mp_dacl_setxattr,
141 .listxattr = mp_dacl_listxattr,
142 .removexattr = mp_dacl_removexattr,
145 XattrOperations passthrough_acl_xattr = {
146 .name = "system.posix_acl_",
147 .getxattr = pt_getxattr,
148 .setxattr = pt_setxattr,
149 .listxattr = pt_listxattr,
150 .removexattr = pt_removexattr,
153 XattrOperations none_acl_xattr = {
154 .name = "system.posix_acl_",
155 .getxattr = notsup_getxattr,
156 .setxattr = notsup_setxattr,
157 .listxattr = notsup_listxattr,
158 .removexattr = notsup_removexattr,