!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 <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2026-06-24 17:53:33 +08:00 committed by Xiang Xiao
parent 9c381340c0
commit 9e141acab3
75 changed files with 239 additions and 213 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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;
}

View file

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

View file

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

View file

@ -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;
}

View file

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

View file

@ -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--;
}

View file

@ -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)
{