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.
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 strncpy(value
, name
, name_size
);
62 * Get the list and pass to each layer to find out whether
63 * to send the data or not
65 ssize_t
v9fs_list_xattr(FsContext
*ctx
, const char *path
,
66 void *value
, size_t vsize
)
70 XattrOperations
*xops
;
71 char *orig_value
, *orig_value_start
;
72 ssize_t xattr_len
, parsed_len
= 0, attr_len
;
74 /* Get the actual len */
75 xattr_len
= llistxattr(rpath(ctx
, path
), value
, 0);
80 /* Now fetch the xattr and find the actual size */
81 orig_value
= qemu_malloc(xattr_len
);
82 xattr_len
= llistxattr(rpath(ctx
, path
), orig_value
, xattr_len
);
84 /* store the orig pointer */
85 orig_value_start
= orig_value
;
86 while (xattr_len
> parsed_len
) {
87 xops
= get_xattr_operations(ctx
->xops
, orig_value
);
93 size
+= xops
->listxattr(ctx
, path
, orig_value
, value
, vsize
);
95 size
= xops
->listxattr(ctx
, path
, orig_value
, value
, vsize
);
103 /* Got the next entry */
104 attr_len
= strlen(orig_value
) + 1;
105 parsed_len
+= attr_len
;
106 orig_value
+= attr_len
;
109 size
= value
- ovalue
;
113 qemu_free(orig_value_start
);
117 int v9fs_set_xattr(FsContext
*ctx
, const char *path
, const char *name
,
118 void *value
, size_t size
, int flags
)
120 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
122 return xops
->setxattr(ctx
, path
, name
, value
, size
, flags
);
129 int v9fs_remove_xattr(FsContext
*ctx
,
130 const char *path
, const char *name
)
132 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
134 return xops
->removexattr(ctx
, path
, name
);
141 XattrOperations
*mapped_xattr_ops
[] = {
148 XattrOperations
*passthrough_xattr_ops
[] = {
149 &passthrough_user_xattr
,
150 &passthrough_acl_xattr
,
154 /* for .user none model should be same as passthrough */
155 XattrOperations
*none_xattr_ops
[] = {
156 &passthrough_user_xattr
,