Donny9 opened a new pull request, #16499:
URL: https://github.com/apache/nuttx/pull/16499

   ## Summary
   
   This PR is a rework of the NuttX file descriptor implementation. The
   goal is two-fold:
   
   Improve POSIX compliance. The old implementation tied file description
   to inode only, not the file struct. POSIX however dictates otherwise.
   Fix a bug with descriptor duplication (dup2() and dup3()). There is
   an existing race condition with this POSIX API that currently results
   in a kernel side crash.
   The crash occurs when a partially open / closed file descriptor is
   duplicated. The reason for the crash is that even if the descriptor is
   closed, the file might still be in use by the kernel (due to e.g. ongoing
   write to file). The open file data is changed by file_dup3() and this
   causes a crash in the device / drivers themselves as they lose access to
   the inode and private data.
   
   The fix is done by separating struct file into file and file descriptor
   structs. The file struct can live on even if the descriptor is closed,
   fixing the crash. This also fixes the POSIX issue, as two descriptors
   can now point to the same file.
   
   The implementation of this PR is based on the modifications made in 
https://github.com/apache/nuttx/pull/16361. 
   Thank you @pussuw 
   
   ## Impact
   
   * Remove the FS_REFCOUNT config because reference counting is a very 
necessary feature that is required in many scenarios to ensure stability.
   * Rename the functions fs_getfilep, fs_putfilep, and fs_reffilep to 
file_get, file_put, and file_ref respectively, to unify the naming convention 
to file_xxx, such as file_open, file_ioctl, etc.
   * Introduce a new fd (file descriptor) structure. If multiple file 
descriptors (fds) are in a dup relationship, they can share the same file 
entity to implement the dup functionality.
   * Modify the functions nx_close_from_tcb, nx_open_from_tcb, 
nx_dup2_from_tcb, and nx_dup3_from_tcb to fdlist_open, fdlist_close, 
fdlist_dup2, and fdlist_dup3 respectively, to uniformly operate on file 
descriptors using fdlist.
   
   ## Testing
   
   monkey(24 hours) and CI
   
   
   


-- 
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