zvfs: 重构核心读写逻辑并新增 POSIX hook;引入目录元数据与伪 fd;分离创建、打开、关闭、删除的逻辑;
This commit is contained in:
40
func_test.c
Normal file
40
func_test.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *path = "/zvfs/func_test.dat";
|
||||
if (argc > 2 && strcmp(argv[1], "-f") == 0) path = argv[2];
|
||||
setenv("ZVFS_ROOT", "/zvfs", 0);
|
||||
|
||||
printf("open: %s\n", path);
|
||||
int fd = open(path, O_CREAT|O_RDWR, 0644);
|
||||
if (fd < 0) { perror("open"); return 1; }
|
||||
|
||||
const char *msg = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
ssize_t w = write(fd, msg, strlen(msg));
|
||||
if (w < 0) { perror("write"); return 2; }
|
||||
printf("write: %zd\n", w);
|
||||
|
||||
/* Rewind by closing and reopening for read */
|
||||
close(fd);
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd < 0) { perror("open R"); return 3; }
|
||||
|
||||
char buf[256]; memset(buf, 0, sizeof(buf));
|
||||
ssize_t r = read(fd, buf, sizeof(buf));
|
||||
if (r < 0) { perror("read"); return 4; }
|
||||
printf("read: %zd bytes: %.*s\n", r, (int)r, buf);
|
||||
close(fd);
|
||||
|
||||
if (unlink(path) != 0) { perror("unlink"); return 5; }
|
||||
printf("unlink: ok\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user