Donny9 commented on code in PR #16499:
URL: https://github.com/apache/nuttx/pull/16499#discussion_r2135965641


##########
fs/vfs/fs_dup3.c:
##########
@@ -49,7 +49,8 @@ int dup3(int fd1, int fd2, int flags)
 {
   int ret;
 
-  ret = nx_dup3_from_tcb(this_task(), fd1, fd2, flags);
+  ret = fdlist_dup3(nxsched_get_fdlist_from_tcb(this_task()), fd1,

Review Comment:
   Done~



##########
fs/vfs/fs_dup.c:
##########
@@ -54,32 +56,8 @@
 
 int file_dup(FAR struct file *filep, int minfd, int flags)
 {
-  FAR struct file *filep2;
-  int fd2;
-  int ret;
-#ifdef CONFIG_FDCHECK
-  minfd = fdcheck_restore(minfd);
-#endif
-
-  fd2 = file_allocate(g_root_inode, 0, 0, NULL, minfd, true);
-  if (fd2 < 0)
-    {
-      return fd2;
-    }
-
-  ret = file_get(fd2, &filep2);
-  DEBUGASSERT(ret >= 0);
-
-  ret = file_dup3(filep, filep2, flags);
-
-  file_put(filep2);
-  if (ret >= 0)
-    {
-      return fd2;
-    }
-
-  file_put(filep2);
-  return ret;
+  return fdlist_dupfile(nxsched_get_fdlist_from_tcb(this_task()), flags,

Review Comment:
   Done~



##########
include/nuttx/fs/fs.h:
##########
@@ -880,117 +882,188 @@ int nx_umount2(FAR const char *target, unsigned int 
flags);
 #endif
 
 /****************************************************************************
- * Name: files_initlist
+ * Name: fdlist_init
  *
  * Description:
- *   Initializes the list of files for a new task
+ *   Initializes the list of file descriptors for a new task.
  *
  ****************************************************************************/
 
-void files_initlist(FAR struct filelist *list);
+void fdlist_init(FAR struct fdlist *list);
 
 /****************************************************************************
- * Name: files_dumplist
+ * Name: fdlist_dump
  *
  * Description:
- *   Dump the list of files.
+ *   Dump the list of file descriptors.
  *
  ****************************************************************************/
 
 #ifdef CONFIG_SCHED_DUMP_ON_EXIT
-void files_dumplist(FAR struct filelist *list);
+void fdlist_dump(FAR struct fdlist *list);
 #else
-#  define files_dumplist(l)
+#  define fdlist_dump(l)
 #endif
 
 /****************************************************************************
- * Name: files_putlist
+ * Name: fdlist_free
  *
  * Description:
- *   Release the list of files.
+ *   Release the list of file descriptors.
+ *
+ * Assumptions:
+ *   Called during task deletion in a safe context.
  *
  ****************************************************************************/
 
-void files_putlist(FAR struct filelist * list);
+void fdlist_free(FAR struct fdlist *list);
 
 /****************************************************************************
- * Name: files_countlist
+ * Name: fdlist_count
  *
  * Description:
- *   Get file count from file list
+ *   Get file descriptor count from file list.
+ *
+ * Input Parameters:
+ *   list - Pointer to the file descriptor list structure.
  *
  * Returned Value:
- *   file count of file list
+ *   file descriptor count of file list.
  *
  ****************************************************************************/
 
-int files_countlist(FAR struct filelist *list);
+int fdlist_count(FAR struct fdlist *list);
 
 /****************************************************************************
- * Name: files_duplist
+ * Name: fdlist_copy
  *
  * Description:
- *   Duplicate parent task's file descriptors.
+ *   Copy parent task's file descriptors to child task.
  *
  * Returned Value:
  *   Zero (OK) is returned on success; a negated errno value is returned on
  *   any failure.
  *
  ****************************************************************************/
 
-int files_duplist(FAR struct filelist *plist, FAR struct filelist *clist,
-                  FAR const posix_spawn_file_actions_t *actions,
-                  bool cloexec);
+int fdlist_copy(FAR struct fdlist *plist, FAR struct fdlist *clist,
+                FAR const posix_spawn_file_actions_t *actions,
+                bool cloexec);
+
+/****************************************************************************
+ * Name: fdlist_get2
+ *
+ * Description:
+ *   Given a file descriptor, return the corresponding instance of struct
+ *   fd and filep.
+ *
+ * Input Parameters:
+ *   list - Pointer to the file descriptor list structure.
+ *   fd    - The file descriptor
+ *   filep - The location to return the struct file instance
+ *   fdp   - The location to return the struct fd instance
+ *
+ * Returned Value:
+ *   Return the pointer to file structure of list[fd] when list[fd].f_file
+ *   is valid, othersize, a null pointer is returned.
+ *
+ ****************************************************************************/
+
+int fdlist_get2(FAR struct fdlist *list, int fd,
+                FAR struct file **filep, FAR struct fd **fdp);
 
 /****************************************************************************
- * Name: files_fget
+ * Name: fdlist_get
  *
  * Description:
- *   Get the instance of struct file from file list by file descriptor.
+ *   Given a file descriptor, return the corresponding instance of struct
+ *   filep.
  *
  * Input Parameters:
- *   list - The list of files for a task.
- *   fd   - A valid descriptor between 0 and files_countlist(list).
+ *   list  - Pointer to the file descriptor list structure.
+ *   fd    - The file descriptor
+ *   filep - The location to return the struct file instance
+ *
+ * Returned Value:
+ *   Return the pointer to file structure of list[fd] when list[fd].f_file
+ *   is valid, othersize, a null pointer is returned.
+ *
+ ****************************************************************************/
+
+#define fdlist_get(list, fd, filep) fdlist_get2(list, fd, filep, NULL)
+
+/****************************************************************************
+ * Name: fdlist_dupfile
+ *
+ * Description:
+ *   Allocate a struct fd instance and bind it to the corresponding file
+ *   handle.
  *
  * Returned Value:
- *   Pointer to file structure of list[fd].
+ *   Returns the file descriptor == index into the files array on success;
+ *   a negated errno value is returned on any failure.
  *
  ****************************************************************************/
 
-FAR struct file *files_fget(FAR struct filelist *list, int fd);
+int fdlist_dupfile(FAR struct fdlist *list, int oflags, int minfd,
+                   FAR struct file *filep);
 
 /****************************************************************************
- * Name: file_allocate_from_tcb
+ * Name: fdlist_allocate
  *
  * Description:
- *   Allocate a struct files instance and associate it with an inode
- *   instance.
+ *   Allocate a struct fd instance and associate it with an empty file
+ *   instance. The difference between this function and
+ *   file_allocate_from_inode is that this function is only used for
+ *   placeholder purposes. Later, the caller will initialize the file entity
+ *   through the returned filep.
+ *
+ *   The fd allocated by this function can be released using fdlist_close.
  *
  * Returned Value:
- *     Returns the file descriptor == index into the files array on success;
- *     a negated errno value is returned on any failure.
+ *   Returns the file descriptor == index into the files array on success;
+ *   a negated errno value is returned on any failure.
  *
  ****************************************************************************/
 
-int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR struct inode *inode,
-                           int oflags, off_t pos, FAR void *priv, int minfd,
-                           bool addref);
+int fdlist_allocate(FAR struct fdlist *list, int oflags,
+                   int minfd, FAR struct file **filep);

Review Comment:
   Done~



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to