hostfs:add get_path

To perform kvdb related type testing in the simulator, ioctl support is required to obtain relpath

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
chenrun1
2024-08-18 10:17:48 +08:00
committed by Xiang Xiao
parent e9ac1a2317
commit 6e9a43c504
2 changed files with 17 additions and 4 deletions
+13 -1
View File
@@ -43,6 +43,7 @@
#include <nuttx/fs/ioctl.h> #include <nuttx/fs/ioctl.h>
#include <nuttx/fs/hostfs.h> #include <nuttx/fs/hostfs.h>
#include "inode/inode.h"
#include "hostfs.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 */ /* Allocate memory for the open file */
hf = kmm_malloc(sizeof *hf); hf = kmm_malloc(sizeof(*hf) + strlen(relpath));
if (hf == NULL) if (hf == NULL)
{ {
ret = -ENOMEM; ret = -ENOMEM;
@@ -321,6 +322,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath,
hf->fnext = fs->fs_head; hf->fnext = fs->fs_head;
hf->crefs = 1; hf->crefs = 1;
hf->oflags = oflags; hf->oflags = oflags;
strcpy(hf->relpath, relpath);
fs->fs_head = hf; fs->fs_head = hf;
ret = OK; 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); 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); nxmutex_unlock(&g_lock);
return ret; return ret;
} }
+4 -3
View File
@@ -47,10 +47,11 @@
struct hostfs_ofile_s struct hostfs_ofile_s
{ {
struct hostfs_ofile_s *fnext; /* Supports a singly linked list */ struct hostfs_ofile_s *fnext; /* Supports a singly linked list */
int16_t crefs; /* Reference count */ int16_t crefs; /* Reference count */
mode_t oflags; /* Open mode */ mode_t oflags; /* Open mode */
int fd; int fd;
char relpath[1];
}; };
/* This structure represents the overall mountpoint state. An instance of /* This structure represents the overall mountpoint state. An instance of