xiaoxiang781216 commented on code in PR #16326:
URL: https://github.com/apache/nuttx/pull/16326#discussion_r2076666136


##########
include/nuttx/fs/fs.h:
##########
@@ -462,6 +462,7 @@ struct file
   int               f_oflags;   /* Open mode flags */
 #ifdef CONFIG_FS_REFCOUNT
   atomic_t          f_refs;     /* Reference count */
+  sem_t             f_closem;   /* Free: file is fully closed */

Review Comment:
   > Yes this would be better. However, it is not clear to me which 
implementation is correct. POSIX says
   > 
   > `The dup2() function shall cause the file descriptor fildes2 to refer to 
the same open file description as the file descriptor fildes and to share any 
locks, and shall return fildes2.`
   > 
   > NuttX dup2/3 uses two file structs for oldfd and newfd, so they point to 
different file structs and do not share file status or offset.
   > 
   > Linux does this differently, dup2/3 makes filep2 = filep1, and when 
accessing fd1 and fd2 the file status and position change for both descriptors 
(as they are the same file struct).
   > 
   > Which is correct ? The POSIX spec is ambiguous in this respect.
   
   Linux implementation is correct, since POSIX spec explicitly state that:
   
   1. offset and lock state should be shared after dup
   2. open flag should be separated after dup
   
   > I think our implementation is wrong but changing this functionality can 
create a MASSIVE regression for people who depend on our (wrong) implementation 
of dup2/3.
   
   It's always the top priority for NuttX to strictly compliant with POSIX 
standard.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to