This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 3a1dbb62655 fcntl: give O_RSYNC its own flag bit
3a1dbb62655 is described below

commit 3a1dbb62655edbd4fc556cb33df4325abc21ddc7
Author: anpeiyun <[email protected]>
AuthorDate: Thu Nov 26 19:27:45 2026 +0800

    fcntl: give O_RSYNC its own flag bit
    
    O_RSYNC needs a non-zero value so open() stores it and fcntl() can report
    it back, but aliasing it to O_SYNC makes aio_fsync(O_RSYNC)
    indistinguishable from the valid aio_fsync(O_SYNC) call, so the EINVAL
    POSIX requires for an op that is neither O_DSYNC nor O_SYNC can never be
    produced.  Give O_RSYNC bit 23 instead; with a 16-bit int there is no spare
    bit, so it keeps the O_SYNC alias there.
    
    Add FRSYNC to FFCNTL so F_SETFL can still set it (bits outside FFCNTL are
    ignored), and map it in the sim hostfs, whose O_RSYNC equals its O_SYNC.
    
    Signed-off-by: anpeiyun <[email protected]>
---
 arch/sim/src/sim/posix/sim_hostfs.c |  7 +++++++
 include/fcntl.h                     | 11 ++++++++---
 include/nuttx/fs/hostfs.h           |  3 ++-
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/sim/src/sim/posix/sim_hostfs.c 
b/arch/sim/src/sim/posix/sim_hostfs.c
index dcfbcf10903..27437ad3285 100644
--- a/arch/sim/src/sim/posix/sim_hostfs.c
+++ b/arch/sim/src/sim/posix/sim_hostfs.c
@@ -102,6 +102,13 @@ static int host_oflags_convert(int flags)
       mapflags |= O_SYNC;
     }
 
+#ifdef O_RSYNC
+  if (flags & NUTTX_O_RSYNC)
+    {
+      mapflags |= O_RSYNC;
+    }
+#endif
+
 #ifdef O_DIRECT
   if (flags & NUTTX_O_DIRECT)
     {
diff --git a/include/fcntl.h b/include/fcntl.h
index 58ac177e234..164466210f8 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -88,7 +88,11 @@
 
 #define O_NDELAY     O_NONBLOCK                  /* Synonym for O_NONBLOCK */
 #define O_SYNC       (__O_SYNC | O_DSYNC)        /* Synchronize output on 
write */
-#define O_RSYNC      O_SYNC                      /* Synchronize input on read 
*/
+#if UINT_MAX > 0xffff
+#define O_RSYNC      (1U << 23)                  /* Synchronize input on read 
*/
+#else
+#define O_RSYNC      O_SYNC                      /* Not supported: no spare 
bit */
+#endif
 #ifndef NUTTX_NO_EXTENSIONS                      /* See nuttx/compiler.h */
 #define O_BINARY     0                           /* Open the file in binary 
mode */
 #endif
@@ -98,7 +102,7 @@
  */
 
 #if UINT_MAX > 0xffff
-#  define _O_MAXBIT   22
+#  define _O_MAXBIT   23
 #else
 #  define _O_MAXBIT   15
 #endif
@@ -109,11 +113,12 @@
 #define FNONBLOCK   O_NONBLOCK       /* Don't wait for data */
 #define FAPPEND     O_APPEND         /* Keep contents, append to end */
 #define FSYNC       O_SYNC           /* Synchronize output on write */
+#define FRSYNC      O_RSYNC          /* Synchronize input on read */
 #define FASYNC      O_ASYNC          /* No counterpart in NuttX */
 
 /* FFCNTL is all the bits that may be set via fcntl. */
 
-#define FFCNTL      (FNONBLOCK | FNDELAY | FAPPEND | FSYNC | FASYNC)
+#define FFCNTL      (FNONBLOCK | FNDELAY | FAPPEND | FSYNC | FASYNC | FRSYNC)
 
 /* fcntl() commands */
 
diff --git a/include/nuttx/fs/hostfs.h b/include/nuttx/fs/hostfs.h
index 95839f6e633..50f9af9d5b8 100644
--- a/include/nuttx/fs/hostfs.h
+++ b/include/nuttx/fs/hostfs.h
@@ -98,10 +98,11 @@
 #define NUTTX___O_SYNC          (1 << 20)      /* Synchronize file 
(data+metadata) */
 #define NUTTX_O_PATH            (1 << 21)      /* Obtain a path-only fd (no 
I/O) */
 #define NUTTX___O_TMPFILE       (1 << 22)      /* Create an unnamed temporary 
file */
+#define NUTTX___O_RSYNC         (1 << 23)      /* Synchronize input on read */
 
 #define NUTTX_O_NDELAY          NUTTX_O_NONBLOCK                        /* 
Synonym for O_NONBLOCK */
 #define NUTTX_O_SYNC            (NUTTX___O_SYNC | NUTTX_O_DSYNC)        /* 
Synchronize output on write */
-#define NUTTX_O_RSYNC           NUTTX_O_SYNC                            /* 
Synchronize input on read */
+#define NUTTX_O_RSYNC           NUTTX___O_RSYNC                         /* 
Synchronize input on read */
 #define NUTTX_O_TMPFILE         (NUTTX___O_TMPFILE | NUTTX_O_DIRECTORY) /* 
Create a temporary file */
 #define NUTTX_O_BINARY          0                                       /* 
Open the file in binary mode */
 

Reply via email to