From 6e9a43c504cb2f6d045226251aae181f220dca5a Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Tue, 2 Jan 2024 11:51:15 +0800 Subject: [PATCH] hostfs:add get_path To perform kvdb related type testing in the simulator, ioctl support is required to obtain relpath Signed-off-by: chenrun1 --- fs/hostfs/hostfs.c | 14 +++++++++++++- fs/hostfs/hostfs.h | 7 ++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c index d6bbd12b90..c5efb5ae06 100644 --- a/fs/hostfs/hostfs.c +++ b/fs/hostfs/hostfs.c @@ -43,6 +43,7 @@ #include #include +#include "inode/inode.h" #include "hostfs.h" /**************************************************************************** @@ -269,7 +270,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath, /* Allocate memory for the open file */ - hf = kmm_malloc(sizeof *hf); + hf = kmm_malloc(sizeof(*hf) + strlen(relpath)); if (hf == NULL) { ret = -ENOMEM; @@ -321,6 +322,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath, hf->fnext = fs->fs_head; hf->crefs = 1; hf->oflags = oflags; + strcpy(hf->relpath, relpath); fs->fs_head = hf; ret = OK; @@ -603,6 +605,16 @@ static int hostfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) ret = host_ioctl(hf->fd, cmd, arg); + if (ret < 0 && cmd == FIOC_FILEPATH) + { + FAR char *path = (FAR char *)(uintptr_t)arg; + ret = inode_getpath(filep->f_inode, path, PATH_MAX); + if (ret >= 0) + { + strlcat(path, hf->relpath, PATH_MAX); + } + } + nxmutex_unlock(&g_lock); return ret; } diff --git a/fs/hostfs/hostfs.h b/fs/hostfs/hostfs.h index 5c9ff3c191..015370fea7 100644 --- a/fs/hostfs/hostfs.h +++ b/fs/hostfs/hostfs.h @@ -47,10 +47,11 @@ struct hostfs_ofile_s { - struct hostfs_ofile_s *fnext; /* Supports a singly linked list */ - int16_t crefs; /* Reference count */ - mode_t oflags; /* Open mode */ + struct hostfs_ofile_s *fnext; /* Supports a singly linked list */ + int16_t crefs; /* Reference count */ + mode_t oflags; /* Open mode */ int fd; + char relpath[1]; }; /* This structure represents the overall mountpoint state. An instance of