diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index 93ee037785..c5f047ba94 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -71,16 +71,6 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list, return filep; } -/**************************************************************************** - * Name: files_fget - ****************************************************************************/ - -static FAR struct file *files_fget(FAR struct filelist *list, int fd) -{ - return files_fget_by_index(list, fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK, - fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK); -} - /**************************************************************************** * Name: files_extend ****************************************************************************/ @@ -347,6 +337,27 @@ int files_countlist(FAR struct filelist *list) return list->fl_rows * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK; } +/**************************************************************************** + * Name: files_fget + * + * Description: + * Get the instance of struct file from file list by file descriptor. + * + * Input Parameters: + * list - The list of files for a task. + * fd - A valid descriptor between 0 and files_countlist(list). + * + * Returned Value: + * Pointer to file structure of list[fd]. + * + ****************************************************************************/ + +FAR struct file *files_fget(FAR struct filelist *list, int fd) +{ + return files_fget_by_index(list, fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK, + fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK); +} + /**************************************************************************** * Name: file_allocate_from_tcb * diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index c0289f6436..d5f3532de2 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -1193,7 +1193,6 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile, size_t copysize; size_t totalsize; int count; - int ret; int i; DEBUGASSERT(group != NULL); @@ -1226,8 +1225,11 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile, for (i = 0; i < count; i++) { - ret = fs_getfilep(i, &filep); - if (ret != OK || filep == NULL) + filep = files_fget(&group->tg_filelist, i); + + /* Is there an inode associated with the file descriptor? */ + + if (filep->f_inode == NULL) { continue; } diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 4211d36470..032f1c6147 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -882,6 +882,23 @@ int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist, FAR const posix_spawn_file_actions_t *actions, bool cloexec); +/**************************************************************************** + * Name: files_fget + * + * Description: + * Get the instance of struct file from file list by file descriptor. + * + * Input Parameters: + * list - The list of files for a task. + * fd - A valid descriptor between 0 and files_countlist(list). + * + * Returned Value: + * Pointer to file structure of list[fd]. + * + ****************************************************************************/ + +FAR struct file *files_fget(FAR struct filelist *list, int fd); + /**************************************************************************** * Name: file_allocate_from_tcb *