audio: Use DIV_ROUND_UP
[qemu.git] / hw / 9pfs / 9p-posix-acl.c
blobec003181cd33d6e3c87f5a9b448e3f99d43c770f
1 /*
2 * 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 "qemu/osdep.h"
15 #include "qemu/xattr.h"
16 #include "9p.h"
17 #include "fsdev/file-op-9p.h"
18 #include "9p-xattr.h"
20 #define MAP_ACL_ACCESS "user.virtfs.system.posix_acl_access"
21 #define MAP_ACL_DEFAULT "user.virtfs.system.posix_acl_default"
22 #define ACL_ACCESS "system.posix_acl_access"
23 #define ACL_DEFAULT "system.posix_acl_default"
25 static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path,
26 const char *name, void *value, size_t size)
28 char *buffer;
29 ssize_t ret;
31 buffer = rpath(ctx, path);
32 ret = lgetxattr(buffer, MAP_ACL_ACCESS, value, size);
33 g_free(buffer);
34 return ret;
37 static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
38 char *name, void *value, size_t osize)
40 ssize_t len = sizeof(ACL_ACCESS);
42 if (!value) {
43 return len;
46 if (osize < len) {
47 errno = ERANGE;
48 return -1;
51 /* len includes the trailing NUL */
52 memcpy(value, ACL_ACCESS, len);
53 return 0;
56 static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name,
57 void *value, size_t size, int flags)
59 char *buffer;
60 int ret;
62 buffer = rpath(ctx, path);
63 ret = lsetxattr(buffer, MAP_ACL_ACCESS, value, size, flags);
64 g_free(buffer);
65 return ret;
68 static int mp_pacl_removexattr(FsContext *ctx,
69 const char *path, const char *name)
71 int ret;
72 char *buffer;
74 buffer = rpath(ctx, path);
75 ret = lremovexattr(buffer, MAP_ACL_ACCESS);
76 if (ret == -1 && errno == ENODATA) {
78 * We don't get ENODATA error when trying to remove a
79 * posix acl that is not present. So don't throw the error
80 * even in case of mapped security model
82 errno = 0;
83 ret = 0;
85 g_free(buffer);
86 return ret;
89 static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path,
90 const char *name, void *value, size_t size)
92 char *buffer;
93 ssize_t ret;
95 buffer = rpath(ctx, path);
96 ret = lgetxattr(buffer, MAP_ACL_DEFAULT, value, size);
97 g_free(buffer);
98 return ret;
101 static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
102 char *name, void *value, size_t osize)
104 ssize_t len = sizeof(ACL_DEFAULT);
106 if (!value) {
107 return len;
110 if (osize < len) {
111 errno = ERANGE;
112 return -1;
115 /* len includes the trailing NUL */
116 memcpy(value, ACL_DEFAULT, len);
117 return 0;
120 static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name,
121 void *value, size_t size, int flags)
123 char *buffer;
124 int ret;
126 buffer = rpath(ctx, path);
127 ret = lsetxattr(buffer, MAP_ACL_DEFAULT, value, size, flags);
128 g_free(buffer);
129 return ret;
132 static int mp_dacl_removexattr(FsContext *ctx,
133 const char *path, const char *name)
135 int ret;
136 char *buffer;
138 buffer = rpath(ctx, path);
139 ret = lremovexattr(buffer, MAP_ACL_DEFAULT);
140 if (ret == -1 && errno == ENODATA) {
142 * We don't get ENODATA error when trying to remove a
143 * posix acl that is not present. So don't throw the error
144 * even in case of mapped security model
146 errno = 0;
147 ret = 0;
149 g_free(buffer);
150 return ret;
154 XattrOperations mapped_pacl_xattr = {
155 .name = "system.posix_acl_access",
156 .getxattr = mp_pacl_getxattr,
157 .setxattr = mp_pacl_setxattr,
158 .listxattr = mp_pacl_listxattr,
159 .removexattr = mp_pacl_removexattr,
162 XattrOperations mapped_dacl_xattr = {
163 .name = "system.posix_acl_default",
164 .getxattr = mp_dacl_getxattr,
165 .setxattr = mp_dacl_setxattr,
166 .listxattr = mp_dacl_listxattr,
167 .removexattr = mp_dacl_removexattr,
170 XattrOperations passthrough_acl_xattr = {
171 .name = "system.posix_acl_",
172 .getxattr = pt_getxattr,
173 .setxattr = pt_setxattr,
174 .listxattr = pt_listxattr,
175 .removexattr = pt_removexattr,
178 XattrOperations none_acl_xattr = {
179 .name = "system.posix_acl_",
180 .getxattr = notsup_getxattr,
181 .setxattr = notsup_setxattr,
182 .listxattr = notsup_listxattr,
183 .removexattr = notsup_removexattr,