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 "qemu/osdep.h"
16 #include "fsdev/file-op-9p.h"
22 static XattrOperations
*get_xattr_operations(XattrOperations
**h
,
25 XattrOperations
*xops
;
26 for (xops
= *(h
)++; xops
!= NULL
; xops
= *(h
)++) {
27 if (!strncmp(name
, xops
->name
, strlen(xops
->name
))) {
34 ssize_t
v9fs_get_xattr(FsContext
*ctx
, const char *path
,
35 const char *name
, void *value
, size_t size
)
37 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
39 return xops
->getxattr(ctx
, path
, name
, value
, size
);
45 ssize_t
pt_listxattr(FsContext
*ctx
, const char *path
,
46 char *name
, void *value
, size_t size
)
48 int name_size
= strlen(name
) + 1;
53 if (size
< name_size
) {
58 /* no need for strncpy: name_size is strlen(name)+1 */
59 memcpy(value
, name
, name_size
);
65 * Get the list and pass to each layer to find out whether
66 * to send the data or not
68 ssize_t
v9fs_list_xattr(FsContext
*ctx
, const char *path
,
69 void *value
, size_t vsize
)
74 XattrOperations
*xops
;
75 char *orig_value
, *orig_value_start
;
76 ssize_t xattr_len
, parsed_len
= 0, attr_len
;
78 /* Get the actual len */
79 buffer
= rpath(ctx
, path
);
80 xattr_len
= llistxattr(buffer
, value
, 0);
86 /* Now fetch the xattr and find the actual size */
87 orig_value
= g_malloc(xattr_len
);
88 xattr_len
= llistxattr(buffer
, orig_value
, xattr_len
);
91 /* store the orig pointer */
92 orig_value_start
= orig_value
;
93 while (xattr_len
> parsed_len
) {
94 xops
= get_xattr_operations(ctx
->xops
, orig_value
);
100 size
+= xops
->listxattr(ctx
, path
, orig_value
, value
, vsize
);
102 size
= xops
->listxattr(ctx
, path
, orig_value
, value
, vsize
);
110 /* Got the next entry */
111 attr_len
= strlen(orig_value
) + 1;
112 parsed_len
+= attr_len
;
113 orig_value
+= attr_len
;
116 size
= value
- ovalue
;
120 g_free(orig_value_start
);
124 int v9fs_set_xattr(FsContext
*ctx
, const char *path
, const char *name
,
125 void *value
, size_t size
, int flags
)
127 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
129 return xops
->setxattr(ctx
, path
, name
, value
, size
, flags
);
136 int v9fs_remove_xattr(FsContext
*ctx
,
137 const char *path
, const char *name
)
139 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
141 return xops
->removexattr(ctx
, path
, name
);
148 ssize_t
local_getxattr_nofollow(FsContext
*ctx
, const char *path
,
149 const char *name
, void *value
, size_t size
)
151 char *dirpath
= g_path_get_dirname(path
);
152 char *filename
= g_path_get_basename(path
);
156 dirfd
= local_opendir_nofollow(ctx
, dirpath
);
161 ret
= fgetxattrat_nofollow(dirfd
, filename
, name
, value
, size
);
162 close_preserve_errno(dirfd
);
169 ssize_t
pt_getxattr(FsContext
*ctx
, const char *path
, const char *name
,
170 void *value
, size_t size
)
172 return local_getxattr_nofollow(ctx
, path
, name
, value
, size
);
175 int pt_setxattr(FsContext
*ctx
, const char *path
, const char *name
, void *value
,
176 size_t size
, int flags
)
181 buffer
= rpath(ctx
, path
);
182 ret
= lsetxattr(buffer
, name
, value
, size
, flags
);
187 int pt_removexattr(FsContext
*ctx
, const char *path
, const char *name
)
192 buffer
= rpath(ctx
, path
);
193 ret
= lremovexattr(path
, name
);
198 ssize_t
notsup_getxattr(FsContext
*ctx
, const char *path
, const char *name
,
199 void *value
, size_t size
)
205 int notsup_setxattr(FsContext
*ctx
, const char *path
, const char *name
,
206 void *value
, size_t size
, int flags
)
212 ssize_t
notsup_listxattr(FsContext
*ctx
, const char *path
, char *name
,
213 void *value
, size_t size
)
218 int notsup_removexattr(FsContext
*ctx
, const char *path
, const char *name
)
224 XattrOperations
*mapped_xattr_ops
[] = {
231 XattrOperations
*passthrough_xattr_ops
[] = {
232 &passthrough_user_xattr
,
233 &passthrough_acl_xattr
,
237 /* for .user none model should be same as passthrough */
238 XattrOperations
*none_xattr_ops
[] = {
239 &passthrough_user_xattr
,