2 * Virtio 9p xattr callback
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 "hw/virtio.h"
15 #include "virtio-9p.h"
16 #include "fsdev/file-op-9p.h"
17 #include "virtio-9p-xattr.h"
20 static XattrOperations
*get_xattr_operations(XattrOperations
**h
,
23 XattrOperations
*xops
;
24 for (xops
= *(h
)++; xops
!= NULL
; xops
= *(h
)++) {
25 if (!strncmp(name
, xops
->name
, strlen(xops
->name
))) {
32 ssize_t
v9fs_get_xattr(FsContext
*ctx
, const char *path
,
33 const char *name
, void *value
, size_t size
)
35 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
37 return xops
->getxattr(ctx
, path
, name
, value
, size
);
43 ssize_t
pt_listxattr(FsContext
*ctx
, const char *path
,
44 char *name
, void *value
, size_t size
)
46 int name_size
= strlen(name
) + 1;
51 if (size
< name_size
) {
56 /* no need for strncpy: name_size is strlen(name)+1 */
57 memcpy(value
, name
, name_size
);
63 * Get the list and pass to each layer to find out whether
64 * to send the data or not
66 ssize_t
v9fs_list_xattr(FsContext
*ctx
, const char *path
,
67 void *value
, size_t vsize
)
70 char buffer
[PATH_MAX
];
72 XattrOperations
*xops
;
73 char *orig_value
, *orig_value_start
;
74 ssize_t xattr_len
, parsed_len
= 0, attr_len
;
76 /* Get the actual len */
77 xattr_len
= llistxattr(rpath(ctx
, path
, buffer
), value
, 0);
82 /* Now fetch the xattr and find the actual size */
83 orig_value
= g_malloc(xattr_len
);
84 xattr_len
= llistxattr(rpath(ctx
, path
, buffer
), orig_value
, xattr_len
);
86 /* store the orig pointer */
87 orig_value_start
= orig_value
;
88 while (xattr_len
> parsed_len
) {
89 xops
= get_xattr_operations(ctx
->xops
, orig_value
);
95 size
+= xops
->listxattr(ctx
, path
, orig_value
, value
, vsize
);
97 size
= xops
->listxattr(ctx
, path
, orig_value
, value
, vsize
);
105 /* Got the next entry */
106 attr_len
= strlen(orig_value
) + 1;
107 parsed_len
+= attr_len
;
108 orig_value
+= attr_len
;
111 size
= value
- ovalue
;
115 g_free(orig_value_start
);
119 int v9fs_set_xattr(FsContext
*ctx
, const char *path
, const char *name
,
120 void *value
, size_t size
, int flags
)
122 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
124 return xops
->setxattr(ctx
, path
, name
, value
, size
, flags
);
131 int v9fs_remove_xattr(FsContext
*ctx
,
132 const char *path
, const char *name
)
134 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
136 return xops
->removexattr(ctx
, path
, name
);
143 XattrOperations
*mapped_xattr_ops
[] = {
150 XattrOperations
*passthrough_xattr_ops
[] = {
151 &passthrough_user_xattr
,
152 &passthrough_acl_xattr
,
156 /* for .user none model should be same as passthrough */
157 XattrOperations
*none_xattr_ops
[] = {
158 &passthrough_user_xattr
,