All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bin.meng@windriver.com>
To: Greg Kurz <groug@kaod.org>,
	Christian Schoenebeck <qemu_oss@crudebyte.com>,
	qemu-devel@nongnu.org
Cc: Guohuai Shi <guohuai.shi@windriver.com>
Subject: [PATCH v3 08/17] hw/9pfs: update helper qemu_stat_rdev()
Date: Mon, 19 Dec 2022 18:20:12 +0800	[thread overview]
Message-ID: <20221219102022.2167736-9-bin.meng@windriver.com> (raw)
In-Reply-To: <20221219102022.2167736-1-bin.meng@windriver.com>

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>
---

(no changes since v1)

 hw/9pfs/9p-util.h       | 20 +++++++++++++++++---
 hw/9pfs/9p-util-win32.c | 18 ++++++++++++++++++
 hw/9pfs/9p.c            |  5 +++--
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index e395936b30..b8e5c037a2 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -19,7 +19,7 @@
 #define O_PATH_9P_UTIL 0
 #endif
 
-#if !defined(CONFIG_LINUX)
+#ifdef CONFIG_DARWIN
 
 /*
  * Generates a Linux device number (a.k.a. dev_t) for given device major
@@ -51,10 +51,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
 }
 
@@ -128,6 +130,7 @@ int statfs_win32(const char *root_path, struct statfs *stbuf);
 int openat_dir(int dirfd, const char *name);
 int openat_file(int 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);
 #endif
 
 static inline void close_preserve_errno(int fd)
@@ -244,6 +247,17 @@ 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, void *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 3592e057ce..54c10069b9 100644
--- a/hw/9pfs/9p-util-win32.c
+++ b/hw/9pfs/9p-util-win32.c
@@ -936,3 +936,21 @@ off_t qemu_dirent_off_win32(void *s, void *fs)
 
     return v9fs->ops->telldir(&v9fs->ctx, (V9fsFidOpenState *)fs);
 }
+
+uint64_t qemu_stat_rdev_win32(void *fs_ctx)
+{
+    uint64_t rdev = 0;
+    LocalData *data = ((FsContext *)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



  parent reply	other threads:[~2022-12-19 10:30 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 10:20 [PATCH v3 00/17] hw/9pfs: Add 9pfs support for Windows Bin Meng
2022-12-19 10:20 ` [PATCH v3 01/17] qemu/xattr.h: Exclude <sys/xattr.h> " Bin Meng
2022-12-19 10:20 ` [PATCH v3 02/17] hw/9pfs: Drop unnecessary *xattr wrapper API declarations Bin Meng
2022-12-19 10:20 ` [PATCH v3 03/17] hw/9pfs: Replace the direct call to xxxat() APIs with a wrapper Bin Meng
2022-12-19 10:20 ` [PATCH v3 04/17] hw/9pfs: Add missing definitions for Windows Bin Meng
2022-12-19 10:20 ` [PATCH v3 05/17] hw/9pfs: Implement Windows specific utilities functions for 9pfs Bin Meng
2022-12-19 10:20 ` [PATCH v3 06/17] hw/9pfs: Update the local fs driver to support Windows Bin Meng
2022-12-19 10:20 ` [PATCH v3 07/17] hw/9pfs: Support getting current directory offset for Windows Bin Meng
2022-12-21 14:48   ` Christian Schoenebeck
2022-12-21 18:02     ` Shi, Guohuai
2022-12-28 11:51       ` Christian Schoenebeck
2022-12-29  6:03         ` Shi, Guohuai
2022-12-30 13:36           ` Christian Schoenebeck
2022-12-19 10:20 ` Bin Meng [this message]
2022-12-19 10:20 ` [PATCH v3 09/17] hw/9pfs: Add a helper qemu_stat_blksize() Bin Meng
2022-12-19 10:20 ` [PATCH v3 10/17] hw/9pfs: Disable unsupported flags and features for Windows Bin Meng
2022-12-19 10:20 ` [PATCH v3 11/17] hw/9pfs: Update v9fs_set_fd_limit() " Bin Meng
2022-12-19 10:20 ` [PATCH v3 12/17] hw/9pfs: Add Linux error number definition Bin Meng
2022-12-19 10:20 ` [PATCH v3 13/17] hw/9pfs: Translate Windows errno to Linux value Bin Meng
2022-12-19 10:20 ` [PATCH v3 14/17] fsdev: Disable proxy fs driver on Windows Bin Meng
2022-12-19 10:20 ` [PATCH v3 15/17] hw/9pfs: Update synth fs driver for Windows Bin Meng
2022-12-19 10:20 ` [PATCH v3 16/17] tests/qtest: virtio-9p-test: Adapt the case for win32 Bin Meng
2022-12-19 10:20 ` [PATCH v3 17/17] meson.build: Turn on virtfs for Windows Bin Meng
2022-12-21 14:14 ` [PATCH v3 00/17] hw/9pfs: Add 9pfs support " Christian Schoenebeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221219102022.2167736-9-bin.meng@windriver.com \
    --to=bin.meng@windriver.com \
    --cc=groug@kaod.org \
    --cc=guohuai.shi@windriver.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.