This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch releases/13.0 in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a0357b3a6537946d9d7e9a40ff3df405efe3af35 Author: Xiang Xiao <[email protected]> AuthorDate: Wed Jun 24 17:53:33 2026 +0800 !include/fcntl.h: align open flags with Linux values Align the NuttX open(2) flag constants with the Linux asm-generic values so that the FUSE wire protocol and other cross-platform interfaces work without conversion. All code that used '(flags & O_RDONLY)' as a bitmask check (always 0 now that O_RDONLY=0) has been updated to use '(flags & O_ACCMODE)' comparisons. The NUTTX_O_* constants in include/nuttx/fs/hostfs.h are updated to match, and the sim hostfs open flag mapping is fixed. Signed-off-by: Xiang Xiao <[email protected]> --- arch/arm/src/common/arm_hostfs.c | 2 +- arch/arm/src/cxd56xx/cxd56_hostif.c | 15 ++-- arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c | 2 +- arch/arm/src/cxd56xx/cxd56_usbdev.c | 2 +- arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c | 2 +- arch/arm64/src/common/arm64_fpu.c | 2 +- arch/arm64/src/common/arm64_hostfs.c | 2 +- arch/risc-v/src/common/riscv_hostfs.c | 2 +- arch/sim/src/sim/posix/sim_hostfs.c | 22 +++--- arch/sim/src/sim/win/sim_hostfs.c | 22 +++--- arch/x86_64/src/common/x86_64_acpi_procfs.c | 2 +- .../rddrone-bms772/src/s32k1xx_nrstcheck_procfs.c | 2 +- drivers/bch/bchlib_setup.c | 2 +- drivers/can/can.c | 2 +- drivers/clk/clk.c | 2 +- drivers/mmcsd/mmcsd_procfs.c | 2 +- drivers/mtd/mtd_partition.c | 2 +- drivers/pipes/pipe_common.c | 31 +++++---- drivers/power/pm/pm_procfs.c | 2 +- drivers/sensors/sensor.c | 8 +-- drivers/sensors/sensor_rpmsg.c | 8 +-- fs/aio/aio_write.c | 2 +- fs/binfs/fs_binfs.c | 2 +- fs/cromfs/fs_cromfs.c | 2 +- fs/fat/fs_fat32.c | 10 +-- fs/hostfs/hostfs.c | 4 +- fs/inode/fs_inode.c | 25 +++---- fs/littlefs/lfs_vfs.c | 17 +++-- fs/mmap/fs_mmap.c | 6 +- fs/mount/fs_procfs_mount.c | 2 +- fs/nfs/nfs_vfsops.c | 4 +- fs/nxffs/nxffs_open.c | 9 ++- fs/nxffs/nxffs_read.c | 2 +- fs/nxffs/nxffs_truncate.c | 2 +- fs/nxffs/nxffs_write.c | 2 +- fs/procfs/fs_procfscpuload.c | 2 +- fs/procfs/fs_procfscritmon.c | 2 +- fs/procfs/fs_procfsfdt.c | 2 +- fs/procfs/fs_procfsiobinfo.c | 2 +- fs/procfs/fs_procfstcbinfo.c | 2 +- fs/procfs/fs_procfsuptime.c | 2 +- fs/procfs/fs_procfsversion.c | 2 +- fs/procfs/fs_skeleton.c | 4 +- fs/romfs/fs_romfs.c | 2 +- fs/rpmsgfs/rpmsgfs.c | 4 +- fs/shm/shm_open.c | 4 +- fs/smartfs/smartfs_procfs.c | 4 +- fs/smartfs/smartfs_smart.c | 4 +- fs/spiffs/src/spiffs_vfs.c | 4 +- fs/spiffs/src/spiffs_volume.c | 2 +- fs/tmpfs/fs_tmpfs.c | 2 +- fs/vfs/fs_inotify.c | 2 +- fs/vfs/fs_open.c | 2 +- fs/vfs/fs_read.c | 2 +- fs/vfs/fs_truncate.c | 2 +- fs/vfs/fs_write.c | 2 +- graphics/nxterm/nxterm_driver.c | 2 +- include/fcntl.h | 81 +++++++++++----------- include/nuttx/fs/hostfs.h | 42 +++++++---- include/sys/mount.h | 20 +++--- libs/libc/stdio/lib_fclose.c | 2 +- libs/libc/stdio/lib_fmemopen.c | 4 +- libs/libc/stdio/lib_libfflush.c | 2 +- libs/libc/stdio/lib_libflushall.c | 4 +- libs/libc/stdio/lib_libfread_unlocked.c | 2 +- libs/libc/stdio/lib_libfwrite.c | 2 +- libs/libc/stdio/lib_ungetc.c | 2 +- libs/libc/stdio/lib_ungetwc.c | 2 +- libs/libc/stdio/lib_wrflush_unlocked.c | 2 +- net/procfs/net_procfs.c | 4 +- net/procfs/net_procfs_route.c | 2 +- sched/irq/irq_procfs.c | 2 +- sched/module/mod_procfs.c | 2 +- sched/mqueue/mq_receive.c | 2 +- sched/mqueue/mq_send.c | 2 +- 75 files changed, 243 insertions(+), 217 deletions(-) diff --git a/arch/arm/src/common/arm_hostfs.c b/arch/arm/src/common/arm_hostfs.c index b0bede45590..9f3d829c365 100644 --- a/arch/arm/src/common/arm_hostfs.c +++ b/arch/arm/src/common/arm_hostfs.c @@ -78,7 +78,7 @@ static ssize_t host_flen(long fd) static int host_flags_to_mode(int flags) { - static const int modemasks = O_RDONLY | O_WRONLY | O_TEXT | O_RDWR | + static const int modemasks = O_ACCMODE | O_TEXT | O_CREAT | O_TRUNC | O_APPEND; static const int modeflags[] = { diff --git a/arch/arm/src/cxd56xx/cxd56_hostif.c b/arch/arm/src/cxd56xx/cxd56_hostif.c index 07e24680675..4ecbfbf9e39 100644 --- a/arch/arm/src/cxd56xx/cxd56_hostif.c +++ b/arch/arm/src/cxd56xx/cxd56_hostif.c @@ -209,20 +209,19 @@ static int hif_open(struct file *filep) /* Check parameters */ - if ((filep->f_oflags & O_WRONLY) != 0 && - (filep->f_oflags & O_RDONLY) != 0) + if ((filep->f_oflags & O_ACCMODE) == O_RDWR) { return -EACCES; } - if ((filep->f_oflags & O_RDONLY) && - ((priv->flags & HOSTIF_BUFF_ATTR_READ) == 0)) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY && + (priv->flags & HOSTIF_BUFF_ATTR_READ) == 0) { return -EINVAL; } - if ((filep->f_oflags & O_WRONLY) && - ((priv->flags & HOSTIF_BUFF_ATTR_READ) != 0)) + if ((filep->f_oflags & O_ACCMODE) != O_RDONLY && + (priv->flags & HOSTIF_BUFF_ATTR_READ) != 0) { return -EINVAL; } @@ -292,7 +291,7 @@ static ssize_t hif_read(struct file *filep, char *buffer, size_t len) DEBUGASSERT(buffer); - if ((filep->f_oflags & O_RDONLY) == 0) + if ((filep->f_oflags & O_ACCMODE) == O_WRONLY) { return -EACCES; } @@ -323,7 +322,7 @@ static ssize_t hif_write(struct file *filep, DEBUGASSERT(buffer); - if ((filep->f_oflags & O_WRONLY) == 0) + if ((filep->f_oflags & O_ACCMODE) == O_RDONLY) { return -EACCES; } diff --git a/arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c b/arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c index 705c57d22dd..9917a77486c 100644 --- a/arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c +++ b/arch/arm/src/cxd56xx/cxd56_powermgr_procfs.c @@ -488,7 +488,7 @@ static int cxd56_powermgr_procfs_open(struct file *filep, * REVISIT: Write-able proc files could be quite useful. */ - if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)) + if ((oflags & O_ACCMODE) != O_RDONLY) { pmerr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/arch/arm/src/cxd56xx/cxd56_usbdev.c b/arch/arm/src/cxd56xx/cxd56_usbdev.c index 6c59a877e8c..faeb0fcfefd 100644 --- a/arch/arm/src/cxd56xx/cxd56_usbdev.c +++ b/arch/arm/src/cxd56xx/cxd56_usbdev.c @@ -3388,7 +3388,7 @@ static int cxd56_usbdev_open(struct file *filep, const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)) + if ((oflags & O_ACCMODE) != O_RDONLY) { uerr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c b/arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c index 0c0e8206eb8..93e3ca5488d 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c +++ b/arch/arm/src/s32k1xx/s32k1xx_resetcause_procfs.c @@ -128,7 +128,7 @@ static int s32k1xx_resetcause_procfs_open(struct file *filep, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/arch/arm64/src/common/arm64_fpu.c b/arch/arm64/src/common/arm64_fpu.c index 5a30db39a5b..d072d21dc25 100644 --- a/arch/arm64/src/common/arm64_fpu.c +++ b/arch/arm64/src/common/arm64_fpu.c @@ -166,7 +166,7 @@ static int arm64_fpu_procfs_open(struct file *filep, const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)) + if ((oflags & O_ACCMODE) != O_RDONLY) { uerr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/arch/arm64/src/common/arm64_hostfs.c b/arch/arm64/src/common/arm64_hostfs.c index 75ee7e85936..0bcbef7b098 100644 --- a/arch/arm64/src/common/arm64_hostfs.c +++ b/arch/arm64/src/common/arm64_hostfs.c @@ -78,7 +78,7 @@ static ssize_t host_flen(long fd) static int host_flags_to_mode(int flags) { - static const int modemasks = O_RDONLY | O_WRONLY | O_TEXT | O_RDWR | + static const int modemasks = O_ACCMODE | O_TEXT | O_CREAT | O_TRUNC | O_APPEND; static const int modeflags[] = { diff --git a/arch/risc-v/src/common/riscv_hostfs.c b/arch/risc-v/src/common/riscv_hostfs.c index aa1409d6a05..a22ea85440f 100644 --- a/arch/risc-v/src/common/riscv_hostfs.c +++ b/arch/risc-v/src/common/riscv_hostfs.c @@ -78,7 +78,7 @@ static ssize_t host_flen(long fd) static int host_flags_to_mode(int flags) { - static const int modemasks = O_RDONLY | O_WRONLY | O_TEXT | O_RDWR | + static const int modemasks = O_ACCMODE | O_TEXT | O_CREAT | O_TRUNC | O_APPEND; static const int modeflags[] = { diff --git a/arch/sim/src/sim/posix/sim_hostfs.c b/arch/sim/src/sim/posix/sim_hostfs.c index 8597b036f1c..f582a2bbeca 100644 --- a/arch/sim/src/sim/posix/sim_hostfs.c +++ b/arch/sim/src/sim/posix/sim_hostfs.c @@ -134,17 +134,19 @@ int host_open(const char *pathname, int flags, int mode) /* Perform flag mapping */ - if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR) + switch (flags & NUTTX_O_ACCMODE) { - mapflags = O_RDWR; - } - else if (flags & NUTTX_O_RDONLY) - { - mapflags = O_RDONLY; - } - else if (flags & NUTTX_O_WRONLY) - { - mapflags = O_WRONLY; + case NUTTX_O_RDONLY: + mapflags = O_RDONLY; + break; + + case NUTTX_O_WRONLY: + mapflags = O_WRONLY; + break; + + case NUTTX_O_RDWR: + mapflags = O_RDWR; + break; } if (flags & NUTTX_O_APPEND) diff --git a/arch/sim/src/sim/win/sim_hostfs.c b/arch/sim/src/sim/win/sim_hostfs.c index 9fb42fbe5a0..5cd0ad1ddf5 100644 --- a/arch/sim/src/sim/win/sim_hostfs.c +++ b/arch/sim/src/sim/win/sim_hostfs.c @@ -89,17 +89,19 @@ int host_open(const char *pathname, int flags, int mode) /* Perform flag mapping */ - if ((flags & NUTTX_O_RDWR) == NUTTX_O_RDWR) + switch (flags & NUTTX_O_ACCMODE) { - mapflags = O_RDWR; - } - else if (flags & NUTTX_O_RDONLY) - { - mapflags = O_RDONLY; - } - else if (flags & NUTTX_O_WRONLY) - { - mapflags = O_WRONLY; + case NUTTX_O_RDONLY: + mapflags = O_RDONLY; + break; + + case NUTTX_O_WRONLY: + mapflags = O_WRONLY; + break; + + case NUTTX_O_RDWR: + mapflags = O_RDWR; + break; } if (flags & NUTTX_O_APPEND) diff --git a/arch/x86_64/src/common/x86_64_acpi_procfs.c b/arch/x86_64/src/common/x86_64_acpi_procfs.c index 6aa96343269..5239e6e469b 100644 --- a/arch/x86_64/src/common/x86_64_acpi_procfs.c +++ b/arch/x86_64/src/common/x86_64_acpi_procfs.c @@ -144,7 +144,7 @@ static int acpi_open(struct file *filep, const char *relpath, * is not permitted. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/boards/arm/s32k1xx/rddrone-bms772/src/s32k1xx_nrstcheck_procfs.c b/boards/arm/s32k1xx/rddrone-bms772/src/s32k1xx_nrstcheck_procfs.c index 13373fc362a..da3bae73e31 100644 --- a/boards/arm/s32k1xx/rddrone-bms772/src/s32k1xx_nrstcheck_procfs.c +++ b/boards/arm/s32k1xx/rddrone-bms772/src/s32k1xx_nrstcheck_procfs.c @@ -134,7 +134,7 @@ static int s32k1xx_nrstcheck_procfs_open(struct file *filep, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/drivers/bch/bchlib_setup.c b/drivers/bch/bchlib_setup.c index 710084c73a7..7f17fe3e11e 100644 --- a/drivers/bch/bchlib_setup.c +++ b/drivers/bch/bchlib_setup.c @@ -59,7 +59,7 @@ int bchlib_setup(FAR const char *blkdev, int oflags, FAR void **handle) { FAR struct bchlib_s *bch; struct geometry geo; - bool readonly = (oflags & O_WRONLY) == 0; + bool readonly = (oflags & O_ACCMODE) == O_RDONLY; int ret; DEBUGASSERT(blkdev); diff --git a/drivers/can/can.c b/drivers/can/can.c index ccb84480848..987100f60c5 100644 --- a/drivers/can/can.c +++ b/drivers/can/can.c @@ -276,7 +276,7 @@ static int can_open(FAR struct file *filep) reader = init_can_reader(filep); - if ((filep->f_oflags & O_RDONLY) != 0) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY) { list_add_head(&dev->cd_readers, (FAR struct list_node *)reader); diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 21f95707650..288b14491b3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -141,7 +141,7 @@ static int clk_procfs_open(FAR struct file *filep, FAR const char *relpath, { FAR struct procfs_file_s *priv; - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { return -EACCES; } diff --git a/drivers/mmcsd/mmcsd_procfs.c b/drivers/mmcsd/mmcsd_procfs.c index 034c24d7a12..2ea4ff7879a 100644 --- a/drivers/mmcsd/mmcsd_procfs.c +++ b/drivers/mmcsd/mmcsd_procfs.c @@ -180,7 +180,7 @@ static int mmcsd_open(FAR struct file *filep, FAR const char *relpath, * is not permitted. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { finfo("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/drivers/mtd/mtd_partition.c b/drivers/mtd/mtd_partition.c index bd271949d8a..b2fee01002b 100644 --- a/drivers/mtd/mtd_partition.c +++ b/drivers/mtd/mtd_partition.c @@ -564,7 +564,7 @@ static int part_procfs_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index e0a4fda89a4..1329f43139b 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -169,7 +169,7 @@ int pipecommon_open(FAR struct file *filep) * instance. */ - if ((filep->f_oflags & O_WRONLY) != 0) + if ((filep->f_oflags & O_ACCMODE) != O_RDONLY) { dev->d_nwriters++; @@ -184,10 +184,10 @@ int pipecommon_open(FAR struct file *filep) } } - while ((filep->f_oflags & O_NONBLOCK) == 0 && /* Blocking */ - (filep->f_oflags & O_RDWR) == O_WRONLY && /* Write-only */ - dev->d_nreaders < 1 && /* No readers on the pipe */ - circbuf_is_empty(&dev->d_buffer)) /* Buffer is empty */ + while ((filep->f_oflags & O_NONBLOCK) == 0 && /* Blocking */ + (filep->f_oflags & O_ACCMODE) == O_WRONLY && /* Write-only */ + dev->d_nreaders < 1 && /* No readers on the pipe */ + circbuf_is_empty(&dev->d_buffer)) /* Buffer is empty */ { /* If opened for write-only, then wait for at least one reader * on the pipe. @@ -233,7 +233,7 @@ int pipecommon_open(FAR struct file *filep) * instance. */ - if ((filep->f_oflags & O_RDONLY) != 0) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY) { dev->d_nreaders++; @@ -248,10 +248,10 @@ int pipecommon_open(FAR struct file *filep) } } - while ((filep->f_oflags & O_NONBLOCK) == 0 && /* Blocking */ - (filep->f_oflags & O_RDWR) == O_RDONLY && /* Read-only */ - dev->d_nwriters < 1 && /* No writers on the pipe */ - circbuf_is_empty(&dev->d_buffer)) /* Buffer is empty */ + while ((filep->f_oflags & O_NONBLOCK) == 0 && /* Blocking */ + (filep->f_oflags & O_ACCMODE) == O_RDONLY && /* Read-only */ + dev->d_nwriters < 1 && /* No writers on the pipe */ + circbuf_is_empty(&dev->d_buffer)) /* Buffer is empty */ { /* If opened for read-only, then wait for either at least one writer * on the pipe. @@ -337,7 +337,7 @@ int pipecommon_close(FAR struct file *filep) * writers on the pipe instance. */ - if ((filep->f_oflags & O_WRONLY) != 0) + if ((filep->f_oflags & O_ACCMODE) != O_RDONLY) { /* If there are no longer any writers on the pipe, then notify all * of the waiting readers that they must return end-of-file. @@ -357,7 +357,7 @@ int pipecommon_close(FAR struct file *filep) * instance. */ - if ((filep->f_oflags & O_RDONLY) != 0) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY) { if (--dev->d_nreaders <= 0) { @@ -718,15 +718,16 @@ int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds, */ eventset = 0; - if ((filep->f_oflags & O_WRONLY) && - nbytes < (dev->d_bufsize - dev->d_polloutthrd)) + if ((filep->f_oflags & O_ACCMODE) != O_RDONLY && + nbytes < dev->d_bufsize - dev->d_polloutthrd) { eventset |= POLLOUT; } /* Notify the POLLIN event if buffer used exceeds poll threshold */ - if ((filep->f_oflags & O_RDONLY) && (nbytes > dev->d_pollinthrd)) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY && + nbytes > dev->d_pollinthrd) { eventset |= POLLIN; } diff --git a/drivers/power/pm/pm_procfs.c b/drivers/power/pm/pm_procfs.c index 36b5f1095e8..15a1106db89 100644 --- a/drivers/power/pm/pm_procfs.c +++ b/drivers/power/pm/pm_procfs.c @@ -200,7 +200,7 @@ static int pm_open(FAR struct file *filep, FAR const char *relpath, * is not permitted. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index 1e5cc5e8e94..323cd8181db 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -728,7 +728,7 @@ static int sensor_open(FAR struct file *filep) * allowing for direct I/O operations. */ - if (filep->f_oflags & O_RDONLY) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY) { if (upper->state.nsubscribers == 0 && lower->ops->activate) { @@ -743,7 +743,7 @@ static int sensor_open(FAR struct file *filep) upper->state.nsubscribers++; } - if (filep->f_oflags & O_WRONLY) + if ((filep->f_oflags & O_ACCMODE) != O_RDONLY) { user->role |= SENSOR_ROLE_WR; upper->state.nadvertisers++; @@ -820,7 +820,7 @@ static int sensor_close(FAR struct file *filep) * allowing for direct I/O operations. */ - if (filep->f_oflags & O_RDONLY) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY) { upper->state.nsubscribers--; if (upper->state.nsubscribers == 0 && lower->ops->activate) @@ -829,7 +829,7 @@ static int sensor_close(FAR struct file *filep) } } - if (filep->f_oflags & O_WRONLY) + if ((filep->f_oflags & O_ACCMODE) != O_RDONLY) { upper->state.nadvertisers--; } diff --git a/drivers/sensors/sensor_rpmsg.c b/drivers/sensors/sensor_rpmsg.c index c10988f6263..5f172cf35cc 100644 --- a/drivers/sensors/sensor_rpmsg.c +++ b/drivers/sensors/sensor_rpmsg.c @@ -680,7 +680,7 @@ static int sensor_rpmsg_open(FAR struct sensor_lowerhalf_s *lower, } sensor_rpmsg_lock(dev); - if (filep->f_oflags & O_WRONLY) + if ((filep->f_oflags & O_ACCMODE) != O_RDONLY) { if (dev->nadvertisers++ == 0) { @@ -688,7 +688,7 @@ static int sensor_rpmsg_open(FAR struct sensor_lowerhalf_s *lower, } } - if (filep->f_oflags & O_RDONLY) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY) { if (dev->nsubscribers++ == 0) { @@ -722,7 +722,7 @@ static int sensor_rpmsg_close(FAR struct sensor_lowerhalf_s *lower, } sensor_rpmsg_lock(dev); - if (filep->f_oflags & O_WRONLY) + if ((filep->f_oflags & O_ACCMODE) != O_RDONLY) { if (dev->nadvertisers == 1) { @@ -737,7 +737,7 @@ static int sensor_rpmsg_close(FAR struct sensor_lowerhalf_s *lower, dev->nadvertisers--; } - if (filep->f_oflags & O_RDONLY) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY) { if (dev->nsubscribers == 1) { diff --git a/fs/aio/aio_write.c b/fs/aio/aio_write.c index 55780b8df3d..0ba11dc357e 100644 --- a/fs/aio/aio_write.c +++ b/fs/aio/aio_write.c @@ -280,7 +280,7 @@ int aio_write(FAR struct aiocb *aiocbp) */ flags = fcntl(aiocbp->aio_fildes, F_GETFL); - if ((flags & O_WRONLY) == 0) + if ((flags & O_ACCMODE) == O_RDONLY) { aiocbp->aio_result = -EBADF; return OK; diff --git a/fs/binfs/fs_binfs.c b/fs/binfs/fs_binfs.c index f24a1297f92..f65409b4e88 100644 --- a/fs/binfs/fs_binfs.c +++ b/fs/binfs/fs_binfs.c @@ -158,7 +158,7 @@ static int binfs_open(FAR struct file *filep, FAR const char *relpath, * access is not permitted. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/cromfs/fs_cromfs.c b/fs/cromfs/fs_cromfs.c index 3eddaceeddb..c82b75a4317 100644 --- a/fs/cromfs/fs_cromfs.c +++ b/fs/cromfs/fs_cromfs.c @@ -761,7 +761,7 @@ static int cromfs_open(FAR struct file *filep, FAR const char *relpath, * access is not permitted. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index b61e1c10605..d92c066087e 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -253,7 +253,7 @@ static int fat_open(FAR struct file *filep, FAR const char *relpath, /* Check if the caller has sufficient privileges to open the file */ readonly = ((DIR_GETATTRIBUTES(direntry) & FATATTR_READONLY) != 0); - if (((oflags & O_WRONLY) != 0) && readonly) + if ((oflags & O_ACCMODE) != O_RDONLY && readonly) { ret = -EACCES; goto errout_with_lock; @@ -379,7 +379,7 @@ static int fat_open(FAR struct file *filep, FAR const char *relpath, * the file. */ - if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY)) + if ((oflags & O_APPEND) && (oflags & O_ACCMODE) != O_RDONLY) { off_t offset = fat_seek(filep, ff->ff_size, SEEK_SET); if (offset < 0) @@ -802,7 +802,7 @@ static ssize_t fat_read(FAR struct file *filep, FAR char *buffer, /* Check if the file was opened with read access */ - if ((ff->ff_oflags & O_RDONLY) == 0) + if ((ff->ff_oflags & O_ACCMODE) == O_WRONLY) { ret = -EACCES; goto errout_with_lock; @@ -1020,7 +1020,7 @@ static ssize_t fat_write(FAR struct file *filep, FAR const char *buffer, /* Check if the file was opened for write access */ - if ((ff->ff_oflags & O_WRONLY) == 0) + if ((ff->ff_oflags & O_ACCMODE) == O_RDONLY) { ret = -EACCES; goto errout_with_lock; @@ -2289,7 +2289,7 @@ static int fat_truncate(FAR struct file *filep, off_t length) /* Check if the file was opened for write access */ - if ((ff->ff_oflags & O_WRONLY) == 0) + if ((ff->ff_oflags & O_ACCMODE) == O_RDONLY) { ret = -EACCES; goto errout_with_lock; diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c index 2f7ebcb07d7..092655ef609 100644 --- a/fs/hostfs/hostfs.c +++ b/fs/hostfs/hostfs.c @@ -304,7 +304,7 @@ static int hostfs_open(FAR struct file *filep, FAR const char *relpath, * file. */ - if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY)) + if ((oflags & O_APPEND) && (oflags & O_ACCMODE) != O_RDONLY) { ret = host_lseek(hf->fd, 0, 0, SEEK_END); if (ret >= 0) @@ -516,7 +516,7 @@ static ssize_t hostfs_write(FAR struct file *filep, const char *buffer, * write flags. */ - if ((hf->oflags & O_WRONLY) == 0) + if ((hf->oflags & O_ACCMODE) == O_RDONLY) { ret = -EACCES; goto errout_with_lock; diff --git a/fs/inode/fs_inode.c b/fs/inode/fs_inode.c index e7017f91984..294f7bb791e 100644 --- a/fs/inode/fs_inode.c +++ b/fs/inode/fs_inode.c @@ -111,19 +111,20 @@ int fs_checkmode(uid_t owner, gid_t group, mode_t mode, int amode) int fs_open_amode(int oflags) { - int amode = 0; - - if ((oflags & O_RDONLY) != 0) + switch (oflags & O_ACCMODE) { - amode |= R_OK; - } + case O_RDONLY: + return R_OK; - if ((oflags & O_WRONLY) != 0) - { - amode |= W_OK; - } + case O_WRONLY: + return W_OK; + + case O_RDWR: + return R_OK | W_OK; - return amode; + default: + return 0; + } } /**************************************************************************** @@ -285,9 +286,9 @@ int inode_checkopenperm(FAR struct inode *inode, int oflags) return -ENXIO; } - if (((oflags & O_RDONLY) != 0 && + if (((oflags & O_ACCMODE) != O_WRONLY && !ops->readv && !ops->read && !ops->ioctl) || - ((oflags & O_WRONLY) != 0 && + ((oflags & O_ACCMODE) != O_RDONLY && !ops->writev && !ops->write && !ops->ioctl)) { return -EACCES; diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c index 780c0d8a10f..c7ac79da365 100644 --- a/fs/littlefs/lfs_vfs.c +++ b/fs/littlefs/lfs_vfs.c @@ -285,14 +285,19 @@ static int littlefs_convert_oflags(int oflags) { int ret = 0; - if ((oflags & O_RDONLY) != 0) + switch (oflags & O_ACCMODE) { - ret |= LFS_O_RDONLY; - } + case O_RDONLY: + ret |= LFS_O_RDONLY; + break; - if ((oflags & O_WRONLY) != 0) - { - ret |= LFS_O_WRONLY; + case O_WRONLY: + ret |= LFS_O_WRONLY; + break; + + case O_RDWR: + ret |= LFS_O_RDWR; + break; } if ((oflags & O_CREAT) != 0) diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c index b5cac9175d4..2ccc5a646d8 100644 --- a/fs/mmap/fs_mmap.c +++ b/fs/mmap/fs_mmap.c @@ -137,15 +137,15 @@ static int file_mmap_(FAR struct file *filep, FAR void *start, return -EBADF; } - if ((flags & MAP_SHARED) && - (filep->f_oflags & O_WRONLY) == 0 && (prot & PROT_WRITE)) + if ((flags & MAP_SHARED) && (prot & PROT_WRITE) && + (filep->f_oflags & O_ACCMODE) == O_RDONLY) { ferr("ERROR: Unsupported options for read-only file descriptor," "prot=%x flags=%04x\n", prot, flags); return -EACCES; } - if ((filep->f_oflags & O_RDONLY) == 0) + if ((filep->f_oflags & O_ACCMODE) == O_WRONLY) { ferr("ERROR: File descriptor does not have read permission\n"); return -EACCES; diff --git a/fs/mount/fs_procfs_mount.c b/fs/mount/fs_procfs_mount.c index 8ed3acd457c..792688f935b 100644 --- a/fs/mount/fs_procfs_mount.c +++ b/fs/mount/fs_procfs_mount.c @@ -377,7 +377,7 @@ static int mount_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/nfs/nfs_vfsops.c b/fs/nfs/nfs_vfsops.c index 1914b2d2bd9..c2b29d2fbed 100644 --- a/fs/nfs/nfs_vfsops.c +++ b/fs/nfs/nfs_vfsops.c @@ -581,7 +581,7 @@ static int nfs_fileopen(FAR struct nfsmount *nmp, FAR struct nfsnode *np, /* Check if the caller has sufficient privileges to open the file */ - if ((oflags & O_WRONLY) != 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { /* Check if anyone has privileges to write to the file -- owner, * group, or other (we are probably "other" and may still not be @@ -737,7 +737,7 @@ static int nfs_open(FAR struct file *filep, FAR const char *relpath, * the file. */ - if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY)) + if ((oflags & O_APPEND) && (oflags & O_ACCMODE) != O_RDONLY) { filep->f_pos = (off_t)np->n_size; } diff --git a/fs/nxffs/nxffs_open.c b/fs/nxffs/nxffs_open.c index c879b7e268f..fc2a8911292 100644 --- a/fs/nxffs/nxffs_open.c +++ b/fs/nxffs/nxffs_open.c @@ -706,7 +706,7 @@ static inline int nxffs_rdopen(FAR struct nxffs_volume_s *volume, * Limitation: Files cannot be open both for reading and writing. */ - if ((ofile->oflags & O_WRONLY) != 0) + if ((ofile->oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: File is open for writing\n"); ret = -ENOSYS; @@ -1013,9 +1013,8 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath, * extension is supported. */ - switch (oflags & (O_WRONLY | O_RDONLY)) + switch (oflags & O_ACCMODE) { - case 0: default: ferr("ERROR: One of O_WRONLY/O_RDONLY must be provided\n"); return -EINVAL; @@ -1028,7 +1027,7 @@ int nxffs_open(FAR struct file *filep, FAR const char *relpath, ret = nxffs_rdopen(volume, relpath, &ofile); break; - case O_WRONLY | O_RDONLY: + case O_RDWR: ferr("ERROR: O_RDWR is not supported\n"); return -ENOSYS; } @@ -1156,7 +1155,7 @@ int nxffs_close(FAR struct file *filep) /* Handle special finalization of the write operation. */ - if ((ofile->oflags & O_WRONLY) != 0) + if ((ofile->oflags & O_ACCMODE) != O_RDONLY) { ret = nxffs_wrclose(volume, (FAR struct nxffs_wrfile_s *)ofile); } diff --git a/fs/nxffs/nxffs_read.c b/fs/nxffs/nxffs_read.c index 7b6b495d8d2..721684164f4 100644 --- a/fs/nxffs/nxffs_read.c +++ b/fs/nxffs/nxffs_read.c @@ -168,7 +168,7 @@ ssize_t nxffs_read(FAR struct file *filep, FAR char *buffer, size_t buflen) /* Check if the file was opened with read access */ - if ((ofile->oflags & O_RDONLY) == 0) + if ((ofile->oflags & O_ACCMODE) == O_WRONLY) { ferr("ERROR: File not open for read access\n"); ret = -EACCES; diff --git a/fs/nxffs/nxffs_truncate.c b/fs/nxffs/nxffs_truncate.c index 1de330eac8c..e370aac8850 100644 --- a/fs/nxffs/nxffs_truncate.c +++ b/fs/nxffs/nxffs_truncate.c @@ -83,7 +83,7 @@ int nxffs_truncate(FAR struct file *filep, off_t length) /* Check if the file was opened with write access */ - if ((wrfile->ofile.oflags & O_WRONLY) == 0) + if ((wrfile->ofile.oflags & O_ACCMODE) == O_RDONLY) { ferr("ERROR: File not open for write access\n"); ret = -EACCES; diff --git a/fs/nxffs/nxffs_write.c b/fs/nxffs/nxffs_write.c index d414f897d97..10ac8245606 100644 --- a/fs/nxffs/nxffs_write.c +++ b/fs/nxffs/nxffs_write.c @@ -545,7 +545,7 @@ ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer, /* Check if the file was opened with write access */ - if ((wrfile->ofile.oflags & O_WRONLY) == 0) + if ((wrfile->ofile.oflags & O_ACCMODE) == O_RDONLY) { ferr("ERROR: File not open for write access\n"); ret = -EACCES; diff --git a/fs/procfs/fs_procfscpuload.c b/fs/procfs/fs_procfscpuload.c index 149e6e5ef09..3c19b49c4b1 100644 --- a/fs/procfs/fs_procfscpuload.c +++ b/fs/procfs/fs_procfscpuload.c @@ -138,7 +138,7 @@ static int cpuload_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/procfs/fs_procfscritmon.c b/fs/procfs/fs_procfscritmon.c index a87b2fc6a7c..599c1fcdc18 100644 --- a/fs/procfs/fs_procfscritmon.c +++ b/fs/procfs/fs_procfscritmon.c @@ -137,7 +137,7 @@ static int critmon_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/procfs/fs_procfsfdt.c b/fs/procfs/fs_procfsfdt.c index 4a7320b1353..1ec5fdb2552 100644 --- a/fs/procfs/fs_procfsfdt.c +++ b/fs/procfs/fs_procfsfdt.c @@ -119,7 +119,7 @@ static int fdt_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/procfs/fs_procfsiobinfo.c b/fs/procfs/fs_procfsiobinfo.c index b84a7dd98b3..f37841eaccc 100644 --- a/fs/procfs/fs_procfsiobinfo.c +++ b/fs/procfs/fs_procfsiobinfo.c @@ -132,7 +132,7 @@ static int iobinfo_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/procfs/fs_procfstcbinfo.c b/fs/procfs/fs_procfstcbinfo.c index 827cb328137..91010d8def4 100644 --- a/fs/procfs/fs_procfstcbinfo.c +++ b/fs/procfs/fs_procfstcbinfo.c @@ -137,7 +137,7 @@ static int tcbinfo_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/procfs/fs_procfsuptime.c b/fs/procfs/fs_procfsuptime.c index 248c8dedb9d..2237fa2b819 100644 --- a/fs/procfs/fs_procfsuptime.c +++ b/fs/procfs/fs_procfsuptime.c @@ -138,7 +138,7 @@ static int uptime_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/procfs/fs_procfsversion.c b/fs/procfs/fs_procfsversion.c index 2c08b67539f..2e673cda643 100644 --- a/fs/procfs/fs_procfsversion.c +++ b/fs/procfs/fs_procfsversion.c @@ -138,7 +138,7 @@ static int version_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/procfs/fs_skeleton.c b/fs/procfs/fs_skeleton.c index f978a1a632b..a760e13eea0 100644 --- a/fs/procfs/fs_skeleton.c +++ b/fs/procfs/fs_skeleton.c @@ -168,8 +168,8 @@ static int skel_open(FAR struct file *filep, FAR const char *relpath, * can not be permitted. */ - if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) && - (skel_procfsoperations.write == NULL)) + if ((oflags & O_ACCMODE) != O_RDONLY && + skel_procfsoperations.write == NULL) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index 64eeff65dd7..e4c98131592 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -202,7 +202,7 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath, * access is not permitted. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); ret = -EACCES; diff --git a/fs/rpmsgfs/rpmsgfs.c b/fs/rpmsgfs/rpmsgfs.c index b2267cc1118..b19d0aaa52a 100644 --- a/fs/rpmsgfs/rpmsgfs.c +++ b/fs/rpmsgfs/rpmsgfs.c @@ -341,7 +341,7 @@ static int rpmsgfs_open(FAR struct file *filep, FAR const char *relpath, * file. */ - if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY)) + if ((oflags & O_APPEND) && (oflags & O_ACCMODE) != O_RDONLY) { ret = rpmsgfs_client_lseek(fs->handle, hf->fd, 0, SEEK_END); if (ret >= 0) @@ -553,7 +553,7 @@ static ssize_t rpmsgfs_write(FAR struct file *filep, const char *buffer, * write flags. */ - if ((hf->oflags & O_WRONLY) == 0) + if ((hf->oflags & O_ACCMODE) == O_RDONLY) { ret = -EACCES; goto errout_with_lock; diff --git a/fs/shm/shm_open.c b/fs/shm/shm_open.c index 258b88f899e..dd609fc79c7 100644 --- a/fs/shm/shm_open.c +++ b/fs/shm/shm_open.c @@ -113,8 +113,8 @@ static int file_shm_open(FAR struct file *shm, FAR const char *name, } #ifdef CONFIG_PSEUDOFS_ATTRIBUTES - if (((oflags & O_WRONLY) && !(inode->i_mode & S_IWUSR)) || - ((oflags & O_RDONLY) && !(inode->i_mode & S_IRUSR)) + if (((oflags & O_ACCMODE) != O_RDONLY && !(inode->i_mode & S_IWUSR)) || + ((oflags & O_ACCMODE) != O_WRONLY && !(inode->i_mode & S_IRUSR))) { ret = -EACCES; inode_release(inode); diff --git a/fs/smartfs/smartfs_procfs.c b/fs/smartfs/smartfs_procfs.c index bdee43077e2..024c86195e5 100644 --- a/fs/smartfs/smartfs_procfs.c +++ b/fs/smartfs/smartfs_procfs.c @@ -351,8 +351,8 @@ static int smartfs_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) && - (g_smartfs_procfs_operations.write == NULL)) + if ((oflags & O_ACCMODE) != O_RDONLY && + g_smartfs_procfs_operations.write == NULL) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index 32b5843382d..d473da2eb98 100644 --- a/fs/smartfs/smartfs_smart.c +++ b/fs/smartfs/smartfs_smart.c @@ -693,7 +693,7 @@ static ssize_t smartfs_write(FAR struct file *filep, FAR const char *buffer, * write flags. */ - if ((sf->oflags & O_WRONLY) == 0) + if ((sf->oflags & O_ACCMODE) == O_RDONLY) { ret = -EACCES; goto errout_with_lock; @@ -1223,7 +1223,7 @@ static int smartfs_truncate(FAR struct file *filep, off_t length) * write flags. */ - if ((sf->oflags & O_WRONLY) == 0) + if ((sf->oflags & O_ACCMODE) == O_RDONLY) { ret = -EACCES; goto errout_with_lock; diff --git a/fs/spiffs/src/spiffs_vfs.c b/fs/spiffs/src/spiffs_vfs.c index b47bf55bd4f..4cd92948180 100644 --- a/fs/spiffs/src/spiffs_vfs.c +++ b/fs/spiffs/src/spiffs_vfs.c @@ -433,7 +433,7 @@ static int spiffs_open(FAR struct file *filep, FAR const char *relpath, */ offset = 0; - if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY)) + if ((oflags & O_APPEND) && (oflags & O_ACCMODE) != O_RDONLY) { offset = fobj->size == SPIFFS_UNDEFINED_LEN ? 0 : fobj->size; } @@ -629,7 +629,7 @@ static ssize_t spiffs_write(FAR struct file *filep, FAR const char *buffer, /* Verify that the file was opened with write access */ - if ((fobj->oflags & O_WRONLY) == 0) + if ((fobj->oflags & O_ACCMODE) == O_RDONLY) { ret = -EACCES; goto errout_with_lock; diff --git a/fs/spiffs/src/spiffs_volume.c b/fs/spiffs/src/spiffs_volume.c index 94428385cfa..c2378f2703c 100644 --- a/fs/spiffs/src/spiffs_volume.c +++ b/fs/spiffs/src/spiffs_volume.c @@ -371,7 +371,7 @@ ssize_t spiffs_fobj_read(FAR struct spiffs_s *fs, /* Make sure that read access is supported */ - if ((fobj->oflags & O_RDONLY) == 0) + if ((fobj->oflags & O_ACCMODE) == O_WRONLY) { return -EACCES; } diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 99b01d04f26..a27c4d08abc 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -1490,7 +1490,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, */ offset = 0; - if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY)) + if ((oflags & O_APPEND) && (oflags & O_ACCMODE) != O_RDONLY) { offset = tfo->tfo_size; } diff --git a/fs/vfs/fs_inotify.c b/fs/vfs/fs_inotify.c index b180770137b..0ce16aaa753 100644 --- a/fs/vfs/fs_inotify.c +++ b/fs/vfs/fs_inotify.c @@ -1349,7 +1349,7 @@ void notify_open(FAR const char *path, int oflags) void notify_close(FAR const char *path, int oflags) { - if (oflags & O_WRONLY) + if ((oflags & O_ACCMODE) != O_RDONLY) { notify_queue_path_event(path, IN_CLOSE_WRITE); } diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index 39481c5033e..b08f7909221 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -220,7 +220,7 @@ static int file_vopen(FAR struct file *filep, FAR const char *path, FS_PROFILE_STOP(start_time, g_fs_profile.total_open_time, g_fs_profile.opens); - if (ret == -EISDIR && ((oflags & O_WRONLY) == 0)) + if (ret == -EISDIR && (oflags & O_ACCMODE) == O_RDONLY) { ret = dir_allocate(filep, desc.relpath); } diff --git a/fs/vfs/fs_read.c b/fs/vfs/fs_read.c index b7dd4de875a..677a420a248 100644 --- a/fs/vfs/fs_read.c +++ b/fs/vfs/fs_read.c @@ -192,7 +192,7 @@ ssize_t file_readv(FAR struct file *filep, /* Was this file opened for read access? */ - if ((filep->f_oflags & O_RDONLY) == 0) + if ((filep->f_oflags & O_ACCMODE) == O_WRONLY) { /* No.. File is not read-able */ diff --git a/fs/vfs/fs_truncate.c b/fs/vfs/fs_truncate.c index d80a8bf3d48..63b91f6df56 100644 --- a/fs/vfs/fs_truncate.c +++ b/fs/vfs/fs_truncate.c @@ -57,7 +57,7 @@ int file_truncate(FAR struct file *filep, off_t length) /* Was this file opened for write access? */ - if ((filep->f_oflags & O_WRONLY) == 0) + if ((filep->f_oflags & O_ACCMODE) == O_RDONLY) { fwarn("WARNING: Cannot truncate a file opened read-only\n"); return -EINVAL; diff --git a/fs/vfs/fs_write.c b/fs/vfs/fs_write.c index f74708ac480..b61483e82fb 100644 --- a/fs/vfs/fs_write.c +++ b/fs/vfs/fs_write.c @@ -153,7 +153,7 @@ ssize_t file_writev(FAR struct file *filep, /* Was this file opened for write access? */ - if ((filep->f_oflags & O_WRONLY) == 0) + if ((filep->f_oflags & O_ACCMODE) == O_RDONLY) { return -EACCES; } diff --git a/graphics/nxterm/nxterm_driver.c b/graphics/nxterm/nxterm_driver.c index f0ecb91765f..08ae08dabbf 100644 --- a/graphics/nxterm/nxterm_driver.c +++ b/graphics/nxterm/nxterm_driver.c @@ -122,7 +122,7 @@ static int nxterm_open(FAR struct file *filep) /* Verify that the driver is opened for write-only access */ #ifndef CONFIG_NXTERM_NXKBDIN - if ((filep->f_oflags & O_RDONLY) != 0) + if ((filep->f_oflags & O_ACCMODE) != O_WRONLY) { gerr("ERROR: Attempted open with read access\n"); return -EACCES; diff --git a/include/fcntl.h b/include/fcntl.h index 6ccbf33893c..05f2ade7185 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -36,53 +36,56 @@ * Pre-processor Definitions ****************************************************************************/ -/* open flag settings for open() (and related APIs) */ - -#define O_RDONLY (1 << 0) /* Open for read access (only) */ -#define O_WRONLY (1 << 1) /* Open for write access (only) */ -#define O_RDWR (3 << 0) /* Open for both read & write access */ -#define O_CREAT (1 << 2) /* Create file/sem/mq object */ -#define O_EXCL (1 << 3) /* Name must not exist when opened */ -#define O_APPEND (1 << 4) /* Keep contents, append to end */ -#define O_TRUNC (1 << 5) /* Delete contents */ -#define O_NONBLOCK (1 << 6) /* Don't wait for data */ -#define O_NDELAY O_NONBLOCK /* Synonym for O_NONBLOCK */ -#define O_SYNC (1 << 7) /* Synchronize output on write */ -#define O_DSYNC O_SYNC /* Equivalent to OSYNC in NuttX */ -#define O_TEXT (1 << 8) /* Open the file in text (translated) mode. */ -#define O_DIRECT (1 << 9) /* Avoid caching, write directly to hardware */ -#define O_CLOEXEC (1 << 10) /* Close on execute */ -#define O_DIRECTORY (1 << 11) /* Must be a directory */ -#define O_NOFOLLOW (1 << 12) /* Don't follow links */ -#define O_LARGEFILE (1 << 13) /* Large File */ -#define O_RESERVE14 (1 << 14) /* reserved and used by mount flag : MS_NOSUID in mount.h */ -#define O_RESERVE15 (1 << 15) /* reserved and used by mount flag : MS_NODEV in mount.h */ -#define O_RESERVE16 (1 << 16) /* reserved and used by mount flag : MS_DIRSYNC in mount.h */ -#define O_RESERVE17 (1 << 17) /* reserved and used by mount flag : MS_REMOUNT in mount.h */ -#define O_NOATIME (1 << 18) /* Don't update the file last access time */ -#define O_RESERVE19 (1 << 19) /* reserved and used by mount flag : MS_MANDLOCK in mount.h */ -#define O_RESERVE20 (1 << 20) /* reserved and used by mount flag : MS_NOEXEC in mount.h */ - -/* Unsupported, but required open flags */ - -#define O_RSYNC O_SYNC /* Synchronize input on read */ -#define O_ACCMODE O_RDWR /* Mask for access mode */ -#define O_NOCTTY 0 /* Required by POSIX */ -#define O_BINARY 0 /* Open the file in binary (untranslated) mode. */ +/* Open flag settings for open() (and related APIs) */ + +/* The access mode flags (O_RDONLY/O_WRONLY/O_RDWR) use the same values + * as Linux (0/1/2) so that the FUSE wire protocol and other cross- + * platform interfaces work without conversion. The remaining flags + * are also aligned with Linux where possible. + */ + +#define O_RDONLY (0U << 0) /* Open for read access (only) */ +#define O_WRONLY (1U << 0) /* Open for write access (only) */ +#define O_RDWR (2U << 0) /* Open for both read & write access */ +#define O_ACCMODE (3U << 0) /* Mask for access mode */ +#define O_TEXT (1U << 5) /* Open the file in text (translated) mode. */ +#define O_CREAT (1U << 6) /* Create file/sem/mq object */ +#define O_EXCL (1U << 7) /* Name must not exist when opened */ +#define O_NOCTTY (1U << 8) /* Don't assign a controlling terminal */ +#define O_TRUNC (1U << 9) /* Delete contents */ +#define O_APPEND (1U << 10) /* Keep contents, append to end */ +#define O_NONBLOCK (1U << 11) /* Don't wait for data */ +#define O_DSYNC (1U << 12) /* Synchronize data on write */ +#define O_ASYNC (1U << 13) /* Enable signal-driven I/O */ +#define O_DIRECT (1U << 14) /* Avoid caching, write directly to hardware */ +#define O_LARGEFILE (1U << 15) /* Large File */ +#define O_DIRECTORY (1U << 16) /* Must be a directory */ +#define O_NOFOLLOW (1U << 17) /* Don't follow links */ +#define O_NOATIME (1U << 18) /* Don't update the file last access time */ +#define O_CLOEXEC (1U << 19) /* Close on execute */ +#define __O_SYNC (1U << 20) /* Synchronize file (data+metadata) */ +#define O_PATH (1U << 21) /* Obtain a path-only fd (no I/O) */ +#define __O_TMPFILE (1U << 22) /* Create an unnamed temporary file */ + +#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 */ +#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) /* Create a temporary file */ +#define O_BINARY 0 /* Open the file in binary mode */ /* This is the highest bit number used in the open flags bitset. Bits above * this bit number may be used within NuttX for other, internal purposes. */ -#define _O_MAXBIT 8 +#define _O_MAXBIT 22 /* Synonyms historically used as F_SETFL flags (BSD). */ -#define FNDELAY O_NONBLOCK /* Don't wait for data */ -#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 FASYNC 0 /* No counterpart in NuttX */ +#define FNDELAY O_NONBLOCK /* Don't wait for data */ +#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 FASYNC O_ASYNC /* No counterpart in NuttX */ /* FFCNTL is all the bits that may be set via fcntl. */ diff --git a/include/nuttx/fs/hostfs.h b/include/nuttx/fs/hostfs.h index 92c611e8b03..3f9bad7bf8e 100644 --- a/include/nuttx/fs/hostfs.h +++ b/include/nuttx/fs/hostfs.h @@ -76,20 +76,34 @@ /* These must exactly match the definitions from include/fcntl.h: */ -#define NUTTX_O_RDONLY (1 << 0) /* Open for read access (only) */ -#define NUTTX_O_WRONLY (1 << 1) /* Open for write access (only) */ -#define NUTTX_O_CREAT (1 << 2) /* Create file/sem/mq object */ -#define NUTTX_O_EXCL (1 << 3) /* Name must not exist when opened */ -#define NUTTX_O_APPEND (1 << 4) /* Keep contents, append to end */ -#define NUTTX_O_TRUNC (1 << 5) /* Delete contents */ -#define NUTTX_O_NONBLOCK (1 << 6) /* Don't wait for data */ -#define NUTTX_O_SYNC (1 << 7) /* Synchronize output on write */ -#define NUTTX_O_TEXT (1 << 8) /* Open the file in text (translated) mode. */ -#define NUTTX_O_DIRECT (1 << 9) /* Avoid caching, write directly to hardware */ -#define NUTTX_O_CLOEXEC (1 << 10) /* Close on execute */ -#define NUTTX_O_DIRECTORY (1 << 11) /* Must be a directory */ - -#define NUTTX_O_RDWR (NUTTX_O_RDONLY | NUTTX_O_WRONLY) +#define NUTTX_O_RDONLY (0 << 0) /* Open for read access (only) */ +#define NUTTX_O_WRONLY (1 << 0) /* Open for write access (only) */ +#define NUTTX_O_RDWR (2 << 0) /* Open for both read & write access */ +#define NUTTX_O_ACCMODE (3 << 0) /* Mask for access mode */ +#define NUTTX_O_TEXT (1 << 5) /* Open the file in text (translated) mode. */ +#define NUTTX_O_CREAT (1 << 6) /* Create file/sem/mq object */ +#define NUTTX_O_EXCL (1 << 7) /* Name must not exist when opened */ +#define NUTTX_O_NOCTTY (1 << 8) /* Don't assign a controlling terminal */ +#define NUTTX_O_TRUNC (1 << 9) /* Delete contents */ +#define NUTTX_O_APPEND (1 << 10) /* Keep contents, append to end */ +#define NUTTX_O_NONBLOCK (1 << 11) /* Don't wait for data */ +#define NUTTX_O_DSYNC (1 << 12) /* Synchronize data on write */ +#define NUTTX_O_ASYNC (1 << 13) /* Enable signal-driven I/O */ +#define NUTTX_O_DIRECT (1 << 14) /* Avoid caching, write directly to hardware */ +#define NUTTX_O_LARGEFILE (1 << 15) /* Large File */ +#define NUTTX_O_DIRECTORY (1 << 16) /* Must be a directory */ +#define NUTTX_O_NOFOLLOW (1 << 17) /* Don't follow links */ +#define NUTTX_O_NOATIME (1 << 18) /* Don't update the file last access time */ +#define NUTTX_O_CLOEXEC (1 << 19) /* Close on execute */ +#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_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_TMPFILE (NUTTX___O_TMPFILE | NUTTX_O_DIRECTORY) /* Create a temporary file */ +#define NUTTX_O_BINARY 0 /* Open the file in binary mode */ /* Should match definition in include/nuttx/fs/fs.h */ diff --git a/include/sys/mount.h b/include/sys/mount.h index a4e6712aad5..93dfb17249d 100644 --- a/include/sys/mount.h +++ b/include/sys/mount.h @@ -40,16 +40,16 @@ /* Mount flags */ -#define MS_RDONLY O_RDONLY /* Mount file system read-only */ -#define MS_SYNCHRONOUS O_SYNC /* Writes are synced at once */ -#define MS_NOSYMFOLLOW O_NOFOLLOW /* Do not follow symlinks */ -#define MS_NOATIME O_NOATIME /* Do not update access times. */ -#define MS_NOSUID O_RESERVE14 /* Ignore suid and sgid bits */ -#define MS_NODEV O_RESERVE15 /* Disallow access to device special files */ -#define MS_DIRSYNC O_RESERVE16 /* Directory modifications are synchronous */ -#define MS_REMOUNT O_RESERVE17 /* Alter flags of a mounted FS */ -#define MS_MANDLOCK O_RESERVE19 /* Allow mandatory locks on an FS */ -#define MS_NOEXEC O_RESERVE20 /* Disallow program execution */ +#define MS_RDONLY 0x0001 /* Mount file system read-only */ +#define MS_NOSUID 0x0002 /* Ignore suid and sgid bits */ +#define MS_NODEV 0x0004 /* Disallow access to device special files */ +#define MS_NOEXEC 0x0008 /* Disallow program execution */ +#define MS_SYNCHRONOUS 0x0010 /* Writes are synced at once */ +#define MS_REMOUNT 0x0020 /* Alter flags of a mounted FS */ +#define MS_MANDLOCK 0x0040 /* Allow mandatory locks on an FS */ +#define MS_DIRSYNC 0x0080 /* Directory modifications are synchronous */ +#define MS_NOSYMFOLLOW 0x0100 /* Do not follow symlinks */ +#define MS_NOATIME 0x0400 /* Do not update access times. */ /* Un-mount flags * diff --git a/libs/libc/stdio/lib_fclose.c b/libs/libc/stdio/lib_fclose.c index 2749faab7fa..fd8d40f8744 100644 --- a/libs/libc/stdio/lib_fclose.c +++ b/libs/libc/stdio/lib_fclose.c @@ -102,7 +102,7 @@ int fclose(FAR FILE *stream) /* If the stream was opened for writing, then flush the stream */ - if ((stream->fs_oflags & O_WRONLY) != 0) + if ((stream->fs_oflags & O_ACCMODE) != O_RDONLY) { ret = lib_fflush(stream); errcode = get_errno(); diff --git a/libs/libc/stdio/lib_fmemopen.c b/libs/libc/stdio/lib_fmemopen.c index 55663c2827e..4d9645952da 100644 --- a/libs/libc/stdio/lib_fmemopen.c +++ b/libs/libc/stdio/lib_fmemopen.c @@ -195,7 +195,7 @@ FAR FILE *fmemopen(FAR void *buf, size_t size, FAR const char *mode) * include a '+'. */ - if ((oflags & O_RDWR) != O_RDWR) + if ((oflags & O_ACCMODE) != O_RDWR) { lib_free(fmemopen_cookie); set_errno(EINVAL); @@ -245,7 +245,7 @@ FAR FILE *fmemopen(FAR void *buf, size_t size, FAR const char *mode) * by the size argument. */ - if ((oflags & O_RDWR) == O_RDONLY) + if ((oflags & O_ACCMODE) == O_RDONLY) { fmemopen_cookie->end = size; } diff --git a/libs/libc/stdio/lib_libfflush.c b/libs/libc/stdio/lib_libfflush.c index dfec66f1eb2..853a9afbfca 100644 --- a/libs/libc/stdio/lib_libfflush.c +++ b/libs/libc/stdio/lib_libfflush.c @@ -66,7 +66,7 @@ ssize_t lib_fflush_unlocked(FAR FILE *stream) /* Return EBADF if the file is not opened for writing */ - if ((stream->fs_oflags & O_WRONLY) == 0) + if ((stream->fs_oflags & O_ACCMODE) == O_RDONLY) { return -EBADF; } diff --git a/libs/libc/stdio/lib_libflushall.c b/libs/libc/stdio/lib_libflushall.c index acbd97b014d..0df7e82dafa 100644 --- a/libs/libc/stdio/lib_libflushall.c +++ b/libs/libc/stdio/lib_libflushall.c @@ -76,7 +76,7 @@ int lib_flushall_unlocked(FAR struct streamlist *list) * the pending write data in the stream. */ - if ((stream->fs_oflags & O_WRONLY) != 0) + if ((stream->fs_oflags & O_ACCMODE) != O_RDONLY) { /* Flush the writable FILE */ @@ -129,7 +129,7 @@ int lib_flushall(FAR struct streamlist *list) * the pending write data in the stream. */ - if ((stream->fs_oflags & O_WRONLY) != 0) + if ((stream->fs_oflags & O_ACCMODE) != O_RDONLY) { /* Flush the writable FILE */ diff --git a/libs/libc/stdio/lib_libfread_unlocked.c b/libs/libc/stdio/lib_libfread_unlocked.c index 645af03ebef..91c26f94a0b 100644 --- a/libs/libc/stdio/lib_libfread_unlocked.c +++ b/libs/libc/stdio/lib_libfread_unlocked.c @@ -64,7 +64,7 @@ ssize_t lib_fread_unlocked(FAR void *ptr, size_t count, FAR FILE *stream) _NX_SETERRNO(EBADF); return ERROR; } - else if ((stream->fs_oflags & O_RDONLY) == 0) + else if ((stream->fs_oflags & O_ACCMODE) == O_WRONLY) { stream->fs_flags |= __FS_FLAG_ERROR; _NX_SETERRNO(EBADF); diff --git a/libs/libc/stdio/lib_libfwrite.c b/libs/libc/stdio/lib_libfwrite.c index 07668359682..51523dc40e4 100644 --- a/libs/libc/stdio/lib_libfwrite.c +++ b/libs/libc/stdio/lib_libfwrite.c @@ -64,7 +64,7 @@ ssize_t lib_fwrite_unlocked(FAR const void *ptr, size_t count, /* Check if write access is permitted */ - if ((stream->fs_oflags & O_WRONLY) == 0) + if ((stream->fs_oflags & O_ACCMODE) == O_RDONLY) { set_errno(EBADF); goto errout; diff --git a/libs/libc/stdio/lib_ungetc.c b/libs/libc/stdio/lib_ungetc.c index 3853a9b208c..d352e9224cb 100644 --- a/libs/libc/stdio/lib_ungetc.c +++ b/libs/libc/stdio/lib_ungetc.c @@ -54,7 +54,7 @@ int ungetc(int c, FAR FILE *stream) /* Stream must be open for read access */ - if ((stream->fs_oflags & O_RDONLY) == 0) + if ((stream->fs_oflags & O_ACCMODE) == O_WRONLY) { return EOF; } diff --git a/libs/libc/stdio/lib_ungetwc.c b/libs/libc/stdio/lib_ungetwc.c index a1f75c132fa..648f654c6f4 100644 --- a/libs/libc/stdio/lib_ungetwc.c +++ b/libs/libc/stdio/lib_ungetwc.c @@ -64,7 +64,7 @@ wint_t ungetwc_unlocked(wint_t wc, FAR FILE *f) /* Stream must be open for read access */ - if ((f->fs_oflags & O_RDONLY) == 0) + if ((f->fs_oflags & O_ACCMODE) == O_WRONLY) { return WEOF; } diff --git a/libs/libc/stdio/lib_wrflush_unlocked.c b/libs/libc/stdio/lib_wrflush_unlocked.c index e10b29b73e2..c875edc4824 100644 --- a/libs/libc/stdio/lib_wrflush_unlocked.c +++ b/libs/libc/stdio/lib_wrflush_unlocked.c @@ -70,7 +70,7 @@ int lib_wrflush_unlocked(FAR FILE *stream) * that case. */ - if ((stream->fs_oflags & O_WRONLY) == 0) + if ((stream->fs_oflags & O_ACCMODE) == O_RDONLY) { /* Report that the success was successful if we attempt to flush a * read-only stream. diff --git a/net/procfs/net_procfs.c b/net/procfs/net_procfs.c index 6825552be89..a05fd0c6dcb 100644 --- a/net/procfs/net_procfs.c +++ b/net/procfs/net_procfs.c @@ -204,8 +204,8 @@ static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) && - (g_net_operations.write == NULL)) + if ((oflags & O_ACCMODE) != O_RDONLY && + g_net_operations.write == NULL) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/net/procfs/net_procfs_route.c b/net/procfs/net_procfs_route.c index a03196471dc..e9d7dd724b5 100644 --- a/net/procfs/net_procfs_route.c +++ b/net/procfs/net_procfs_route.c @@ -445,7 +445,7 @@ static int route_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/sched/irq/irq_procfs.c b/sched/irq/irq_procfs.c index a260bb0e8b3..89a5b03893a 100644 --- a/sched/irq/irq_procfs.c +++ b/sched/irq/irq_procfs.c @@ -274,7 +274,7 @@ static int irq_open(FAR struct file *filep, FAR const char *relpath, * is not permitted. */ - if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/sched/module/mod_procfs.c b/sched/module/mod_procfs.c index fcc6b061a89..60491c1975d 100644 --- a/sched/module/mod_procfs.c +++ b/sched/module/mod_procfs.c @@ -171,7 +171,7 @@ static int modprocfs_open(FAR struct file *filep, FAR const char *relpath, * REVISIT: Write-able proc files could be quite useful. */ - if (((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)) + if ((oflags & O_ACCMODE) != O_RDONLY) { ferr("ERROR: Only O_RDONLY supported\n"); return -EACCES; diff --git a/sched/mqueue/mq_receive.c b/sched/mqueue/mq_receive.c index b2ea218aae8..15c389b08f5 100644 --- a/sched/mqueue/mq_receive.c +++ b/sched/mqueue/mq_receive.c @@ -90,7 +90,7 @@ static int nxmq_verify_receive(FAR struct file *mq, return -EINVAL; } - if ((mq->f_oflags & O_RDONLY) == 0) + if ((mq->f_oflags & O_ACCMODE) == O_WRONLY) { return -EBADF; } diff --git a/sched/mqueue/mq_send.c b/sched/mqueue/mq_send.c index e74a84397ba..e3b5bd7a1b6 100644 --- a/sched/mqueue/mq_send.c +++ b/sched/mqueue/mq_send.c @@ -91,7 +91,7 @@ static int nxmq_verify_send(FAR FAR struct file *mq, FAR const char *msg, return -EINVAL; } - if ((mq->f_oflags & O_WRONLY) == 0) + if ((mq->f_oflags & O_ACCMODE) == O_RDONLY) { return -EBADF; }
