-
Notifications
You must be signed in to change notification settings - Fork 1.5k
dirent.h: Add missing field d_ino #13556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Refer to apache/nuttx#13556, should be merged together. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
yamt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we add the field, i guess we should set a sane value.
at least it should be consistent with st_ino.
I'm not familiar with implementations of VFS, did you mean something like this? static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
FAR struct fs_dirent_s *dir = filep->f_priv;
#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 */
if (buffer == NULL || buflen < sizeof(struct dirent))
{
return -EINVAL;
}
/* The way we handle the readdir depends on the type of inode
* that we are dealing with.
*/
#ifndef CONFIG_DISABLE_MOUNTPOINT
if (INODE_IS_MOUNTPT(inode))
{
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, dirent);
}
/* ret < 0 is an error. Special case: ret = -ENOENT is end of file */
if (ret < 0)
{
if (ret == -ENOENT)
{
ret = 0;
}
return ret;
}
>>> New added here <<<
dirent->d_ino = dir->fd_root->i_ino;
filep->f_pos++;
return sizeof(struct dirent);
} |
Currently implementations of dirent.h do not have a field for the inode number, but it is required by POSIX. For better compatibility with POSIX based applications, it is should be added even if it is not actually implemented, now just use i_ino from inode for it. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
|
|
||
| /* REVISIT: Should we use i_ino for the d_ino field? */ | ||
|
|
||
| dirent->d_ino = dir->fd_root->i_ino; |
There was a problem hiding this comment.
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.
|
honestly speaking, i'm not sure if it's worth to implement d_ino for nuttx. what's your motivation to add d_ino? |
@yamt I'm porting Rust std library to NuttX, the But this is not used by Rust itself, leave it to 0 is OK if nobody really need it. So in the first PR I just add the missing field to make the compiler happy. |
|
And I'm reusing the unix port, so the strcut layout should be aligned to POSIX if possible even if we don't implement it yet |
@no1wudi I think we might need to customise the Unix Port, and make it work for NuttX? It seems a bit odd that we need to add extra Kernel Fields to NuttX, just to support Rust. |
It's OK that just leave it to 0 in Rust side for NuttX, if it's better |
as it can be a bit expensive to perform fstat equivalent on each entries, it might be better to avoid doing that by default. however, unfortunately, there is no reserved values for inode numbers to indicate the "no inode number available" situation as far as i know. wrt rust, depending on how serious your port is, you might need to consider emulating the inode number by yourself. FYI, wasi-libc tries to emulate d_ino by itself for similar reasons. (well, another motivation there is windows support) |
Maybe not 0 but panic if user try to use it for now on NuttX, Rust std allow some unsupported features if platform don't support it.
Thanks for your information, I guess it should be emulated in NuttX side as your comments above instead of Rust side. |
Summary
Currently implementations of dirent.h do not have a field for the inode number, but it is required by POSIX.
For better compatibility with POSIX based applications, it is should be added even if it is not actually implemented.
PR coupled with nuttx-apps PR apache/nuttx-apps#2593.
Impact
include/dirent.h.include/nuttx/fs/hostfs.h.Testing
CI and local machine