apps: Fix O_ACCMODE bitmask checks after Linux flag alignment#3572
Merged
Conversation
After aligning NuttX open() flag constants with Linux (O_RDONLY=0,
O_WRONLY=1, O_RDWR=2), code that used '(flags & O_RDONLY)' or
'(flags & O_WRONLY)' as a bitmask check is broken because O_RDONLY
is now 0. Fix by using '(flags & O_ACCMODE)' comparisons instead.
- usrsocktest: replace 'flags & O_RDWR' with 'flags & O_ACCMODE'
in fcntl F_GETFL assertions
- dd: verify mode used '(oflags & O_RDONLY)' to detect verify;
replace with '(oflags & O_ACCMODE) == O_RDWR'
- dpopen: replace '(oflag & O_RDWR) == O_RDWR' with
'(oflag & O_ACCMODE) == O_RDWR'
- usbmsc: replace 'flags & O_WRONLY' with
'(flags & O_ACCMODE) == O_RDONLY'
- fcntl_test: replace '(flags & O_WRONLY) == 0' with
'(flags & O_ACCMODE) == O_RDONLY'
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
acassis
approved these changes
Jun 30, 2026
Contributor
Author
|
@jerpelea and @linguini1 this patch need merge ASAP to avoid breaking mainline. |
linguini1
approved these changes
Jun 30, 2026
cederom
approved these changes
Jun 30, 2026
cederom
left a comment
Contributor
There was a problem hiding this comment.
Thank you @xiaoxiang781216 :-)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion to apache/nuttx#19238 ("include/fcntl.h: align open flags with Linux values").
After aligning the NuttX
open()flag constants with Linux (O_RDONLY=0,O_WRONLY=1,O_RDWR=2), code that used(flags & O_RDONLY)or(flags & O_WRONLY)as a bitmask check is broken becauseO_RDONLYis now0. This PR fixes all such sites inapps/by using(flags & O_ACCMODE)comparisons instead.examples/usrsocktest/): replaceflags & O_RDWRwithflags & O_ACCMODEinfcntl(F_GETFL)assertions across 5 test files.system/dd/dd_main.c): verify mode used(oflags & O_RDONLY)to detect verify; replace with(oflags & O_ACCMODE) == O_RDWR.system/popen/dpopen.c): replace(oflag & O_RDWR) == O_RDWRwith(oflag & O_ACCMODE) == O_RDWR.system/usbmsc/usbmsc_main.c): replaceflags & O_WRONLYwith(flags & O_ACCMODE) == O_RDONLY.testing/testsuites/kernel/syscall/cases/fcntl_test.c): replace(flags & O_WRONLY) == 0with(flags & O_ACCMODE) == O_RDONLY.Impact
O_RDONLY == 0(e.g.dd verifynever triggers, dpopen bidirectional detection fails, usbmsc read-only detection is wrong).Testing
Tested on the
sim:nshtarget (Linux x86_64 host, gcc) together with apache/nuttx#19238.Boot log:
OSTest: ran
ostestfrom the NSH prompt — all tests passed with no failures or panics.