Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/sim/src/sim/sim_checkhostfstypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
/* dirent */

STATIC_ASSERT_FILED(nuttx_dirent_s, dirent, d_type);
STATIC_ASSERT_FILED(nuttx_dirent_s, dirent, d_ino);
STATIC_ASSERT_FILED(nuttx_dirent_s, dirent, d_name);

STATIC_ASSERT(sizeof(struct nuttx_dirent_s) == sizeof(struct dirent));
Expand Down
9 changes: 6 additions & 3 deletions fs/vfs/fs_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,
#ifndef CONFIG_DISABLE_MOUNTPOINT
FAR struct inode *inode = dir->fd_root;
#endif
FAR struct dirent *dirent = (FAR struct dirent *)buffer;
int ret;

/* Verify that we were provided with a valid directory structure */
Expand All @@ -480,15 +481,14 @@ 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,
(FAR struct dirent *)buffer);
ret = inode->u.i_mops->readdir(inode, dir, dirent);
}
else
#endif
{
/* The node is part of the root pseudo file system */

ret = read_pseudodir(dir, (FAR struct dirent *)buffer);
ret = read_pseudodir(dir, dirent);
}

/* ret < 0 is an error. Special case: ret = -ENOENT is end of file */
Expand All @@ -503,6 +503,9 @@ static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,
return ret;
}

/* REVISIT: Should we use i_ino for the d_ino field? */

dirent->d_ino = dir->fd_root->i_ino;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d_ino should match st_ino of the file referenced by the directory entry.

a naive implementation would be something like:

fstat(dirent->d_name, &st);
dirent->d_ino = st.st_ino;

iirc, on nuttx, most filesystems just use st_ino = 0.
for those filesystems, it can be optimized to d_ino = 0.

filep->f_pos++;
return sizeof(struct dirent);
}
Expand Down
1 change: 1 addition & 0 deletions include/dirent.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
struct dirent
{
uint8_t d_type; /* Type of file */
ino_t d_ino; /* File serial number, not implemented */
char d_name[NAME_MAX + 1]; /* File name */
};

Expand Down
1 change: 1 addition & 0 deletions include/nuttx/fs/hostfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ struct nuttx_timespec
struct nuttx_dirent_s
{
uint8_t d_type; /* type of file */
nuttx_ino_t d_ino; /* inode number */
char d_name[CONFIG_NAME_MAX + 1]; /* filename */
};

Expand Down