You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/08/09 15:30:09 UTC
[incubator-nuttx] 03/05: fs/directory: update readdir interface for all filesystem
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 90db4daca9b738735585201225cabb5248399abc
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Tue Jul 26 06:56:41 2022 +0000
fs/directory: update readdir interface for all filesystem
Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c | 12 +++++----
drivers/mtd/mtd_partition.c | 3 ++-
drivers/power/pm/pm_procfs.c | 10 +++++---
fs/binfs/fs_binfs.c | 11 +++++---
fs/cromfs/fs_cromfs.c | 31 +++++++++++++----------
fs/fat/fs_fat32.c | 14 +++++-----
fs/fat/fs_fat32.h | 5 ++--
fs/fat/fs_fat32dirent.c | 23 +++++++++--------
fs/hostfs/hostfs.c | 8 +++---
fs/littlefs/lfs_vfs.c | 12 +++++----
fs/nfs/nfs_vfsops.c | 34 +++++++++++++------------
fs/nxffs/nxffs.h | 4 ++-
fs/nxffs/nxffs_dirent.c | 11 ++++----
fs/procfs/fs_procfs.c | 36 +++++++++++++-------------
fs/procfs/fs_procfsproc.c | 10 +++++---
fs/procfs/fs_skeleton.c | 10 +++++---
fs/romfs/fs_romfs.c | 18 +++++++------
fs/rpmsgfs/rpmsgfs.c | 8 +++---
fs/smartfs/smartfs_procfs.c | 24 ++++++++++--------
fs/smartfs/smartfs_smart.c | 14 +++++-----
fs/spiffs/src/spiffs_vfs.c | 17 ++++++-------
fs/tmpfs/fs_tmpfs.c | 12 +++++----
fs/unionfs/fs_unionfs.c | 31 ++++++++++-------------
fs/userfs/fs_userfs.c | 8 +++---
fs/vfs/fs_dir.c | 38 +++++++++++++++-------------
include/nuttx/fs/dirent.h | 6 -----
include/nuttx/fs/fs.h | 3 ++-
include/nuttx/fs/procfs.h | 2 +-
net/procfs/net_procfs.c | 24 ++++++++++--------
net/procfs/net_procfs_route.c | 10 +++++---
30 files changed, 244 insertions(+), 205 deletions(-)
diff --git a/arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c b/arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c
index 9168a2633b..f56774901e 100644
--- a/arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c
+++ b/arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c
@@ -99,7 +99,8 @@ static int cxd56_powermgr_procfs_dup(const struct file *oldp,
static int cxd56_powermgr_procfs_opendir(const char *relpath,
struct fs_dirent_s *dir);
static int cxd56_powermgr_procfs_closedir(struct fs_dirent_s *dir);
-static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir);
+static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir,
+ struct dirent *entry);
static int cxd56_powermgr_procfs_rewinddir(struct fs_dirent_s *dir);
static int cxd56_powermgr_procfs_stat(const char *relpath,
struct stat *buf);
@@ -749,7 +750,8 @@ static int cxd56_powermgr_procfs_closedir(struct fs_dirent_s *dir)
*
****************************************************************************/
-static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir)
+static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir,
+ struct dirent *entry)
{
struct cxd56_powermgr_procfs_dir_s *procfs;
@@ -765,9 +767,9 @@ static int cxd56_powermgr_procfs_readdir(struct fs_dirent_s *dir)
return -ENOENT;
}
- dir->fd_dir.d_type = DTYPE_FILE;
- strncpy(dir->fd_dir.d_name, g_powermg_procfs_dir[procfs->index],
- strlen(g_powermg_procfs_dir[procfs->index])+1);
+ entry->d_type = DTYPE_FILE;
+ strncpy(entry->d_name, g_powermg_procfs_dir[procfs->index],
+ strlen(g_powermg_procfs_dir[procfs->index])+1);
procfs->index++;
return OK;
diff --git a/drivers/mtd/mtd_partition.c b/drivers/mtd/mtd_partition.c
index b7dd47c86f..243c613f14 100644
--- a/drivers/mtd/mtd_partition.c
+++ b/drivers/mtd/mtd_partition.c
@@ -133,7 +133,8 @@ static int part_procfs_dup(FAR const struct file *oldp,
static int part_procfs_opendir(const char *relpath,
FAR struct fs_dirent_s *dir);
static int part_procfs_closedir(FAR struct fs_dirent_s *dir);
-static int part_procfs_readdir(FAR struct fs_dirent_s *dir);
+static int part_procfs_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int part_procfs_rewinddir(FAR struct fs_dirent_s *dir);
#endif
diff --git a/drivers/power/pm/pm_procfs.c b/drivers/power/pm/pm_procfs.c
index ea41b68665..9b46629d99 100644
--- a/drivers/power/pm/pm_procfs.c
+++ b/drivers/power/pm/pm_procfs.c
@@ -106,7 +106,8 @@ static int pm_dup(FAR const struct file *oldp,
static int pm_opendir(FAR const char *relpath,
FAR struct fs_dirent_s *dir);
static int pm_closedir(FAR struct fs_dirent_s *dir);
-static int pm_readdir(FAR struct fs_dirent_s *dir);
+static int pm_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int pm_rewinddir(FAR struct fs_dirent_s *dir);
static int pm_stat(FAR const char *relpath, FAR struct stat *buf);
@@ -490,7 +491,8 @@ static int pm_closedir(FAR struct fs_dirent_s *dir)
*
****************************************************************************/
-static int pm_readdir(FAR struct fs_dirent_s *dir)
+static int pm_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct procfs_dir_priv_s *level1;
int index;
@@ -514,8 +516,8 @@ static int pm_readdir(FAR struct fs_dirent_s *dir)
domain = index / ARRAY_SIZE(g_pm_files);
fpos = index % ARRAY_SIZE(g_pm_files);
- dir->fd_dir.d_type = DTYPE_FILE;
- snprintf(dir->fd_dir.d_name, NAME_MAX + 1, "%s%d",
+ entry->d_type = DTYPE_FILE;
+ snprintf(entry->d_name, NAME_MAX + 1, "%s%d",
g_pm_files[fpos].name, domain);
level1->index++;
diff --git a/fs/binfs/fs_binfs.c b/fs/binfs/fs_binfs.c
index c2ff84bd45..8c058aa8a5 100644
--- a/fs/binfs/fs_binfs.c
+++ b/fs/binfs/fs_binfs.c
@@ -65,7 +65,8 @@ static int binfs_fstat(FAR const struct file *filep,
static int binfs_opendir(struct inode *mountpt, const char *relpath,
struct fs_dirent_s *dir);
static int binfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int binfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -301,7 +302,9 @@ static int binfs_opendir(struct inode *mountpt, const char *relpath,
*
****************************************************************************/
-static int binfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int binfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR const char *name;
unsigned int index;
@@ -325,8 +328,8 @@ static int binfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
/* Save the filename and file type */
finfo("Entry %d: \"%s\"\n", index, name);
- dir->fd_dir.d_type = DTYPE_FILE;
- strlcpy(dir->fd_dir.d_name, name, sizeof(dir->fd_dir.d_name));
+ entry->d_type = DTYPE_FILE;
+ strlcpy(entry->d_name, name, sizeof(entry->d_name));
/* The application list is terminated by an entry with a NULL name.
* Therefore, there is at least one more entry in the list.
diff --git a/fs/cromfs/fs_cromfs.c b/fs/cromfs/fs_cromfs.c
index 68b76bf8e1..cede01c30f 100644
--- a/fs/cromfs/fs_cromfs.c
+++ b/fs/cromfs/fs_cromfs.c
@@ -144,7 +144,8 @@ static int cromfs_fstat(FAR const struct file *filep,
static int cromfs_opendir(FAR struct inode *mountpt,
FAR const char *relpath, FAR struct fs_dirent_s *dir);
static int cromfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int cromfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -1230,7 +1231,9 @@ static int cromfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
*
****************************************************************************/
-static int cromfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int cromfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR const struct cromfs_volume_s *fs;
FAR const struct cromfs_node_s *node;
@@ -1289,53 +1292,53 @@ static int cromfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
name = (FAR char *)cromfs_offset2addr(fs, node->cn_name);
finfo("Entry %" PRIu32 ": %s\n", offset, name);
- strlcpy(dir->fd_dir.d_name, name, sizeof(dir->fd_dir.d_name));
+ strlcpy(entry->d_name, name, sizeof(entry->d_name));
switch (node->cn_mode & S_IFMT)
{
case S_IFDIR: /* Directory */
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
break;
case S_IFREG: /* Regular file */
- dir->fd_dir.d_type = DTYPE_FILE;
+ entry->d_type = DTYPE_FILE;
break;
case S_IFIFO: /* FIFO */
- dir->fd_dir.d_type = DTYPE_FIFO;
+ entry->d_type = DTYPE_FIFO;
break;
case S_IFCHR: /* Character driver */
- dir->fd_dir.d_type = DTYPE_CHR;
+ entry->d_type = DTYPE_CHR;
break;
case S_IFBLK: /* Block driver */
- dir->fd_dir.d_type = DTYPE_BLK;
+ entry->d_type = DTYPE_BLK;
break;
case S_IFMQ: /* Message queue */
- dir->fd_dir.d_type = DTYPE_MQ;
+ entry->d_type = DTYPE_MQ;
break;
case S_IFSEM: /* Semaphore */
- dir->fd_dir.d_type = DTYPE_SEM;
+ entry->d_type = DTYPE_SEM;
break;
case S_IFSHM: /* Shared memory */
- dir->fd_dir.d_type = DTYPE_SHM;
+ entry->d_type = DTYPE_SHM;
break;
case S_IFMTD: /* MTD driver */
- dir->fd_dir.d_type = DTYPE_MTD;
+ entry->d_type = DTYPE_MTD;
break;
case S_IFSOCK: /* Socket */
- dir->fd_dir.d_type = DTYPE_SOCK;
+ entry->d_type = DTYPE_SOCK;
break;
default:
DEBUGPANIC();
- dir->fd_dir.d_type = DTYPE_UNKNOWN;
+ entry->d_type = DTYPE_UNKNOWN;
break;
}
diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c
index 5c47340a94..d7b359a67d 100644
--- a/fs/fat/fs_fat32.c
+++ b/fs/fat/fs_fat32.c
@@ -69,7 +69,8 @@ static int fat_truncate(FAR struct file *filep, off_t length);
static int fat_opendir(FAR struct inode *mountpt,
FAR const char *relpath, FAR struct fs_dirent_s *dir);
static int fat_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int fat_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -1878,7 +1879,8 @@ errout_with_semaphore:
****************************************************************************/
static int fat_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct fat_mountpt_s *fs;
unsigned int dirindex;
@@ -1914,7 +1916,7 @@ static int fat_readdir(FAR struct inode *mountpt,
/* Read the next directory entry */
- dir->fd_dir.d_name[0] = '\0';
+ entry->d_name[0] = '\0';
found = false;
while (dir->u.fat.fd_currsector && !found)
@@ -1960,7 +1962,7 @@ static int fat_readdir(FAR struct inode *mountpt,
* several directory entries.
*/
- ret = fat_dirname2path(fs, dir);
+ ret = fat_dirname2path(fs, dir, entry);
if (ret == OK)
{
/* The name was successfully extracted. Re-read the
@@ -1991,11 +1993,11 @@ static int fat_readdir(FAR struct inode *mountpt,
if ((attribute & FATATTR_DIRECTORY) == 0)
{
- dir->fd_dir.d_type = DTYPE_FILE;
+ entry->d_type = DTYPE_FILE;
}
else
{
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
}
/* Mark the entry found. We will set up the next directory
diff --git a/fs/fat/fs_fat32.h b/fs/fat/fs_fat32.h
index 3c6e191618..3e80308462 100644
--- a/fs/fat/fs_fat32.h
+++ b/fs/fat/fs_fat32.h
@@ -1054,8 +1054,9 @@ EXTERN int fat_allocatedirentry(struct fat_mountpt_s *fs,
struct fat_dirinfo_s *dirinfo);
EXTERN int fat_freedirentry(struct fat_mountpt_s *fs,
struct fat_dirseq_s *seq);
-EXTERN int fat_dirname2path(struct fat_mountpt_s *fs,
- struct fs_dirent_s *dir);
+EXTERN int fat_dirname2path(FAR struct fat_mountpt_s *fs,
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
/* File creation and removal helpers */
diff --git a/fs/fat/fs_fat32dirent.c b/fs/fat/fs_fat32dirent.c
index 0876155a70..431709b9ba 100644
--- a/fs/fat/fs_fat32dirent.c
+++ b/fs/fat/fs_fat32dirent.c
@@ -136,7 +136,8 @@ static inline int fat_getsfname(FAR uint8_t *direntry, FAR char *buffer,
static void fat_getlfnchunk(FAR uint8_t *chunk, FAR lfnchar *dest,
int nchunk);
static inline int fat_getlfname(FAR struct fat_mountpt_s *fs,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
#endif
static int fat_putsfname(FAR struct fat_mountpt_s *fs,
FAR struct fat_dirinfo_s *dirinfo);
@@ -1960,7 +1961,8 @@ static void fat_getlfnchunk(FAR uint8_t *chunk, FAR lfnchar *dest,
#ifdef CONFIG_FAT_LFN
static inline int fat_getlfname(FAR struct fat_mountpt_s *fs,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR uint8_t *direntry;
lfnchar lfname[LDIR_MAXLFNCHARS];
@@ -2030,7 +2032,7 @@ static inline int fat_getlfname(FAR struct fat_mountpt_s *fs,
* terminator will fit).
*/
- dir->fd_dir.d_name[NAME_MAX] = '\0';
+ entry->d_name[NAME_MAX] = '\0';
offset = NAME_MAX;
}
@@ -2038,7 +2040,7 @@ static inline int fat_getlfname(FAR struct fat_mountpt_s *fs,
for (i = nsrc - 1; i >= 0; i--)
{
- offset = fat_ucstoutf8((FAR uint8_t *)dir->fd_dir.d_name,
+ offset = fat_ucstoutf8((FAR uint8_t *)entry->d_name,
offset, lfname[i]);
}
# else
@@ -2087,14 +2089,14 @@ static inline int fat_getlfname(FAR struct fat_mountpt_s *fs,
* terminator will fit).
*/
- dir->fd_dir.d_name[offset + nsrc] = '\0';
+ entry->d_name[offset + nsrc] = '\0';
}
/* Then transfer the characters */
for (i = 0; i < nsrc && offset + i < NAME_MAX; i++)
{
- dir->fd_dir.d_name[offset + i] = lfname[i];
+ entry->d_name[offset + i] = lfname[i];
}
}
#endif
@@ -2129,7 +2131,7 @@ static inline int fat_getlfname(FAR struct fat_mountpt_s *fs,
if (offset > 0)
{
- memmove(dir->fd_dir.d_name, &dir->fd_dir.d_name[offset],
+ memmove(entry->d_name, &entry->d_name[offset],
(NAME_MAX + 1) - offset);
}
# endif
@@ -2938,7 +2940,8 @@ int fat_freedirentry(FAR struct fat_mountpt_s *fs, struct fat_dirseq_s *seq)
****************************************************************************/
int fat_dirname2path(FAR struct fat_mountpt_s *fs,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
uint16_t diroffset;
FAR uint8_t *direntry;
@@ -2961,14 +2964,14 @@ int fat_dirname2path(FAR struct fat_mountpt_s *fs,
* entries.
*/
- return fat_getlfname(fs, dir);
+ return fat_getlfname(fs, dir, entry);
}
else
#endif
{
/* No.. Get the name from a short file name directory entries */
- return fat_getsfname(direntry, dir->fd_dir.d_name, NAME_MAX + 1);
+ return fat_getsfname(direntry, entry->d_name, NAME_MAX + 1);
}
}
diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c
index 4ebca506c2..a4ebf34940 100644
--- a/fs/hostfs/hostfs.c
+++ b/fs/hostfs/hostfs.c
@@ -83,7 +83,8 @@ static int hostfs_opendir(FAR struct inode *mountpt,
static int hostfs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int hostfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int hostfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -917,7 +918,8 @@ static int hostfs_closedir(FAR struct inode *mountpt,
****************************************************************************/
static int hostfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct hostfs_mountpt_s *fs;
int ret;
@@ -940,7 +942,7 @@ static int hostfs_readdir(FAR struct inode *mountpt,
/* Call the host OS's readdir function */
- ret = host_readdir(dir->u.hostfs.fs_dir, &dir->fd_dir);
+ ret = host_readdir(dir->u.hostfs.fs_dir, entry);
hostfs_semgive(fs);
return ret;
diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c
index 003bdd3d37..efcacd2a3c 100644
--- a/fs/littlefs/lfs_vfs.c
+++ b/fs/littlefs/lfs_vfs.c
@@ -97,7 +97,8 @@ static int littlefs_opendir(FAR struct inode *mountpt,
static int littlefs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int littlefs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int littlefs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -820,7 +821,8 @@ static int littlefs_closedir(FAR struct inode *mountpt,
****************************************************************************/
static int littlefs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct littlefs_mountpt_s *fs;
FAR struct lfs_dir *priv;
@@ -845,14 +847,14 @@ static int littlefs_readdir(FAR struct inode *mountpt,
{
if (info.type == LFS_TYPE_REG)
{
- dir->fd_dir.d_type = DTYPE_FILE;
+ entry->d_type = DTYPE_FILE;
}
else
{
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
}
- strlcpy(dir->fd_dir.d_name, info.name, sizeof(dir->fd_dir.d_name));
+ strlcpy(entry->d_name, info.name, sizeof(entry->d_name));
}
else if (ret == 0)
{
diff --git a/fs/nfs/nfs_vfsops.c b/fs/nfs/nfs_vfsops.c
index f3fcd464a6..99f43b3435 100644
--- a/fs/nfs/nfs_vfsops.c
+++ b/fs/nfs/nfs_vfsops.c
@@ -140,7 +140,8 @@ static int nfs_truncate(FAR struct file *filep, off_t length);
static int nfs_opendir(FAR struct inode *mountpt,
FAR const char *relpath, FAR struct fs_dirent_s *dir);
static int nfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int nfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static void nfs_decode_args(FAR struct nfs_mount_parameters *nprmt,
@@ -1478,7 +1479,8 @@ errout_with_semaphore:
****************************************************************************/
static int nfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct nfsmount *nmp;
struct file_handle fhandle;
@@ -1658,12 +1660,12 @@ next_entry:
length = NAME_MAX;
}
- memcpy(dir->fd_dir.d_name, name, length);
- dir->fd_dir.d_name[length] = '\0';
- finfo("name: \"%s\"\n", dir->fd_dir.d_name);
+ memcpy(entry->d_name, name, length);
+ entry->d_name[length] = '\0';
+ finfo("name: \"%s\"\n", entry->d_name);
- if (strcmp(dir->fd_dir.d_name, ".") == 0 ||
- strcmp(dir->fd_dir.d_name, "..") == 0)
+ if (strcmp(entry->d_name, ".") == 0 ||
+ strcmp(entry->d_name, "..") == 0)
{
goto next_entry; /* Skip . and .. */
}
@@ -1675,7 +1677,7 @@ next_entry:
fhandle.length = (uint32_t)dir->u.nfs.nfs_fhsize;
memcpy(&fhandle.handle, dir->u.nfs.nfs_fhandle, fhandle.length);
- ret = nfs_lookup(nmp, dir->fd_dir.d_name, &fhandle, &obj_attributes, NULL);
+ ret = nfs_lookup(nmp, entry->d_name, &fhandle, &obj_attributes, NULL);
if (ret != OK)
{
ferr("ERROR: nfs_lookup failed: %d\n", ret);
@@ -1692,35 +1694,35 @@ next_entry:
break;
case NFSOCK: /* Socket */
- dir->fd_dir.d_type = DTYPE_SOCK;
+ entry->d_type = DTYPE_SOCK;
break;
case NFLNK: /* Symbolic link */
- dir->fd_dir.d_type = DTYPE_LINK;
+ entry->d_type = DTYPE_LINK;
break;
case NFREG: /* Regular file */
- dir->fd_dir.d_type = DTYPE_FILE;
+ entry->d_type = DTYPE_FILE;
break;
case NFDIR: /* Directory */
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
break;
case NFBLK: /* Block special device file */
- dir->fd_dir.d_type = DTYPE_BLK;
+ entry->d_type = DTYPE_BLK;
break;
case NFFIFO: /* Named FIFO */
- dir->fd_dir.d_type = DTYPE_FIFO;
+ entry->d_type = DTYPE_FIFO;
break;
case NFCHR: /* Character special device file */
- dir->fd_dir.d_type = DTYPE_CHR;
+ entry->d_type = DTYPE_CHR;
break;
}
- finfo("type: %d->%d\n", (int)tmp, dir->fd_dir.d_type);
+ finfo("type: %d->%d\n", (int)tmp, entry->d_type);
errout_with_semaphore:
nfs_semgive(nmp);
diff --git a/fs/nxffs/nxffs.h b/fs/nxffs/nxffs.h
index 77be52d4f5..7fa120b617 100644
--- a/fs/nxffs/nxffs.h
+++ b/fs/nxffs/nxffs.h
@@ -1109,7 +1109,9 @@ int nxffs_truncate(FAR struct file *filep, off_t length);
int nxffs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct fs_dirent_s *dir);
-int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
+int nxffs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
int nxffs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir);
int nxffs_bind(FAR struct inode *blkdriver, FAR const void *data,
diff --git a/fs/nxffs/nxffs_dirent.c b/fs/nxffs/nxffs_dirent.c
index df06fd029b..8894060bcb 100644
--- a/fs/nxffs/nxffs_dirent.c
+++ b/fs/nxffs/nxffs_dirent.c
@@ -26,7 +26,6 @@
#include <stdint.h>
#include <string.h>
-#include <dirent.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
@@ -97,10 +96,12 @@ errout:
*
****************************************************************************/
-int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir)
+int nxffs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *dentry)
{
FAR struct nxffs_volume_s *volume;
- FAR struct nxffs_entry_s entry;
+ struct nxffs_entry_s entry;
off_t offset;
int ret;
@@ -132,8 +133,8 @@ int nxffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir)
/* Return the filename and file type */
finfo("Offset %jd: \"%s\"\n", (intmax_t)entry.hoffset, entry.name);
- dir->fd_dir.d_type = DTYPE_FILE;
- strlcpy(dir->fd_dir.d_name, entry.name, sizeof(dir->fd_dir.d_name));
+ dentry->d_type = DTYPE_FILE;
+ strlcpy(dentry->d_name, entry.name, sizeof(dentry->d_name));
/* Discard this entry and set the next offset. */
diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c
index de47d7b006..2858c33b6e 100644
--- a/fs/procfs/fs_procfs.c
+++ b/fs/procfs/fs_procfs.c
@@ -228,7 +228,7 @@ static int procfs_opendir(FAR struct inode *mountpt, const char *relpath,
static int procfs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int procfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir, FAR struct dirent *entry);
static int procfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -717,9 +717,11 @@ static int procfs_closedir(FAR struct inode *mountpt,
*
****************************************************************************/
-static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int procfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
- FAR const struct procfs_entry_s *entry = NULL;
+ FAR const struct procfs_entry_s *pentry = NULL;
FAR struct procfs_dir_priv_s *priv;
FAR struct procfs_level0_s *level0;
FAR struct tcb_s *tcb;
@@ -751,8 +753,8 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
while (index < priv->nentries + g_procfs_entrycount)
{
- entry = &g_procfs_entries[index - priv->nentries];
- name = entry->pathpattern;
+ pentry = &g_procfs_entries[index - priv->nentries];
+ name = pentry->pathpattern;
while (*name != '/' && *name != '\0')
{
@@ -820,21 +822,21 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
level0->lastlen = strcspn(name, "/");
level0->lastread = name;
- strlcpy(dir->fd_dir.d_name, name, level0->lastlen + 1);
+ strlcpy(entry->d_name, name, level0->lastlen + 1);
/* If the entry is a directory type OR if the reported name is
* only a sub-string of the entry (meaning that it contains
* '/'), then report this entry as a directory.
*/
- if (entry->type == PROCFS_DIR_TYPE ||
+ if (pentry->type == PROCFS_DIR_TYPE ||
level0->lastlen != strlen(name))
{
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
}
else
{
- dir->fd_dir.d_type = DTYPE_FILE;
+ entry->d_type = DTYPE_FILE;
}
/* Advance to next entry for the next read */
@@ -859,8 +861,8 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
/* Save the filename=pid and file type=directory */
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
- procfs_snprintf(dir->fd_dir.d_name, NAME_MAX + 1, "%d", (int)pid);
+ entry->d_type = DTYPE_DIRECTORY;
+ procfs_snprintf(entry->d_name, NAME_MAX + 1, "%d", (int)pid);
/* Set up the next directory entry offset. NOTE that we could use
* the standard f_pos instead of our own private index.
@@ -894,27 +896,27 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
level1->subdirlen + 1];
level1->lastlen = strcspn(name, "/");
level1->lastread = name;
- strncpy(dir->fd_dir.d_name, name, level1->lastlen);
+ strncpy(entry->d_name, name, level1->lastlen);
/* Some of the search entries contain '**' wildcards. When we
* report the entry name, we must remove this wildcard search
* specifier.
*/
- while (dir->fd_dir.d_name[level1->lastlen - 1] == '*')
+ while (entry->d_name[level1->lastlen - 1] == '*')
{
level1->lastlen--;
}
- dir->fd_dir.d_name[level1->lastlen] = '\0';
+ entry->d_name[level1->lastlen] = '\0';
if (name[level1->lastlen] == '/')
{
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
}
else
{
- dir->fd_dir.d_type = DTYPE_FILE;
+ entry->d_type = DTYPE_FILE;
}
level1->base.index++;
@@ -934,7 +936,7 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
*/
DEBUGASSERT(priv->procfsentry && priv->procfsentry->ops->readdir);
- ret = priv->procfsentry->ops->readdir(dir);
+ ret = priv->procfsentry->ops->readdir(dir, entry);
}
return ret;
diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c
index 097610f137..5f53a8c535 100644
--- a/fs/procfs/fs_procfsproc.c
+++ b/fs/procfs/fs_procfsproc.c
@@ -225,7 +225,8 @@ static int proc_dup(FAR const struct file *oldp,
static int proc_opendir(const char *relpath,
FAR struct fs_dirent_s *dir);
static int proc_closedir(FAR struct fs_dirent_s *dir);
-static int proc_readdir(FAR struct fs_dirent_s *dir);
+static int proc_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int proc_rewinddir(FAR struct fs_dirent_s *dir);
static int proc_stat(FAR const char *relpath, FAR struct stat *buf);
@@ -1920,7 +1921,8 @@ static int proc_closedir(FAR struct fs_dirent_s *dir)
*
****************************************************************************/
-static int proc_readdir(struct fs_dirent_s *dir)
+static int proc_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct proc_dir_s *procdir;
FAR const struct proc_node_s *node = NULL;
@@ -1984,8 +1986,8 @@ static int proc_readdir(struct fs_dirent_s *dir)
/* Save the filename and file type */
- dir->fd_dir.d_type = node->dtype;
- strlcpy(dir->fd_dir.d_name, node->name, sizeof(dir->fd_dir.d_name));
+ entry->d_type = node->dtype;
+ strlcpy(entry->d_name, node->name, sizeof(entry->d_name));
/* Set up the next directory entry offset. NOTE that we could use the
* standard f_pos instead of our own private index.
diff --git a/fs/procfs/fs_skeleton.c b/fs/procfs/fs_skeleton.c
index 3ee618efe9..254913a7f7 100644
--- a/fs/procfs/fs_skeleton.c
+++ b/fs/procfs/fs_skeleton.c
@@ -102,7 +102,8 @@ static int skel_dup(FAR const struct file *oldp,
static int skel_opendir(FAR const char *relpath,
FAR struct fs_dirent_s *dir);
static int skel_closedir(FAR struct fs_dirent_s *dir);
-static int skel_readdir(FAR struct fs_dirent_s *dir);
+static int skel_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int skel_rewinddir(FAR struct fs_dirent_s *dir);
static int skel_stat(FAR const char *relpath, FAR struct stat *buf);
@@ -399,7 +400,8 @@ static int skel_closedir(FAR struct fs_dirent_s *dir)
*
****************************************************************************/
-static int skel_readdir(FAR struct fs_dirent_s *dir)
+static int skel_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct skel_level1_s *level1;
char filename[16];
@@ -439,8 +441,8 @@ static int skel_readdir(FAR struct fs_dirent_s *dir)
/* TODO: Specify the type of entry */
- dir->fd_dir.d_type = DTYPE_FILE;
- strlcpy(dir->fd_dir.d_name, filename, sizeof(dir->fd_dir.d_name));
+ entry->d_type = DTYPE_FILE;
+ strlcpy(entry->d_name, filename, sizeof(entry->d_name));
/* Set up the next directory entry offset. NOTE that we could use the
* standard f_pos instead of our own private index.
diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c
index ea773ed004..35ccf4cb78 100644
--- a/fs/romfs/fs_romfs.c
+++ b/fs/romfs/fs_romfs.c
@@ -66,7 +66,8 @@ static int romfs_opendir(FAR struct inode *mountpt,
FAR const char *relpath,
FAR struct fs_dirent_s *dir);
static int romfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int romfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -811,7 +812,8 @@ errout_with_semaphore:
****************************************************************************/
static int romfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct romfs_mountpt_s *rm;
#ifndef CONFIG_FS_ROMFS_CACHE_NODE
@@ -870,8 +872,8 @@ static int romfs_readdir(FAR struct inode *mountpt,
#ifdef CONFIG_FS_ROMFS_CACHE_NODE
next = (*dir->u.romfs.fr_currnode)->rn_next;
- strlcpy(dir->fd_dir.d_name, (*dir->u.romfs.fr_currnode)->rn_name,
- sizeof(dir->fd_dir.d_name));
+ strlcpy(entry->d_name, (*dir->u.romfs.fr_currnode)->rn_name,
+ sizeof(entry->d_name));
dir->u.romfs.fr_currnode++;
#else
/* Parse the directory entry */
@@ -887,7 +889,7 @@ static int romfs_readdir(FAR struct inode *mountpt,
/* Save the filename */
ret = romfs_parsefilename(rm, dir->u.romfs.fr_curroffset,
- dir->fd_dir.d_name);
+ entry->d_name);
if (ret < 0)
{
ferr("ERROR: romfs_parsefilename failed: %d\n", ret);
@@ -903,17 +905,17 @@ static int romfs_readdir(FAR struct inode *mountpt,
if (IS_DIRECTORY(next))
{
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
break;
}
else if (IS_FILE(next))
{
- dir->fd_dir.d_type = DTYPE_FILE;
+ entry->d_type = DTYPE_FILE;
break;
}
else if (IS_SOFTLINK(next))
{
- dir->fd_dir.d_type = DTYPE_LINK;
+ entry->d_type = DTYPE_LINK;
break;
}
}
diff --git a/fs/rpmsgfs/rpmsgfs.c b/fs/rpmsgfs/rpmsgfs.c
index 6f91a373b9..7e76c3a00d 100644
--- a/fs/rpmsgfs/rpmsgfs.c
+++ b/fs/rpmsgfs/rpmsgfs.c
@@ -113,7 +113,8 @@ static int rpmsgfs_opendir(FAR struct inode *mountpt,
static int rpmsgfs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int rpmsgfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int rpmsgfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -956,7 +957,8 @@ static int rpmsgfs_closedir(FAR struct inode *mountpt,
****************************************************************************/
static int rpmsgfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct rpmsgfs_mountpt_s *fs;
int ret;
@@ -980,7 +982,7 @@ static int rpmsgfs_readdir(FAR struct inode *mountpt,
/* Call the host OS's readdir function */
ret = rpmsgfs_client_readdir(fs->handle,
- dir->u.rpmsgfs.fs_dir, &dir->fd_dir);
+ dir->u.rpmsgfs.fs_dir, entry);
rpmsgfs_semgive(fs);
return ret;
diff --git a/fs/smartfs/smartfs_procfs.c b/fs/smartfs/smartfs_procfs.c
index 5ce38d55cc..b59f295e2c 100644
--- a/fs/smartfs/smartfs_procfs.c
+++ b/fs/smartfs/smartfs_procfs.c
@@ -118,7 +118,8 @@ static int smartfs_dup(FAR const struct file *oldp,
static int smartfs_opendir(const char *relpath,
FAR struct fs_dirent_s *dir);
static int smartfs_closedir(FAR struct fs_dirent_s *dir);
-static int smartfs_readdir(FAR struct fs_dirent_s *dir);
+static int smartfs_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int smartfs_rewinddir(FAR struct fs_dirent_s *dir);
static int smartfs_stat(FAR const char *relpath, FAR struct stat *buf);
@@ -601,7 +602,8 @@ static int smartfs_closedir(FAR struct fs_dirent_s *dir)
*
****************************************************************************/
-static int smartfs_readdir(struct fs_dirent_s *dir)
+static int smartfs_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct smartfs_level1_s *level1;
int ret;
@@ -640,9 +642,9 @@ static int smartfs_readdir(struct fs_dirent_s *dir)
return -ENOENT;
}
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
- strlcpy(dir->fd_dir.d_name, level1->mount->fs_blkdriver->i_name,
- sizeof(dir->fd_dir.d_name));
+ entry->d_type = DTYPE_DIRECTORY;
+ strlcpy(entry->d_name, level1->mount->fs_blkdriver->i_name,
+ sizeof(entry->d_name));
/* Advance to next entry */
@@ -653,17 +655,17 @@ static int smartfs_readdir(struct fs_dirent_s *dir)
{
/* Listing the contents of a specific mount */
- dir->fd_dir.d_type = g_direntry[level1->base.index].type;
- strlcpy(dir->fd_dir.d_name, g_direntry[level1->base.index++].name,
- sizeof(dir->fd_dir.d_name));
+ entry->d_type = g_direntry[level1->base.index].type;
+ strlcpy(entry->d_name, g_direntry[level1->base.index++].name,
+ sizeof(entry->d_name));
}
else if (level1->base.level == 3)
{
/* Listing the contents of a specific entry */
- dir->fd_dir.d_type = g_direntry[level1->base.index].type;
- strlcpy(dir->fd_dir.d_name, g_direntry[level1->direntry].name,
- sizeof(dir->fd_dir.d_name));
+ entry->d_type = g_direntry[level1->base.index].type;
+ strlcpy(entry->d_name, g_direntry[level1->direntry].name,
+ sizeof(entry->d_name));
level1->base.index++;
}
diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c
index eb403c0d3a..413eaf80d8 100644
--- a/fs/smartfs/smartfs_smart.c
+++ b/fs/smartfs/smartfs_smart.c
@@ -73,7 +73,8 @@ static int smartfs_opendir(FAR struct inode *mountpt,
FAR const char *relpath,
FAR struct fs_dirent_s *dir);
static int smartfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *dentry);
static int smartfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -1252,7 +1253,9 @@ errout_with_semaphore:
*
****************************************************************************/
-static int smartfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int smartfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *dentry)
{
struct smartfs_mountpt_s *fs;
int ret;
@@ -1325,17 +1328,16 @@ static int smartfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
if ((entry->flags & SMARTFS_DIRENT_TYPE) ==
SMARTFS_DIRENT_TYPE_DIR)
{
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ dentry->d_type = DTYPE_DIRECTORY;
}
else
{
- dir->fd_dir.d_type = DTYPE_FILE;
+ dentry->d_type = DTYPE_FILE;
}
/* Copy the entry name to dirent */
- strlcpy(dir->fd_dir.d_name, entry->name,
- sizeof(dir->fd_dir.d_name));
+ strlcpy(dentry->d_name, entry->name, sizeof(dentry->d_name));
/* Now advance to the next entry */
diff --git a/fs/spiffs/src/spiffs_vfs.c b/fs/spiffs/src/spiffs_vfs.c
index 9bc47dd536..de4cc8797e 100644
--- a/fs/spiffs/src/spiffs_vfs.c
+++ b/fs/spiffs/src/spiffs_vfs.c
@@ -99,9 +99,11 @@ static int spiffs_truncate(FAR struct file *filep, off_t length);
static int spiffs_opendir(FAR struct inode *mountpt,
FAR const char *relpath, FAR struct fs_dirent_s *dir);
static int spiffs_closedir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int spiffs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *dentry);
static int spiffs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
@@ -258,11 +260,7 @@ static int spiffs_readdir_callback(FAR struct spiffs_s *fs,
SPIFFS_PH_FLAG_NDXDELE)) ==
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_NDXDELE))
{
- FAR struct fs_dirent_s *dir = (FAR struct fs_dirent_s *)user_var;
- FAR struct dirent *entryp;
-
- DEBUGASSERT(dir != NULL);
- entryp = &dir->fd_dir;
+ FAR struct dirent *entryp = user_var;
#ifdef CONFIG_SPIFFS_LEADING_SLASH
/* Skip the leading '/'. */
@@ -1280,7 +1278,8 @@ static int spiffs_closedir(FAR struct inode *mountpt,
****************************************************************************/
static int spiffs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *dentry)
{
FAR struct spiffs_s *fs;
int16_t blkndx;
@@ -1303,7 +1302,7 @@ static int spiffs_readdir(FAR struct inode *mountpt,
ret = spiffs_foreach_objlu(fs, dir->u.spiffs.block, dir->u.spiffs.entry,
SPIFFS_VIS_NO_WRAP, 0, spiffs_readdir_callback,
- NULL, dir, &blkndx, &entry);
+ NULL, dentry, &blkndx, &entry);
if (ret >= 0)
{
dir->u.spiffs.block = blkndx;
diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
index 8165a19833..8ea2e1d7f5 100644
--- a/fs/tmpfs/fs_tmpfs.c
+++ b/fs/tmpfs/fs_tmpfs.c
@@ -136,7 +136,8 @@ static int tmpfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
static int tmpfs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int tmpfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int tmpfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int tmpfs_bind(FAR struct inode *blkdriver, FAR const void *data,
@@ -1880,7 +1881,8 @@ static int tmpfs_closedir(FAR struct inode *mountpt,
****************************************************************************/
static int tmpfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct tmpfs_directory_s *tdo;
unsigned int index;
@@ -1923,18 +1925,18 @@ static int tmpfs_readdir(FAR struct inode *mountpt,
{
/* A directory */
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
}
else /* to->to_type == TMPFS_REGULAR) */
{
/* A regular file */
- dir->fd_dir.d_type = DTYPE_FILE;
+ entry->d_type = DTYPE_FILE;
}
/* Copy the entry name */
- strlcpy(dir->fd_dir.d_name, tde->tde_name, sizeof(dir->fd_dir.d_name));
+ strlcpy(entry->d_name, tde->tde_name, sizeof(entry->d_name));
/* Save the index for next time */
diff --git a/fs/unionfs/fs_unionfs.c b/fs/unionfs/fs_unionfs.c
index 49ef7da038..37e77e4c13 100644
--- a/fs/unionfs/fs_unionfs.c
+++ b/fs/unionfs/fs_unionfs.c
@@ -163,7 +163,8 @@ static int unionfs_opendir(struct inode *mountpt, const char *relpath,
static int unionfs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int unionfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int unionfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -1669,7 +1670,9 @@ static int unionfs_closedir(FAR struct inode *mountpt,
* Name: unionfs_readdir
****************************************************************************/
-static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
+static int unionfs_readdir(FAR struct inode *mountpt,
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct unionfs_inode_s *ui;
FAR struct unionfs_mountpt_s *um;
@@ -1718,11 +1721,11 @@ static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
* directories.
*/
- strlcpy(dir->fd_dir.d_name, um->um_prefix, sizeof(dir->fd_dir.d_name));
+ strlcpy(entry->d_name, um->um_prefix, sizeof(entry->d_name));
/* Describe this as a read only directory */
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
/* Increment the index to file system 2 (maybe) */
@@ -1760,7 +1763,7 @@ static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
{
/* Read the directory entry */
- ret = ops->readdir(um->um_node, fu->fu_lower[fu->fu_ndx]);
+ ret = ops->readdir(um->um_node, fu->fu_lower[fu->fu_ndx], entry);
/* Did the read operation fail because we reached the end of the
* directory? In that case, the error would be -ENOENT. If we
@@ -1792,12 +1795,12 @@ static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
* be multiple directories.
*/
- strlcpy(dir->fd_dir.d_name, um->um_prefix,
- sizeof(dir->fd_dir.d_name));
+ strlcpy(entry->d_name, um->um_prefix,
+ sizeof(entry->d_name));
/* Describe this as a read only directory */
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
/* Mark the end of the directory listing */
@@ -1869,7 +1872,7 @@ static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
/* Then try the read operation again */
- ret = ops->readdir(um->um_node, fu->fu_lower[1]);
+ ret = ops->readdir(um->um_node, fu->fu_lower[1], entry);
}
}
@@ -1887,8 +1890,7 @@ static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
* is not a duplicate.
*/
- relpath = unionfs_relpath(fu->fu_relpath,
- fu->fu_lower[1]->fd_dir.d_name);
+ relpath = unionfs_relpath(fu->fu_relpath, entry->d_name);
if (relpath)
{
int tmp;
@@ -1915,13 +1917,6 @@ static int unionfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir)
}
}
while (duplicate);
-
- /* Copy the return information into the dirent structure that the
- * application will see.
- */
-
- memcpy(&dir->fd_dir, &fu->fu_lower[fu->fu_ndx]->fd_dir,
- sizeof(struct dirent));
}
return ret;
diff --git a/fs/userfs/fs_userfs.c b/fs/userfs/fs_userfs.c
index 22a00980f9..83577a70df 100644
--- a/fs/userfs/fs_userfs.c
+++ b/fs/userfs/fs_userfs.c
@@ -110,7 +110,8 @@ static int userfs_opendir(FAR struct inode *mountpt,
static int userfs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
static int userfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int userfs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
@@ -1236,7 +1237,8 @@ static int userfs_closedir(FAR struct inode *mountpt,
****************************************************************************/
static int userfs_readdir(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir)
+ FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct userfs_state_s *priv;
FAR struct userfs_readdir_request_s *req;
@@ -1302,7 +1304,7 @@ static int userfs_readdir(FAR struct inode *mountpt,
/* Return the dirent */
DEBUGASSERT(dir != NULL);
- memcpy(&dir->fd_dir, &resp->entry, sizeof(struct dirent));
+ memcpy(entry, &resp->entry, sizeof(struct dirent));
return resp->ret;
}
diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c
index 0c698acd77..2161703088 100644
--- a/fs/vfs/fs_dir.c
+++ b/fs/vfs/fs_dir.c
@@ -207,6 +207,7 @@ static off_t seek_mountptdir(FAR struct file *filep, off_t offset)
{
FAR struct fs_dirent_s *dir = filep->f_priv;
FAR struct inode *inode = dir->fd_root;
+ struct dirent entry;
off_t pos;
/* Determine a starting point for the seek. If the seek
@@ -240,7 +241,7 @@ static off_t seek_mountptdir(FAR struct file *filep, off_t offset)
{
int ret;
- ret = inode->u.i_mops->readdir(inode, dir);
+ ret = inode->u.i_mops->readdir(inode, dir, &entry);
if (ret < 0)
{
return ret;
@@ -259,7 +260,8 @@ static off_t seek_mountptdir(FAR struct file *filep, off_t offset)
* Name: read_pseudodir
****************************************************************************/
-static int read_pseudodir(FAR struct fs_dirent_s *dir)
+static int read_pseudodir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct inode *prev;
@@ -276,51 +278,51 @@ static int read_pseudodir(FAR struct fs_dirent_s *dir)
/* Copy the inode name into the dirent structure */
- strlcpy(dir->fd_dir.d_name, dir->u.pseudo.fd_next->i_name,
- sizeof(dir->fd_dir.d_name));
+ strlcpy(entry->d_name, dir->u.pseudo.fd_next->i_name,
+ sizeof(entry->d_name));
/* If the node has file operations, we will say that it is a file. */
- dir->fd_dir.d_type = DTYPE_UNKNOWN;
+ entry->d_type = DTYPE_UNKNOWN;
if (dir->u.pseudo.fd_next->u.i_ops != NULL)
{
#ifndef CONFIG_DISABLE_MOUNTPOINT
if (INODE_IS_BLOCK(dir->u.pseudo.fd_next))
{
- dir->fd_dir.d_type = DTYPE_BLK;
+ entry->d_type = DTYPE_BLK;
}
else if (INODE_IS_MTD(dir->u.pseudo.fd_next))
{
- dir->fd_dir.d_type = DTYPE_MTD;
+ entry->d_type = DTYPE_MTD;
}
else if (INODE_IS_MOUNTPT(dir->u.pseudo.fd_next))
{
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
}
else
#endif
#ifdef CONFIG_PSEUDOFS_SOFTLINKS
if (INODE_IS_SOFTLINK(dir->u.pseudo.fd_next))
{
- dir->fd_dir.d_type = DTYPE_LINK;
+ entry->d_type = DTYPE_LINK;
}
else
#endif
if (INODE_IS_DRIVER(dir->u.pseudo.fd_next))
{
- dir->fd_dir.d_type = DTYPE_CHR;
+ entry->d_type = DTYPE_CHR;
}
else if (INODE_IS_NAMEDSEM(dir->u.pseudo.fd_next))
{
- dir->fd_dir.d_type = DTYPE_SEM;
+ entry->d_type = DTYPE_SEM;
}
else if (INODE_IS_MQUEUE(dir->u.pseudo.fd_next))
{
- dir->fd_dir.d_type = DTYPE_MQ;
+ entry->d_type = DTYPE_MQ;
}
else if (INODE_IS_SHM(dir->u.pseudo.fd_next))
{
- dir->fd_dir.d_type = DTYPE_SHM;
+ entry->d_type = DTYPE_SHM;
}
}
@@ -332,7 +334,7 @@ static int read_pseudodir(FAR struct fs_dirent_s *dir)
if (dir->u.pseudo.fd_next->i_child != NULL ||
dir->u.pseudo.fd_next->u.i_ops == NULL)
{
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
+ entry->d_type = DTYPE_DIRECTORY;
}
/* Now get the inode to visit next time that readdir() is called */
@@ -432,14 +434,15 @@ static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,
#ifndef CONFIG_DISABLE_MOUNTPOINT
if (INODE_IS_MOUNTPT(inode))
{
- ret = inode->u.i_mops->readdir(inode, dir);
+ ret = inode->u.i_mops->readdir(inode, dir,
+ (FAR struct dirent *)buffer);
}
else
#endif
{
/* The node is part of the root pseudo file system */
- ret = read_pseudodir(dir);
+ ret = read_pseudodir(dir, (FAR struct dirent *)buffer);
}
/* ret < 0 is an error. Special case: ret = -ENOENT is end of file */
@@ -455,8 +458,7 @@ static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,
}
filep->f_pos++;
- memcpy(buffer, &dir->fd_dir, sizeof(dir->fd_dir));
- return sizeof(dir->fd_dir);
+ return sizeof(struct dirent);
}
static off_t dir_seek(FAR struct file *filep, off_t offset, int whence)
diff --git a/include/nuttx/fs/dirent.h b/include/nuttx/fs/dirent.h
index d66a8bc24f..5c4b19bcd6 100644
--- a/include/nuttx/fs/dirent.h
+++ b/include/nuttx/fs/dirent.h
@@ -321,12 +321,6 @@ struct fs_dirent_s
#endif
#endif /* !CONFIG_DISABLE_MOUNTPOINT */
} u;
-
- /* In any event, this the actual struct dirent that is returned by
- * readdir
- */
-
- struct dirent fd_dir; /* Populated when readdir is called */
};
/****************************************************************************
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index e8baeba1ee..43d9d5c9ec 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -33,6 +33,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
+#include <dirent.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
@@ -305,7 +306,7 @@ struct mountpt_operations
int (*closedir)(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
int (*readdir)(FAR struct inode *mountpt,
- FAR struct fs_dirent_s *dir);
+ FAR struct fs_dirent_s *dir, FAR struct dirent *entry);
int (*rewinddir)(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir);
diff --git a/include/nuttx/fs/procfs.h b/include/nuttx/fs/procfs.h
index 4ea05e58c2..62e5373546 100644
--- a/include/nuttx/fs/procfs.h
+++ b/include/nuttx/fs/procfs.h
@@ -75,7 +75,7 @@ struct procfs_operations
int (*opendir)(FAR const char *relpath,
FAR struct fs_dirent_s *dir);
int (*closedir)(FAR struct fs_dirent_s *dir);
- int (*readdir)(FAR struct fs_dirent_s *dir);
+ int (*readdir)(FAR struct fs_dirent_s *dir, FAR struct dirent *entry);
int (*rewinddir)(FAR struct fs_dirent_s *dir);
/* Operations on paths */
diff --git a/net/procfs/net_procfs.c b/net/procfs/net_procfs.c
index 39e68e64a4..eeb5e443a8 100644
--- a/net/procfs/net_procfs.c
+++ b/net/procfs/net_procfs.c
@@ -93,7 +93,8 @@ static int netprocfs_dup(FAR const struct file *oldp,
static int netprocfs_opendir(FAR const char *relpath,
FAR struct fs_dirent_s *dir);
static int netprocfs_closedir(FAR struct fs_dirent_s *dir);
-static int netprocfs_readdir(FAR struct fs_dirent_s *dir);
+static int netprocfs_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int netprocfs_rewinddir(FAR struct fs_dirent_s *dir);
static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf);
@@ -486,7 +487,8 @@ static int netprocfs_closedir(FAR struct fs_dirent_s *dir)
*
****************************************************************************/
-static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
+static int netprocfs_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct netprocfs_level1_s *level1;
FAR struct net_driver_s *dev;
@@ -523,8 +525,8 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
{
/* Copy the network statistics directory entry */
- dir->fd_dir.d_type = DTYPE_FILE;
- strncpy(dir->fd_dir.d_name, "stat", NAME_MAX + 1);
+ entry->d_type = DTYPE_FILE;
+ strncpy(entry->d_name, "stat", NAME_MAX + 1);
}
else
#ifdef CONFIG_NET_MLD
@@ -532,8 +534,8 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
{
/* Copy the MLD directory entry */
- dir->fd_dir.d_type = DTYPE_FILE;
- strncpy(dir->fd_dir.d_name, "mld", NAME_MAX + 1);
+ entry->d_type = DTYPE_FILE;
+ strncpy(entry->d_name, "mld", NAME_MAX + 1);
}
else
#endif
@@ -543,8 +545,8 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
{
/* Copy the network statistics directory entry */
- dir->fd_dir.d_type = DTYPE_DIRECTORY;
- strncpy(dir->fd_dir.d_name, "route", NAME_MAX + 1);
+ entry->d_type = DTYPE_DIRECTORY;
+ strncpy(entry->d_name, "route", NAME_MAX + 1);
}
else
#endif
@@ -591,8 +593,8 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
/* Copy the device statistics file entry */
- dir->fd_dir.d_type = DTYPE_FILE;
- strncpy(dir->fd_dir.d_name, dev->d_ifname, NAME_MAX + 1);
+ entry->d_type = DTYPE_FILE;
+ strncpy(entry->d_name, dev->d_ifname, NAME_MAX + 1);
}
/* Set up the next directory entry offset. NOTE that we could use the
@@ -611,7 +613,7 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
DEBUGASSERT(level1->base.procfsentry != NULL &&
level1->base.procfsentry->ops->readdir != NULL);
- ret = level1->base.procfsentry->ops->readdir(dir);
+ ret = level1->base.procfsentry->ops->readdir(dir, entry);
}
return ret;
diff --git a/net/procfs/net_procfs_route.c b/net/procfs/net_procfs_route.c
index aa4a18b7e0..b18aee3a35 100644
--- a/net/procfs/net_procfs_route.c
+++ b/net/procfs/net_procfs_route.c
@@ -161,7 +161,8 @@ static int route_dup(FAR const struct file *oldp,
static int route_opendir(const char *relpath,
FAR struct fs_dirent_s *dir);
static int route_closedir(FAR struct fs_dirent_s *dir);
-static int route_readdir(FAR struct fs_dirent_s *dir);
+static int route_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry);
static int route_rewinddir(FAR struct fs_dirent_s *dir);
static int route_stat(FAR const char *relpath, FAR struct stat *buf);
@@ -685,7 +686,8 @@ static int route_closedir(FAR struct fs_dirent_s *dir)
*
****************************************************************************/
-static int route_readdir(struct fs_dirent_s *dir)
+static int route_readdir(FAR struct fs_dirent_s *dir,
+ FAR struct dirent *entry)
{
FAR struct route_dir_s *level2;
FAR const char *dname;
@@ -722,8 +724,8 @@ static int route_readdir(struct fs_dirent_s *dir)
/* Save the filename and file type */
- dir->fd_dir.d_type = DTYPE_FILE;
- strncpy(dir->fd_dir.d_name, dname, NAME_MAX + 1);
+ entry->d_type = DTYPE_FILE;
+ strncpy(entry->d_name, dname, NAME_MAX + 1);
/* Set up the next directory entry offset. NOTE that we could use the
* standard f_pos instead of our own private index.