zvfs: 完成open/close/read/write/unlink的hook动态库代码编写、编译与简单功能测试。

This commit is contained in:
2026-02-23 16:01:55 +00:00
parent 31dc307d0b
commit 6f8f2148c3
7 changed files with 527 additions and 196 deletions

17
zvfs.h
View File

@@ -13,7 +13,7 @@
#define ZVFS_MAX_FD 64
#define BUFFER_SIZE (1024*8)
static const char *json_file = "/home/lian/share/10.1-spdk/zvfs/zvfs.json";
extern const char *json_file;
extern struct spdk_thread *global_thread;
static const int WAITER_MAX_TIME = 100000;
@@ -29,6 +29,7 @@ typedef struct {
/* 文件系统全局结构 */
typedef struct zvfs_s {
struct spdk_bs_dev *bs_dev;
struct spdk_blob_store *bs;
struct spdk_io_channel *channel;
struct spdk_blob *super_blob; // 承载目录日志的blob
@@ -39,7 +40,7 @@ typedef struct zvfs_s {
uint32_t dirent_count; // 当前有效项数
/* 伪FD表 */
struct zvfs_file *fd_table[ZVFS_MAX_FD]; // // e.g., #define ZVFS_MAX_FD 64
struct zvfs_file_s *fd_table[ZVFS_MAX_FD]; // // e.g., #define ZVFS_MAX_FD 64
int fd_base; // 伪FD起始值如1000
int openfd_count;
@@ -66,6 +67,9 @@ typedef struct zvfs_file_s {
void *dma_buf;
uint64_t dma_buf_size;
size_t actual_io_count;
const uint8_t *write_staging_buf;
size_t io_count;
bool finished;
} zvfs_file_t;
@@ -83,9 +87,10 @@ int zvfs_close(struct zvfs_file_s *file);
int zvfs_delete(struct zvfs_file_s *file);
/* POSIX hook APIzvfs_hook.c 实现) */
int zvfs_open_hook(const char *path, int flags, ...);
ssize_t zvfs_read_hook(int fd, void *buf, size_t count);
ssize_t zvfs_write_hook(int fd, const void *buf, size_t count);
int zvfs_close_hook(int fd);
int open(const char *path, int flags, ...);
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
int close(int fd);
int unlink(const char *name);
#endif