Skip to content
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

dirent.h: Add missing field d_ino #13556

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

dirent.h: Add missing field d_ino #13556

wants to merge 1 commit into from

Conversation

no1wudi
Copy link
Contributor

@no1wudi no1wudi commented Sep 20, 2024

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.
  • Makes implementation compatible with POSIX.

Testing

CI and local machine

@github-actions github-actions bot added the Size: XS The size of the change in this PR is very small label Sep 20, 2024
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.

Signed-off-by: Huang Qi <[email protected]>
no1wudi added a commit to no1wudi/nuttx-apps that referenced this pull request Sep 20, 2024
Refer to apache/nuttx#13556,
should be merged together.

Signed-off-by: Huang Qi <[email protected]>
Copy link
Contributor

@yamt yamt left a 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.

@no1wudi
Copy link
Contributor Author

no1wudi commented Sep 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: XS The size of the change in this PR is very small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants