[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 07/16] hw/9pfs: Update helper qemu_stat_rdev()
From: |
Bin Meng |
Subject: |
[PATCH v4 07/16] hw/9pfs: Update helper qemu_stat_rdev() |
Date: |
Mon, 30 Jan 2023 17:51:53 +0800 |
As Windows host does not have stat->st_rdev field, we use the first
3 characters of the root path to build a device id.
Co-developed-by: Guohuai Shi <guohuai.shi@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
hw/9pfs/9p-util.h | 22 +++++++++++++++++++---
hw/9pfs/9p-util-win32.c | 18 ++++++++++++++++++
hw/9pfs/9p.c | 5 +++--
3 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 91f70a4c38..1fb54d0b97 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -22,8 +22,9 @@
/* forward declaration */
union V9fsFidOpenState;
struct V9fsState;
+struct FsContext;
-#if !defined(CONFIG_LINUX)
+#ifdef CONFIG_DARWIN
/*
* Generates a Linux device number (a.k.a. dev_t) for given device major
@@ -55,10 +56,12 @@ static inline uint64_t makedev_dotl(uint32_t dev_major,
uint32_t dev_minor)
*/
static inline uint64_t host_dev_to_dotl_dev(dev_t dev)
{
-#ifdef CONFIG_LINUX
+#if defined(CONFIG_LINUX) || defined(CONFIG_WIN32)
return dev;
-#else
+#elif defined(CONFIG_DARWIN)
return makedev_dotl(major(dev), minor(dev));
+#else
+#error Missing host_dev_to_dotl_dev() implementation for this host system
#endif
}
@@ -152,6 +155,7 @@ void rewinddir_win32(DIR *pDir);
void seekdir_win32(DIR *pDir, long pos);
long telldir_win32(DIR *pDir);
off_t qemu_dirent_off_win32(struct V9fsState *s, union V9fsFidOpenState *fs);
+uint64_t qemu_stat_rdev_win32(struct FsContext *fs_ctx);
#endif
static inline void close_preserve_errno(int fd)
@@ -269,6 +273,18 @@ static inline struct dirent *qemu_dirent_dup(struct dirent
*dent)
return g_memdup(dent, sz);
}
+static inline uint64_t qemu_stat_rdev(const struct stat *stbuf,
+ struct FsContext *fs_ctx)
+{
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
+ return stbuf->st_rdev;
+#elif defined(CONFIG_WIN32)
+ return qemu_stat_rdev_win32(fs_ctx);
+#else
+#error Missing qemu_stat_rdev() 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 050c177d0c..5f6d43b62c 100644
--- a/hw/9pfs/9p-util-win32.c
+++ b/hw/9pfs/9p-util-win32.c
@@ -1278,3 +1278,21 @@ off_t qemu_dirent_off_win32(struct V9fsState *s, union
V9fsFidOpenState *fs)
{
return s->ops->telldir(&s->ctx, fs);
}
+
+uint64_t qemu_stat_rdev_win32(struct FsContext *fs_ctx)
+{
+ uint64_t rdev = 0;
+ LocalData *data = fs_ctx->private;
+
+ /*
+ * As Windows host does not have stat->st_rdev field, we use the first
+ * 3 characters of the root path to build a device id.
+ *
+ * (Windows root path always starts from a driver letter like "C:\")
+ */
+ if (data) {
+ memcpy(&rdev, data->root_path, 3);
+ }
+
+ return rdev;
+}
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index be247eeb30..36916fe581 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1266,7 +1266,8 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu,
V9fsPath *path,
} else if (v9stat->mode & P9_STAT_MODE_DEVICE) {
v9fs_string_sprintf(&v9stat->extension, "%c %u %u",
S_ISCHR(stbuf->st_mode) ? 'c' : 'b',
- major(stbuf->st_rdev), minor(stbuf->st_rdev));
+ major(qemu_stat_rdev(stbuf, &pdu->s->ctx)),
+ minor(qemu_stat_rdev(stbuf, &pdu->s->ctx)));
} else if (S_ISDIR(stbuf->st_mode) || S_ISREG(stbuf->st_mode)) {
v9fs_string_sprintf(&v9stat->extension, "%s %lu",
"HARDLINKCOUNT", (unsigned long)stbuf->st_nlink);
@@ -1346,7 +1347,7 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct
stat *stbuf,
v9lstat->st_nlink = stbuf->st_nlink;
v9lstat->st_uid = stbuf->st_uid;
v9lstat->st_gid = stbuf->st_gid;
- v9lstat->st_rdev = host_dev_to_dotl_dev(stbuf->st_rdev);
+ v9lstat->st_rdev = host_dev_to_dotl_dev(rdev);
v9lstat->st_size = stbuf->st_size;
v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
v9lstat->st_blocks = stbuf->st_blocks;
--
2.25.1
- [PATCH v4 00/16] hw/9pfs: Add 9pfs support for Windows, Bin Meng, 2023/01/30
- [PATCH v4 01/16] hw/9pfs: Add missing definitions for Windows, Bin Meng, 2023/01/30
- [PATCH v4 03/16] hw/9pfs: Replace the direct call to xxxdir() APIs with a wrapper, Bin Meng, 2023/01/30
- [PATCH v4 04/16] hw/9pfs: Implement Windows specific xxxdir() APIs, Bin Meng, 2023/01/30
- [PATCH v4 05/16] hw/9pfs: Update the local fs driver to support Windows, Bin Meng, 2023/01/30
- [PATCH v4 08/16] hw/9pfs: Add a helper qemu_stat_blksize(), Bin Meng, 2023/01/30
- [PATCH v4 02/16] hw/9pfs: Implement Windows specific utilities functions for 9pfs, Bin Meng, 2023/01/30
- [PATCH v4 07/16] hw/9pfs: Update helper qemu_stat_rdev(),
Bin Meng <=
- [PATCH v4 10/16] hw/9pfs: Update v9fs_set_fd_limit() for Windows, Bin Meng, 2023/01/30
- [PATCH v4 06/16] hw/9pfs: Support getting current directory offset for Windows, Bin Meng, 2023/01/30
- [PATCH v4 09/16] hw/9pfs: Disable unsupported flags and features for Windows, Bin Meng, 2023/01/30
- [PATCH v4 13/16] fsdev: Disable proxy fs driver on Windows, Bin Meng, 2023/01/30
- [PATCH v4 11/16] hw/9pfs: Add Linux error number definition, Bin Meng, 2023/01/30
- [PATCH v4 12/16] hw/9pfs: Translate Windows errno to Linux value, Bin Meng, 2023/01/30
- [PATCH v4 16/16] meson.build: Turn on virtfs for Windows, Bin Meng, 2023/01/30
- [PATCH v4 14/16] hw/9pfs: Update synth fs driver for Windows, Bin Meng, 2023/01/30
- [PATCH v4 15/16] tests/qtest: virtio-9p-test: Adapt the case for win32, Bin Meng, 2023/01/30
- Re: [PATCH v4 00/16] hw/9pfs: Add 9pfs support for Windows, Marc-André Lureau, 2023/01/31