summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hw/9pfs/9p.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 0a37c8bd13..1078cfdaa4 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -803,12 +803,12 @@ static uint32_t stat_to_v9mode(const struct stat *stbuf)
return mode;
}
-static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name,
+static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *path,
+ const char *basename,
const struct stat *stbuf,
V9fsStat *v9stat)
{
int err;
- const char *str;
memset(v9stat, 0, sizeof(*v9stat));
@@ -829,7 +829,7 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name,
v9fs_string_free(&v9stat->extension);
if (v9stat->mode & P9_STAT_MODE_SYMLINK) {
- err = v9fs_co_readlink(pdu, name, &v9stat->extension);
+ err = v9fs_co_readlink(pdu, path, &v9stat->extension);
if (err < 0) {
return err;
}
@@ -842,14 +842,7 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name,
"HARDLINKCOUNT", (unsigned long)stbuf->st_nlink);
}
- str = strrchr(name->data, '/');
- if (str) {
- str += 1;
- } else {
- str = name->data;
- }
-
- v9fs_string_sprintf(&v9stat->name, "%s", str);
+ v9fs_string_sprintf(&v9stat->name, "%s", basename);
v9stat->size = 61 +
v9fs_string_size(&v9stat->name) +
@@ -1056,6 +1049,7 @@ static void coroutine_fn v9fs_stat(void *opaque)
struct stat stbuf;
V9fsFidState *fidp;
V9fsPDU *pdu = opaque;
+ char *basename;
err = pdu_unmarshal(pdu, offset, "d", &fid);
if (err < 0) {
@@ -1072,7 +1066,9 @@ static void coroutine_fn v9fs_stat(void *opaque)
if (err < 0) {
goto out;
}
- err = stat_to_v9stat(pdu, &fidp->path, &stbuf, &v9stat);
+ basename = g_path_get_basename(fidp->path.data);
+ err = stat_to_v9stat(pdu, &fidp->path, basename, &stbuf, &v9stat);
+ g_free(basename);
if (err < 0) {
goto out;
}
@@ -1748,7 +1744,7 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu,
if (err < 0) {
break;
}
- err = stat_to_v9stat(pdu, &path, &stbuf, &v9stat);
+ err = stat_to_v9stat(pdu, &path, dent->d_name, &stbuf, &v9stat);
if (err < 0) {
break;
}