Skip to content

Commit 331f152

Browse files
fs/dirent: add d_ino member to struct dirent
Add the POSIX d_ino (file serial number) member to struct dirent and populate it on every readdir() path, so portable callers (e.g. scp in dropbear) that read dp->d_ino observe a meaningful, non-zero inode number: - include/dirent.h: declare d_ino in struct dirent and drop the outdated comment claiming the field is unimplemented. - include/nuttx/fs/hostfs.h: add d_ino to struct nuttx_dirent_s so the hostfs ABI can carry the inode number across the VFS boundary. - arch/sim/src/sim/posix/sim_hostfs.c: forward the host's ent->d_ino into entry->d_ino. - fs/vfs/fs_dir.c (read_pseudodir): copy the in-memory inode's i_ino into entry->d_ino for the pseudo filesystem. - fs/yaffs/yaffs_vfs.c: forward yaffs's dirent->d_ino into entry->d_ino. - fs/rpmsgfs: extend struct rpmsgfs_readdir_s with an 'ino' field and propagate it across the RPC in both rpmsgfs_server (fills it from the underlying entry) and rpmsgfs_client (writes it back to the caller's nuttx_dirent_s). Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent af7633d commit 331f152

7 files changed

Lines changed: 10 additions & 1 deletion

File tree

arch/sim/src/sim/posix/sim_hostfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
443443
strncpy(entry->d_name, ent->d_name, sizeof(entry->d_name) - 1);
444444
entry->d_name[sizeof(entry->d_name) - 1] = 0;
445445

446+
entry->d_ino = ent->d_ino;
447+
446448
/* Map the type */
447449

448450
if (ent->d_type == DT_REG)

fs/rpmsgfs/rpmsgfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ begin_packed_struct struct rpmsgfs_readdir_s
166166
{
167167
struct rpmsgfs_header_s header;
168168
int32_t fd;
169+
uint32_t ino;
169170
uint32_t type;
170171
char name[0];
171172
} end_packed_struct;

fs/rpmsgfs/rpmsgfs_client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static int rpmsgfs_readdir_handler(FAR struct rpmsg_endpoint *ept,
209209
{
210210
strlcpy(entry->d_name, rsp->name, sizeof(entry->d_name));
211211
entry->d_type = rsp->type;
212+
entry->d_ino = rsp->ino;
212213
}
213214

214215
rpmsg_post(ept, &cookie->sem);

fs/rpmsgfs/rpmsgfs_server.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ static int rpmsgfs_readdir_handler(FAR struct rpmsg_endpoint *ept,
622622
size = MIN(size - len, strlen(entry->d_name) + 1);
623623
msg->type = entry->d_type;
624624
strlcpy(msg->name, entry->d_name, size);
625+
msg->ino = entry->d_ino;
625626
len += size;
626627
ret = 0;
627628
}

fs/vfs/fs_dir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ static int read_pseudodir(FAR struct fs_dirent_s *dir,
376376
entry->d_type = DTYPE_DIRECTORY;
377377
}
378378

379+
entry->d_ino = next->i_ino;
380+
379381
/* Now get the inode to visit next time that readdir() is called */
380382

381383
inode_lock();

include/dirent.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@
107107
* of char containing at least {NAME_MAX} plus one elements.
108108
*
109109
* POSIX also requires the field d_ino (type ino_t) that provides the file
110-
* serial number. This functionality is not implemented in NuttX.
110+
* serial number.
111111
*/
112112

113113
struct dirent
114114
{
115+
ino_t d_ino; /* File serial number */
115116
uint8_t d_type; /* Type of file */
116117
char d_name[NAME_MAX + 1]; /* File name */
117118
};

include/nuttx/fs/hostfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct nuttx_timespec
150150

151151
struct nuttx_dirent_s
152152
{
153+
nuttx_ino_t d_ino;
153154
uint8_t d_type; /* type of file */
154155
char d_name[CONFIG_NAME_MAX + 1]; /* filename */
155156
};

0 commit comments

Comments
 (0)