[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 11/19] hw/9pfs: Add a helper qemu_stat_blksize()
From: |
Bin Meng |
Subject: |
[PATCH v2 11/19] hw/9pfs: Add a helper qemu_stat_blksize() |
Date: |
Fri, 11 Nov 2022 12:22:17 +0800 |
As Windows host does not have stat->st_blksize field, we use the one
we calculated in init_win32_root_directory().
Add a helper qemu_stat_blksize() and use it to avoid direct access to
stat->st_blksize.
Co-developed-by: Guohuai Shi <guohuai.shi@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
Changes in v2:
- new patch: "hw/9pfs: Add a helper qemu_stat_blksize()"
hw/9pfs/9p-util.h | 12 ++++++++++++
hw/9pfs/9p-util-win32.c | 7 +++++++
hw/9pfs/9p.c | 7 ++++++-
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index c424cb00ca..df84374b78 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -133,6 +133,7 @@ QemuFd_t openat_file(QemuFd_t dirfd, const char *name, int
flags,
mode_t mode);
off_t qemu_dirent_off_win32(void *s, void *fs);
uint64_t qemu_stat_rdev_win32(void *fs_ctx);
+uint64_t qemu_stat_blksize_win32(void *fs_ctx);
#endif
static inline void close_preserve_errno(QemuFd_t fd)
@@ -265,6 +266,17 @@ static inline uint64_t qemu_stat_rdev(const struct stat
*stbuf, void *fs_ctx)
#endif
}
+static inline uint64_t qemu_stat_blksize(const struct stat *stbuf, void
*fs_ctx)
+{
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
+ return stbuf->st_blksize;
+#elif defined(CONFIG_WIN32)
+ return qemu_stat_blksize_win32(fs_ctx);
+#else
+#error Missing qemu_stat_blksize() implementation for this host system
+#endif
+}
+
/*
* As long as mknodat is not available on macOS, this workaround
* using pthread_fchdir_np is needed. qemu_mknodat is defined in
diff --git a/hw/9pfs/9p-util-win32.c b/hw/9pfs/9p-util-win32.c
index 44c10370ae..064f878e5e 100644
--- a/hw/9pfs/9p-util-win32.c
+++ b/hw/9pfs/9p-util-win32.c
@@ -954,3 +954,10 @@ uint64_t qemu_stat_rdev_win32(void *fs_ctx)
memcpy(&rdev, data->root_path, 3);
return rdev;
}
+
+uint64_t qemu_stat_blksize_win32(void *fs_ctx)
+{
+ LocalData *data = ((FsContext *)fs_ctx)->private;
+
+ return (uint64_t)data->block_size;
+}
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 7080503b97..169578cc1d 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1335,7 +1335,7 @@ static int32_t blksize_to_iounit(const V9fsPDU *pdu,
int32_t blksize)
static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf)
{
- return blksize_to_iounit(pdu, stbuf->st_blksize);
+ return blksize_to_iounit(pdu, qemu_stat_blksize(stbuf, &pdu->s->ctx));
}
static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,
@@ -1352,7 +1352,12 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const
struct stat *stbuf,
v9lstat->st_rdev = host_dev_to_dotl_dev(rdev);
v9lstat->st_size = stbuf->st_size;
v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
v9lstat->st_blocks = stbuf->st_blocks;
+#elif defined(CONFIG_WIN32)
+ v9lstat->st_blocks = ROUND_UP(v9lstat->st_size / v9lstat->st_blksize,
+ v9lstat->st_blksize);
+#endif
v9lstat->st_atime_sec = stbuf->st_atime;
v9lstat->st_mtime_sec = stbuf->st_mtime;
v9lstat->st_ctime_sec = stbuf->st_ctime;
--
2.25.1
- Re: [PATCH v2 05/19] hw/9pfs: Update 9pfs to use the new QemuFd_t type, (continued)
[PATCH v2 08/19] hw/9pfs: Update the local fs driver to support Windows, Bin Meng, 2022/11/10
[PATCH v2 07/19] hw/9pfs: Implement Windows specific utilities functions for 9pfs, Bin Meng, 2022/11/10
[PATCH v2 01/19] qemu/xattr.h: Exclude <sys/xattr.h> for Windows, Bin Meng, 2022/11/10
[PATCH v2 10/19] hw/9pfs: Add a helper qemu_stat_rdev(), Bin Meng, 2022/11/10
[PATCH v2 09/19] hw/9pfs: Support getting current directory offset for Windows, Bin Meng, 2022/11/10
[PATCH v2 11/19] hw/9pfs: Add a helper qemu_stat_blksize(),
Bin Meng <=
[PATCH v2 13/19] hw/9pfs: Update v9fs_set_fd_limit() for Windows, Bin Meng, 2022/11/10
[PATCH v2 12/19] hw/9pfs: Disable unsupported flags and features for Windows, Bin Meng, 2022/11/10
[PATCH v2 18/19] tests/qtest: virtio-9p-test: Adapt the case for win32, Bin Meng, 2022/11/10
[PATCH v2 14/19] hw/9pfs: Add Linux error number definition, Bin Meng, 2022/11/10
[PATCH v2 15/19] hw/9pfs: Translate Windows errno to Linux value, Bin Meng, 2022/11/10
[PATCH v2 17/19] hw/9pfs: Update synth fs driver for Windows, Bin Meng, 2022/11/10
[PATCH v2 16/19] fsdev: Disable proxy fs driver on Windows, Bin Meng, 2022/11/10
[PATCH v2 19/19] meson.build: Turn on virtfs for Windows, Bin Meng, 2022/11/10