Skip to content
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

SPIFFS_write function does not work when SPIFFS_APPEND is specified #58

Closed
zdrc opened this issue Nov 16, 2015 · 3 comments
Closed

SPIFFS_write function does not work when SPIFFS_APPEND is specified #58

zdrc opened this issue Nov 16, 2015 · 3 comments

Comments

@zdrc
Copy link

zdrc commented Nov 16, 2015

I'm on Mac OSX 10.11.1, and I'm using the spiffs framework with sming to program an ESP201

I ran into a problem where I was unable to write to a file (using SPIFFS_write) I had opened with the SPIFFS_APPEND flag called. I was getting the error SPIFFS_ERR_NOT_WRITABLE with the error code -10021. After some testing I discovered that the root of the problem seems to be this section of code,

if ((fd->flags & SPIFFS_WRONLY) == 0) {
  res = SPIFFS_ERR_NOT_WRITABLE;
  SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
}

I believe this code dictates that SPIFFS_write will only work if opened when the flag is set to SPIFFS_WRONLY this becomes a problem when calling SPIFFS_write when a file is opened in SPIFFS_APPEND

If I change the bitwise operation in the if clause's condition to
(fd-> flags & (SPIFFS_WRONLY | SPIFFS_APPEND)) == 0
I am able to append to the file I opened, and my code behaves as it should.

@pellepl
Copy link
Owner

pellepl commented Nov 17, 2015

Hmm.. The code looks correct to me (though I have not slept enough ;))

Did you open the file with only SPIFFS_APPEND? You probably want to open it with (SPIFFS_RDWR | SPIFFS_APPEND) or (SPIFFS_WRONLY | SPIFFS_APPEND). Specifying only SPIFFS_APPEND when opening the file would lead to a file that cannot be read nor written.

@zdrc
Copy link
Author

zdrc commented Nov 17, 2015

Ah I see. In the Sming repository code only SPIFFS_APPEND is used. It sounds like there was a miscommunication on how to set the flags, I'll discuss with them.

@pellepl
Copy link
Owner

pellepl commented Nov 17, 2015

Yes, I tried opening a file on linux with only O_APPEND and only got a bad
filedesc in return.
But thanks for the heads up!
Den 17 nov 2015 5:50 PM skrev "Alex" notifications@github.com:

Ah I see. In the Sming repository code only SPIFFS_APPEND is used. It
sounds like there was a miscommunication on how to set the flags, I'll
discuss with them.


Reply to this email directly or view it on GitHub
#58 (comment).

@pellepl pellepl closed this as completed Nov 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants