[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 03/16] hw/9pfs: Replace the direct call to xxxdir() APIs with
From: |
Bin Meng |
Subject: |
[PATCH v4 03/16] hw/9pfs: Replace the direct call to xxxdir() APIs with a wrapper |
Date: |
Mon, 30 Jan 2023 17:51:49 +0800 |
From: Guohuai Shi <guohuai.shi@windriver.com>
xxxdir() APIs are not safe on Windows host. For future extension to
Windows, let's replace the direct call to xxxdir() APIs with a wrapper.
Signed-off-by: Guohuai Shi <guohuai.shi@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
hw/9pfs/9p-util.h | 14 ++++++++++++++
hw/9pfs/9p-local.c | 12 ++++++------
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 90420a7578..0f159fb4ce 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -103,6 +103,13 @@ static inline int errno_to_dotl(int err) {
#define qemu_renameat renameat_win32
#define qemu_utimensat utimensat_win32
#define qemu_unlinkat unlinkat_win32
+
+#define qemu_opendir opendir_win32
+#define qemu_closedir closedir_win32
+#define qemu_readdir readdir_win32
+#define qeme_rewinddir rewinddir_win32
+#define qemu_seekdir seekdir_win32
+#define qemu_telldir telldir_win32
#else
#define qemu_openat openat
#define qemu_fstatat fstatat
@@ -110,6 +117,13 @@ static inline int errno_to_dotl(int err) {
#define qemu_renameat renameat
#define qemu_utimensat utimensat
#define qemu_unlinkat unlinkat
+
+#define qemu_opendir opendir
+#define qemu_closedir closedir
+#define qemu_readdir readdir
+#define qeme_rewinddir rewinddir
+#define qemu_seekdir seekdir
+#define qemu_telldir telldir
#endif
#ifdef CONFIG_WIN32
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index b6102c9e5a..4385f18da2 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -495,7 +495,7 @@ static int local_close(FsContext *ctx, V9fsFidOpenState *fs)
static int local_closedir(FsContext *ctx, V9fsFidOpenState *fs)
{
- return closedir(fs->dir.stream);
+ return qemu_closedir(fs->dir.stream);
}
static int local_open(FsContext *ctx, V9fsPath *fs_path,
@@ -533,12 +533,12 @@ static int local_opendir(FsContext *ctx,
static void local_rewinddir(FsContext *ctx, V9fsFidOpenState *fs)
{
- rewinddir(fs->dir.stream);
+ qeme_rewinddir(fs->dir.stream);
}
static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs)
{
- return telldir(fs->dir.stream);
+ return qemu_telldir(fs->dir.stream);
}
static bool local_is_mapped_file_metadata(FsContext *fs_ctx, const char *name)
@@ -552,13 +552,13 @@ static struct dirent *local_readdir(FsContext *ctx,
V9fsFidOpenState *fs)
struct dirent *entry;
again:
- entry = readdir(fs->dir.stream);
+ entry = qemu_readdir(fs->dir.stream);
if (!entry) {
return NULL;
}
#ifdef CONFIG_DARWIN
int off;
- off = telldir(fs->dir.stream);
+ off = qemu_telldir(fs->dir.stream);
/* If telldir fails, fail the entire readdir call */
if (off < 0) {
return NULL;
@@ -581,7 +581,7 @@ again:
static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)
{
- seekdir(fs->dir.stream, off);
+ qemu_seekdir(fs->dir.stream, off);
}
static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs,
--
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 <=
- [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, 2023/01/30
- [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