aboutsummaryrefslogtreecommitdiff
path: root/hw/9pfs/9p.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/9pfs/9p.c')
-rw-r--r--hw/9pfs/9p.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index dfe293d11d..119ee58496 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -12,6 +12,7 @@
*/
#include "qemu/osdep.h"
+#include <glib/gprintf.h>
#include "hw/virtio/virtio.h"
#include "qapi/error.h"
#include "qemu/error-report.h"
@@ -179,6 +180,20 @@ void v9fs_path_free(V9fsPath *path)
path->size = 0;
}
+
+void GCC_FMT_ATTR(2, 3)
+v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...)
+{
+ va_list ap;
+
+ v9fs_path_free(path);
+
+ va_start(ap, fmt);
+ /* Bump the size for including terminating NULL */
+ path->size = g_vasprintf(&path->data, fmt, ap) + 1;
+ va_end(ap);
+}
+
void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs)
{
v9fs_path_free(lhs);
@@ -810,15 +825,15 @@ static int stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name,
v9stat->mtime = stbuf->st_mtime;
v9stat->length = stbuf->st_size;
- v9fs_string_null(&v9stat->uid);
- v9fs_string_null(&v9stat->gid);
- v9fs_string_null(&v9stat->muid);
+ v9fs_string_free(&v9stat->uid);
+ v9fs_string_free(&v9stat->gid);
+ v9fs_string_free(&v9stat->muid);
v9stat->n_uid = stbuf->st_uid;
v9stat->n_gid = stbuf->st_gid;
v9stat->n_muid = 0;
- v9fs_string_null(&v9stat->extension);
+ v9fs_string_free(&v9stat->extension);
if (v9stat->mode & P9_STAT_MODE_SYMLINK) {
err = v9fs_co_readlink(pdu, name, &v9stat->extension);
@@ -917,10 +932,8 @@ static void v9fs_fix_path(V9fsPath *dst, V9fsPath *src, int len)
V9fsPath str;
v9fs_path_init(&str);
v9fs_path_copy(&str, dst);
- v9fs_string_sprintf((V9fsString *)dst, "%s%s", src->data, str.data+len);
+ v9fs_path_sprintf(dst, "%s%s", src->data, str.data + len);
v9fs_path_free(&str);
- /* +1 to include terminating NULL */
- dst->size++;
}
static inline bool is_ro_export(FsContext *ctx)
@@ -1320,13 +1333,14 @@ static void v9fs_walk(void *opaque)
goto out_nofid;
}
+ v9fs_path_init(&dpath);
+ v9fs_path_init(&path);
+
err = fid_to_qid(pdu, fidp, &qid);
if (err < 0) {
goto out;
}
- v9fs_path_init(&dpath);
- v9fs_path_init(&path);
/*
* Both dpath and path initially poin to fidp.
* Needed to handle request with nwnames == 0