]>
git.proxmox.com Git - mirror_qemu.git/blob - hw/9pfs/9p-xattr.c
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 "virtio-9p.h"
15 #include "fsdev/file-op-9p.h"
19 static XattrOperations
*get_xattr_operations(XattrOperations
**h
,
22 XattrOperations
*xops
;
23 for (xops
= *(h
)++; xops
!= NULL
; xops
= *(h
)++) {
24 if (!strncmp(name
, xops
->name
, strlen(xops
->name
))) {
31 ssize_t
v9fs_get_xattr(FsContext
*ctx
, const char *path
,
32 const char *name
, void *value
, size_t size
)
34 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
36 return xops
->getxattr(ctx
, path
, name
, value
, size
);
42 ssize_t
pt_listxattr(FsContext
*ctx
, const char *path
,
43 char *name
, void *value
, size_t size
)
45 int name_size
= strlen(name
) + 1;
50 if (size
< name_size
) {
55 /* no need for strncpy: name_size is strlen(name)+1 */
56 memcpy(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
)
71 XattrOperations
*xops
;
72 char *orig_value
, *orig_value_start
;
73 ssize_t xattr_len
, parsed_len
= 0, attr_len
;
75 /* Get the actual len */
76 buffer
= rpath(ctx
, path
);
77 xattr_len
= llistxattr(buffer
, value
, 0);
83 /* Now fetch the xattr and find the actual size */
84 orig_value
= g_malloc(xattr_len
);
85 xattr_len
= llistxattr(buffer
, orig_value
, xattr_len
);
88 /* store the orig pointer */
89 orig_value_start
= orig_value
;
90 while (xattr_len
> parsed_len
) {
91 xops
= get_xattr_operations(ctx
->xops
, orig_value
);
97 size
+= xops
->listxattr(ctx
, path
, orig_value
, value
, vsize
);
99 size
= xops
->listxattr(ctx
, path
, orig_value
, value
, vsize
);
107 /* Got the next entry */
108 attr_len
= strlen(orig_value
) + 1;
109 parsed_len
+= attr_len
;
110 orig_value
+= attr_len
;
113 size
= value
- ovalue
;
117 g_free(orig_value_start
);
121 int v9fs_set_xattr(FsContext
*ctx
, const char *path
, const char *name
,
122 void *value
, size_t size
, int flags
)
124 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
126 return xops
->setxattr(ctx
, path
, name
, value
, size
, flags
);
133 int v9fs_remove_xattr(FsContext
*ctx
,
134 const char *path
, const char *name
)
136 XattrOperations
*xops
= get_xattr_operations(ctx
->xops
, name
);
138 return xops
->removexattr(ctx
, path
, name
);
145 XattrOperations
*mapped_xattr_ops
[] = {
152 XattrOperations
*passthrough_xattr_ops
[] = {
153 &passthrough_user_xattr
,
154 &passthrough_acl_xattr
,
158 /* for .user none model should be same as passthrough */
159 XattrOperations
*none_xattr_ops
[] = {
160 &passthrough_user_xattr
,