fs/directory: update readdir interface for all filesystem

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-07-26 06:56:41 +00:00 committed by Xiang Xiao
parent 3a70962b7a
commit 90db4daca9
30 changed files with 244 additions and 205 deletions

View File

@ -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;

View File

@ -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

View File

@ -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++;

View File

@ -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.

View File

@ -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;
}

View File

@ -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

View File

@ -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 */

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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)
{

View File

@ -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);

View File

@ -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,

View File

@ -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. */

View File

@ -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;

View File

@ -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.

View File

@ -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.

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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++;
}

View File

@ -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 */

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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;
}

View File

@ -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)

View File

@ -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 */
};
/****************************************************************************

View File

@ -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);

View File

@ -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 */

View File

@ -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;

View File

@ -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.