From f1236da21c34212832d7b39bd7fcd3b1614a5cae Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 3 Jun 2022 00:23:24 +0800 Subject: [PATCH] fs: Make the binary(no process) mode as the default POSIX require file system shouldn't enable the \r and \n conversion by default Signed-off-by: Xiang Xiao --- arch/arm/src/common/arm_hostfs.c | 12 ++++++------ arch/arm/src/rtl8720c/ameba_hci.c | 2 +- arch/risc-v/src/common/riscv_hostfs.c | 12 ++++++------ drivers/wireless/bluetooth/bt_uart_shim.c | 2 +- drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c | 2 +- drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c | 2 +- include/fcntl.h | 4 ++-- include/sys/eventfd.h | 2 +- libs/libc/misc/lib_ncompress.c | 4 ---- libs/libc/stdio/lib_fopen.c | 14 +++++++------- libs/libc/stream/lib_stdoutstream.c | 2 +- libs/libc/stream/lib_stdsostream.c | 2 +- libs/libc/time/lib_localtime.c | 2 +- 13 files changed, 29 insertions(+), 33 deletions(-) diff --git a/arch/arm/src/common/arm_hostfs.c b/arch/arm/src/common/arm_hostfs.c index 720075819b..fbde7fb626 100644 --- a/arch/arm/src/common/arm_hostfs.c +++ b/arch/arm/src/common/arm_hostfs.c @@ -78,18 +78,18 @@ static int host_flags_to_mode(int flags) { static const int modeflags[] = { + O_RDONLY | O_TEXT, O_RDONLY, - O_RDONLY | O_BINARY, + O_RDWR | O_TEXT, O_RDWR, - O_RDWR | O_BINARY, + O_WRONLY | O_CREAT | O_TRUNC | O_TEXT, O_WRONLY | O_CREAT | O_TRUNC, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + O_RDWR | O_CREAT | O_TRUNC | O_TEXT, O_RDWR | O_CREAT | O_TRUNC, - O_RDWR | O_CREAT | O_TRUNC | O_BINARY, + O_WRONLY | O_CREAT | O_APPEND | O_TEXT, O_WRONLY | O_CREAT | O_APPEND, - O_WRONLY | O_CREAT | O_APPEND | O_BINARY, + O_RDWR | O_CREAT | O_APPEND | O_TEXT, O_RDWR | O_CREAT | O_APPEND, - O_RDWR | O_CREAT | O_APPEND | O_BINARY, 0, }; diff --git a/arch/arm/src/rtl8720c/ameba_hci.c b/arch/arm/src/rtl8720c/ameba_hci.c index 2c17f699fe..378e0c45df 100644 --- a/arch/arm/src/rtl8720c/ameba_hci.c +++ b/arch/arm/src/rtl8720c/ameba_hci.c @@ -389,7 +389,7 @@ static int hci_open(struct file *filep) hci_dev_t *dev = inode->i_private; int ret; ret = file_open(&dev->filep, - CONFIG_AMEBA_HCI_DEV_NAME, O_RDWR | O_BINARY); + CONFIG_AMEBA_HCI_DEV_NAME, O_RDWR); if (ret < 0) { return ret; diff --git a/arch/risc-v/src/common/riscv_hostfs.c b/arch/risc-v/src/common/riscv_hostfs.c index d5786e22a2..e20700e1ea 100644 --- a/arch/risc-v/src/common/riscv_hostfs.c +++ b/arch/risc-v/src/common/riscv_hostfs.c @@ -78,18 +78,18 @@ static int host_flags_to_mode(int flags) { static const int modeflags[] = { + O_RDONLY | O_TEXT, O_RDONLY, - O_RDONLY | O_BINARY, + O_RDWR | O_TEXT, O_RDWR, - O_RDWR | O_BINARY, + O_WRONLY | O_CREAT | O_TRUNC | O_TEXT, O_WRONLY | O_CREAT | O_TRUNC, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + O_RDWR | O_CREAT | O_TRUNC | O_TEXT, O_RDWR | O_CREAT | O_TRUNC, - O_RDWR | O_CREAT | O_TRUNC | O_BINARY, + O_WRONLY | O_CREAT | O_APPEND | O_TEXT, O_WRONLY | O_CREAT | O_APPEND, - O_WRONLY | O_CREAT | O_APPEND | O_BINARY, + O_RDWR | O_CREAT | O_APPEND | O_TEXT, O_RDWR | O_CREAT | O_APPEND, - O_RDWR | O_CREAT | O_APPEND | O_BINARY, 0, }; diff --git a/drivers/wireless/bluetooth/bt_uart_shim.c b/drivers/wireless/bluetooth/bt_uart_shim.c index 56707a0cc5..40952504f6 100644 --- a/drivers/wireless/bluetooth/bt_uart_shim.c +++ b/drivers/wireless/bluetooth/bt_uart_shim.c @@ -401,7 +401,7 @@ FAR struct btuart_lowerhalf_s *btuart_shim_getdevice(FAR const char *path) s = &n->state; - ret = file_open(&s->f, path, O_RDWR | O_BINARY); + ret = file_open(&s->f, path, O_RDWR); if (ret < 0) { kmm_free(n); diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c index 10b3aacd73..40124f5970 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_core.c @@ -248,7 +248,7 @@ int bcmf_upload_file(FAR struct bcmf_sdio_dev_s *sbus, uint32_t address, /* Open the file in the detached state */ - ret = file_open(&finfo, path, O_RDONLY | O_BINARY); + ret = file_open(&finfo, path, O_RDONLY); if (ret < 0) { wlerr("ERROR: Failed to open the FILE MTD file %s: %d\n", path, ret); diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c index 718fab2b60..78c7a5168d 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c @@ -259,7 +259,7 @@ int bcmf_driver_download_clm(FAR struct bcmf_dev_s *priv) wlinfo("Download %d bytes\n", datalen); ret = file_open(&finfo, CONFIG_IEEE80211_BROADCOM_FWCLMNAME, - O_RDONLY | O_BINARY); + O_RDONLY); if (ret < 0) { wlerr("ERROR: Failed to open the FILE MTD file\n", ret); diff --git a/include/fcntl.h b/include/fcntl.h index 9cef7ed9e0..77f678126f 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -49,7 +49,7 @@ #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_BINARY (1 << 8) /* Open the file in binary (untranslated) mode. */ +#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 */ @@ -58,7 +58,7 @@ #define O_RSYNC 0 /* Synchronize input on read */ #define O_ACCMODE O_RDWR /* Mask for access mode */ #define O_NOCTTY 0 /* Required by POSIX */ -#define O_TEXT 0 /* Open the file in text (translated) mode. */ +#define O_BINARY 0 /* Open the file in binary (untranslated) 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. diff --git a/include/sys/eventfd.h b/include/sys/eventfd.h index 6ed305a49f..8fbb044236 100644 --- a/include/sys/eventfd.h +++ b/include/sys/eventfd.h @@ -33,7 +33,7 @@ ****************************************************************************/ #define EFD_NONBLOCK O_NONBLOCK -#define EFD_SEMAPHORE O_BINARY +#define EFD_SEMAPHORE O_SYNC #define EFD_CLOEXEC O_CLOEXEC /**************************************************************************** diff --git a/libs/libc/misc/lib_ncompress.c b/libs/libc/misc/lib_ncompress.c index d7e3ae965a..522aadc309 100644 --- a/libs/libc/misc/lib_ncompress.c +++ b/libs/libc/misc/lib_ncompress.c @@ -174,10 +174,6 @@ # define NOALLIGN 1 #endif /* DOS */ -#ifndef O_BINARY -# define O_BINARY 0 /* System has no binary mode */ -#endif - #ifdef M_XENIX /* Stupid compiler can't handle arrays with */ # if BITS == 16 /* more than 65535 bytes - so we fake it */ # define MAXSEG_64K diff --git a/libs/libc/stdio/lib_fopen.c b/libs/libc/stdio/lib_fopen.c index 537a92abca..4de7738bd0 100644 --- a/libs/libc/stdio/lib_fopen.c +++ b/libs/libc/stdio/lib_fopen.c @@ -49,7 +49,7 @@ #define MODE_NONE 0 /* No access mode determined */ #define MODE_MASK (MODE_R | MODE_W | MODE_A) -#define FLAG_KEEP (O_BINARY | O_CLOEXEC | O_EXCL) +#define FLAG_KEEP (O_TEXT | O_CLOEXEC | O_EXCL) /**************************************************************************** * Public Functions @@ -156,7 +156,7 @@ int lib_mode2oflags(FAR const char *mode) { /* Open for read access */ - oflags = O_RDOK; + oflags = O_RDOK | O_TEXT; state = MODE_R; } else @@ -172,7 +172,7 @@ int lib_mode2oflags(FAR const char *mode) { /* Open for write access, truncating any existing file */ - oflags = (O_WROK | O_CREAT | O_TRUNC); + oflags = O_WROK | O_CREAT | O_TRUNC | O_TEXT; state = MODE_W; } else @@ -188,7 +188,7 @@ int lib_mode2oflags(FAR const char *mode) { /* Write to the end of the file */ - oflags = O_WROK | O_CREAT | O_APPEND; + oflags = O_WROK | O_CREAT | O_APPEND | O_TEXT; state = MODE_A; } else @@ -224,7 +224,7 @@ int lib_mode2oflags(FAR const char *mode) * file. */ - oflags |= (O_RDWR | O_CREAT | O_TRUNC); + oflags |= O_RDWR | O_CREAT | O_TRUNC; } break; @@ -238,7 +238,7 @@ int lib_mode2oflags(FAR const char *mode) * end, */ - oflags |= (O_RDWR | O_CREAT | O_APPEND); + oflags |= O_RDWR | O_CREAT | O_APPEND; } break; @@ -255,7 +255,7 @@ int lib_mode2oflags(FAR const char *mode) { /* The file is opened in binary mode */ - oflags |= O_BINARY; + oflags &= ~O_TEXT; } else { diff --git a/libs/libc/stream/lib_stdoutstream.c b/libs/libc/stream/lib_stdoutstream.c index 7733e70d1e..e893cc4293 100644 --- a/libs/libc/stream/lib_stdoutstream.c +++ b/libs/libc/stream/lib_stdoutstream.c @@ -115,7 +115,7 @@ void lib_stdoutstream(FAR struct lib_stdoutstream_s *outstream, */ #ifndef CONFIG_STDIO_DISABLE_BUFFERING - if (stream->fs_bufstart != NULL && (stream->fs_oflags & O_BINARY) == 0) + if (stream->fs_bufstart != NULL && (stream->fs_oflags & O_TEXT) != 0) { outstream->public.flush = stdoutstream_flush; } diff --git a/libs/libc/stream/lib_stdsostream.c b/libs/libc/stream/lib_stdsostream.c index 2d48865cae..2e5aa9e3ba 100644 --- a/libs/libc/stream/lib_stdsostream.c +++ b/libs/libc/stream/lib_stdsostream.c @@ -126,7 +126,7 @@ void lib_stdsostream(FAR struct lib_stdsostream_s *outstream, */ #ifndef CONFIG_STDIO_DISABLE_BUFFERING - if (stream->fs_bufstart != NULL && (stream->fs_oflags & O_BINARY) == 0) + if (stream->fs_bufstart != NULL && (stream->fs_oflags & O_TEXT) != 0) { outstream->public.flush = stdsostream_flush; } diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index 11c08afa1b..3cd312b8d8 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -625,7 +625,7 @@ static int tzload(FAR const char *name, goto oops; } - fid = _NX_OPEN(name, O_RDONLY | O_BINARY); + fid = _NX_OPEN(name, O_RDONLY); if (fid < 0) { goto oops;