fs/directory: move private directory information to filesystem

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong
2022-08-05 12:31:25 +08:00
committed by Xiang Xiao
parent 90db4daca9
commit fe17f747a7
34 changed files with 939 additions and 921 deletions
+38 -12
View File
@@ -39,7 +39,6 @@
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/fat.h>
#include <nuttx/fs/dirent.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/fs/hostfs.h>
@@ -51,6 +50,16 @@
#define HOSTFS_RETRY_DELAY_MS 10
/****************************************************************************
* Private Types
****************************************************************************/
struct hostfs_dir_s
{
struct fs_dirent_s base;
FAR void *dir;
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
@@ -79,7 +88,7 @@ static int hostfs_ftruncate(FAR struct file *filep,
static int hostfs_opendir(FAR struct inode *mountpt,
FAR const char *relpath,
FAR struct fs_dirent_s *dir);
FAR struct fs_dirent_s **dir);
static int hostfs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int hostfs_readdir(FAR struct inode *mountpt,
@@ -830,9 +839,10 @@ static int hostfs_ftruncate(FAR struct file *filep, off_t length)
****************************************************************************/
static int hostfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct fs_dirent_s *dir)
FAR struct fs_dirent_s **dir)
{
FAR struct hostfs_mountpt_s *fs;
FAR struct hostfs_dir_s *hdir;
char path[HOSTFS_MAX_PATH];
int ret;
@@ -843,13 +853,18 @@ static int hostfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
/* Recover our private data from the inode instance */
fs = mountpt->i_private;
hdir = kmm_zalloc(sizeof(struct hostfs_dir_s));
if (hdir == NULL)
{
return -ENOMEM;
}
/* Take the semaphore */
ret = hostfs_semtake(fs);
if (ret < 0)
{
return ret;
goto errout_with_hdir;
}
/* Append to the host's root directory */
@@ -858,18 +873,22 @@ static int hostfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
/* Call the host's opendir function */
dir->u.hostfs.fs_dir = host_opendir(path);
if (dir->u.hostfs.fs_dir == NULL)
hdir->dir = host_opendir(path);
if (hdir->dir == NULL)
{
ret = -ENOENT;
goto errout_with_semaphore;
}
ret = OK;
*dir = (FAR struct fs_dirent_s *)hdir;
hostfs_semgive(fs);
return OK;
errout_with_semaphore:
hostfs_semgive(fs);
errout_with_hdir:
kmm_free(hdir);
return ret;
}
@@ -883,7 +902,8 @@ errout_with_semaphore:
static int hostfs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir)
{
struct hostfs_mountpt_s *fs;
FAR struct hostfs_mountpt_s *fs;
FAR struct hostfs_dir_s *hdir;
int ret;
/* Sanity checks */
@@ -893,6 +913,7 @@ static int hostfs_closedir(FAR struct inode *mountpt,
/* Recover our private data from the inode instance */
fs = mountpt->i_private;
hdir = (FAR struct hostfs_dir_s *)dir;
/* Take the semaphore */
@@ -904,9 +925,10 @@ static int hostfs_closedir(FAR struct inode *mountpt,
/* Call the host's closedir function */
host_closedir(dir->u.hostfs.fs_dir);
host_closedir(hdir->dir);
hostfs_semgive(fs);
kmm_free(hdir);
return OK;
}
@@ -922,6 +944,7 @@ static int hostfs_readdir(FAR struct inode *mountpt,
FAR struct dirent *entry)
{
FAR struct hostfs_mountpt_s *fs;
FAR struct hostfs_dir_s *hdir;
int ret;
/* Sanity checks */
@@ -931,6 +954,7 @@ static int hostfs_readdir(FAR struct inode *mountpt,
/* Recover our private data from the inode instance */
fs = mountpt->i_private;
hdir = (FAR struct hostfs_dir_s *)dir;
/* Take the semaphore */
@@ -942,7 +966,7 @@ static int hostfs_readdir(FAR struct inode *mountpt,
/* Call the host OS's readdir function */
ret = host_readdir(dir->u.hostfs.fs_dir, entry);
ret = host_readdir(hdir->dir, entry);
hostfs_semgive(fs);
return ret;
@@ -959,6 +983,7 @@ static int hostfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir)
{
FAR struct hostfs_mountpt_s *fs;
FAR struct hostfs_dir_s *hdir;
int ret;
/* Sanity checks */
@@ -968,6 +993,7 @@ static int hostfs_rewinddir(FAR struct inode *mountpt,
/* Recover our private data from the inode instance */
fs = mountpt->i_private;
hdir = (FAR struct hostfs_dir_s *)dir;
/* Take the semaphore */
@@ -979,7 +1005,7 @@ static int hostfs_rewinddir(FAR struct inode *mountpt,
/* Call the host and let it do all the work */
host_rewinddir(dir->u.hostfs.fs_dir);
host_rewinddir(hdir->dir);
hostfs_semgive(fs);
return OK;