Skip to content

fs file open for read|write #6227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
xinkiknix opened this issue Feb 3, 2022 · 11 comments
Closed
1 task done

fs file open for read|write #6227

xinkiknix opened this issue Feb 3, 2022 · 11 comments
Labels
Area: Libraries Issue is related to Library support.

Comments

@xinkiknix
Copy link

Board

ESP32

Device Description

ESP32 NodeMCU

Hardware Configuration

na

Version

v2.0.2

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

40

PSRAM enabled

yes

Upload speed

115200

Description

I can not position in a file (Seek) and overwrite a portion. There is no option in FS for RW (O_RDWR or FREAD|FWRITE)
I can only open for FILE_READ, FILE_WRITE, FILE_APPEND.

Sketch

File file = fs.open(path, O_RDWR);

Debug Message

\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2\xtensa-esp32-elf\sys-include\sys\_default_fcntl.h:50: note: it was later defined here
 #define O_RDWR  2  /* +1 == FREAD|FWRITE */

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@xinkiknix xinkiknix added the Status: Awaiting triage Issue is waiting for triage label Feb 3, 2022
@VojtechBartoska
Copy link
Contributor

Hello, can you please retest this on v2.0.3-rc1?

@VojtechBartoska VojtechBartoska added Area: Libraries Issue is related to Library support. Resolution: Awaiting response Waiting for response of author and removed Status: Awaiting triage Issue is waiting for triage labels Apr 11, 2022
@xinkiknix
Copy link
Author

I get the same message with version 2.0.3-rc1.
in FS.h mode is still defined/limited as/to
`namespace fs
{

#define FILE_READ "r"
#define FILE_WRITE "w"
#define FILE_APPEND "a"
`

@VojtechBartoska
Copy link
Contributor

Thanks for testing @xinkiknix, are you able to propose PR?

@xinkiknix
Copy link
Author

PR?

@igrr
Copy link
Member

igrr commented Apr 11, 2022

There is no option in FS for RW (O_RDWR or FREAD|FWRITE)

@xinkiknix When calling FS.open, you can pass any of the file open modes which you can normally pass to C fopen function. Please see its docs here: https://en.cppreference.com/w/c/io/fopen.
Depending on the desired behavior you can use "r+" or "a+" mode.

@xinkiknix
Copy link
Author

Thanks, for the update, but then why are there these definitions?
`namespace fs
{

#define FILE_READ "r"
#define FILE_WRITE "w"
#define FILE_APPEND "a"`
?

@lbernstone
Copy link
Contributor

Those defines are legacies from Arduino's SD.h. ESP32 has POSIX compatibility under the covers, so provides emulated Arduino behaviors.

@johnboiles
Copy link

I don't think it's safe to use rw in the Arduino APIs. For example in this code if((mode && mode[0] != 'r') && (!create)){ it will only create the file if the first character of the const char *mode is not 'r'. So it will fail to create a file if the mode is specified as 'rw'.

@demosglok
Copy link

I don't think it's safe to use rw in the Arduino APIs. For example in this code if((mode && mode[0] != 'r') && (!create)){ it will only create the file if the first character of the const char *mode is not 'r'. So it will fail to create a file if the mode is specified as 'rw'.

try "a+" and "w+". i don't know about "rw", only "a+", "r+", "w+" and I suppose "r+" shouldn't create file, while "w+" and "a+" should

@johnboiles
Copy link

Ah yeah rw isn't a real mode I guess. I wanted w+. My bad!

@Parsaabasi
Copy link

Hi everyone,

Seems like this issue is resolved. I close it for now.

In case the same issue occurs, or you would need to discuss it further, please reopen it and we will revisit it.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support.
Projects
Development

No branches or pull requests

7 participants