!include/fcntl.h: align open flags with Linux values#19238
!include/fcntl.h: align open flags with Linux values#19238xiaoxiang781216 wants to merge 2 commits into
Conversation
|
| #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. */ |
There was a problem hiding this comment.
@xiaoxiang781216 shouldn't it be considered a breaking change? Although the symbols still the same their values changes, so some external lib or app (that for some reason copied this old header file) will fail to run new NuttX version.
There was a problem hiding this comment.
Yes, it's a breaking change, but it actually improves the compatibility with other major OS:
| Constant | NuttX (before) | NuttX (after) | Linux | glibc | FreeBSD | macOS |
|---|---|---|---|---|---|---|
O_RDONLY |
1 |
0 |
0 |
0 |
0 |
0 |
O_WRONLY |
2 |
1 |
1 |
1 |
1 |
1 |
O_RDWR |
3 |
2 |
2 |
2 |
2 |
2 |
O_ACCMODE |
3 |
3 |
3 |
3 |
3 |
3 |
Many 3rd party libraries have to modified to work with NuttX just because NuttX defines O_RDONLY/O_WRONLY/O_RDWR to different values.
There was a problem hiding this comment.
Yes, I agree on that!], but the meaning of "breaking changes" is: breaking change with previous NuttX versions. Even when it is to improve the general compatibility.
There was a problem hiding this comment.
I added ! to commit message and the breaking change label.
6bb526f to
c39f8fe
Compare
to pass PSE52 test suite Signed-off-by: tengshuangshuang <tengshuangshuang@xiaomi.com>
c39f8fe to
e24c6db
Compare
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>
e24c6db to
7872717
Compare
Summary
Align the NuttX
open(2)flag constants (O_RDONLY/O_WRONLY/O_RDWR) with the Linux asm-generic values (0/1/2instead of1/2/3) so that the FUSE wire protocol and other cross-platform interfaces work without conversion.O_CREAT,O_EXCL,O_APPEND,O_TRUNC,O_NONBLOCK,O_SYNC,O_DSYNC,O_DIRECT,O_DIRECTORY,O_NOFOLLOW,O_NOATIME,O_CLOEXEC,O_PATH,O_TMPFILE, etc.) with the Linuxasm-genericvalues.(flags & O_RDONLY)as a bitmask check (which is always0now thatO_RDONLY == 0) to use(flags & O_ACCMODE)comparisons instead, acrossfs/,drivers/,libs/,arch/,sched/,net/, andgraphics/.NUTTX_O_*constants ininclude/nuttx/fs/hostfs.hto match, and fix the sim hostfs open-flag mapping.Access-mode flag values across major operating systems
O_RDONLY100000O_WRONLY211111O_RDWR322222O_ACCMODE333333Before this change NuttX was the only major OS using
1/2/3for the access-mode flags; every other platform (Linux, glibc, FreeBSD, macOS) uses the0/1/2convention. After this change NuttX matches the de-facto standard, so interfaces that pass open flags directly across the kernel/userspace or host/guest boundary (e.g. FUSE) work without conversion.Impact
(flags & O_RDONLY)would silently break (O_RDONLYis now0), so every such site has been audited and converted to(flags & O_ACCMODE).#defines change.Testing
Tested on the
sim:nshtarget (Linux x86_64 host, gcc).Boot log:
OSTest: ran
ostestfrom the NSH prompt — all tests passed with no failures or panics. Final summary: