mirror of
https://github.com/apache/nuttx.git
synced 2026-09-28 03:09:13 +08:00
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:
+13
-1
@@ -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
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user