_FS_LOCK makes f_open return error in IDF 3.0

abcdcadb
Posts: 36
Joined: Mon Aug 07, 2017 1:28 am

_FS_LOCK makes f_open return error in IDF 3.0

Postby abcdcadb » Thu Nov 23, 2017 1:05 am

when I use f_open to open a file in sd card, it returns error (16) (if _FS_LOCK is a positive number (10))

Code: Select all

FR_LOCKED,				/* (16) The operation is rejected according to the file sharing policy */
if I down _FS_LOCK to 0, i can open file well, but there are several other problems.
Can anyone tell me how I keep _FS_LOCK is 10 and work well with file?, like in IDF 2.0. I dont know what were changed in IDF 3.0?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby ESP_igrr » Thu Nov 23, 2017 2:43 am

This error indicates that your program is performing two operations on the same file in parallel.

When _FS_LOCK is 0, fatfs will not check for such access issues, but as you noted there will be issues later on.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby kolban » Thu Nov 23, 2017 2:46 am

Howdy,
I'm assuming by "f_open" you mean "fopen()" as in http://man7.org/linux/man-pages/man3/fopen.3.html

fopen() returns a file pointer, so I am assuming that fopen() is returning NULL and that errno is set to 16 as per your description.

The errno 16 (decimal) is defined here:

https://github.com/espressif/esp-idf/bl ... rrno.h#L48

as EBUSY.

I'm not familiar with the notion of "_FS_LOCK". Would you be able to elaborate on this and ideally provide a link to the relevant documentation?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

abcdcadb
Posts: 36
Joined: Mon Aug 07, 2017 1:28 am

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby abcdcadb » Thu Nov 23, 2017 3:16 am

Hi ESP_igrr
This error indicates that your program is performing two operations on the same file in parallel.
my _FS_LOCK is 10 (and even I changed it into 100), does it still mean "two operations on the same file" causes that error (or it should be 10)?

Hi Kolban,

f_write belongs to fatfs library, fwrite is stdio (newlib/include/stdio.h).

while f_write handle on "FIL"(declared on ff.h), fwrite is on "FILE", FILE is an opaque data type, i don't know they are similar or not

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby ESP_igrr » Thu Nov 23, 2017 4:26 am

Ok, does the application actually open the same file twice, or tries to do something with a file (rename, copy, etc) while it is open?

The value of _FS_LOCK affects the number of files which can be checked for invalid simultaneous access. Setting it to 10 or to 100 should make no difference if you are only working with a few files.

abcdcadb
Posts: 36
Joined: Mon Aug 07, 2017 1:28 am

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby abcdcadb » Thu Nov 23, 2017 6:43 am

does the application actually open the same file twice, or tries to do something with a file (rename, copy, etc) while it is open
is there any way to check that I am opening the same file twice?

my code now is bulky so i am not sure. However, it works in IDF 2.0 therefore I guess it should be OK

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby ESP_igrr » Thu Nov 23, 2017 7:42 am

You can figure out whether you have concurrent operations on the same file by reviewing your code, or logging your file operations, or writing wrappers for f_open and f_close functions.

IIRC, in IDF 2.0 _FS_LOCK was set to 0, which is why you didn't get any errors reported.

abcdcadb
Posts: 36
Joined: Mon Aug 07, 2017 1:28 am

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby abcdcadb » Thu Nov 23, 2017 8:01 am

You can figure out whether you have concurrent operations on the same file by reviewing your code, or logging your file operations, or writing wrappers for f_open and f_close functions.
thanks, I will
in IDF 2.0 _FS_LOCK was set to 0, which is why you didn't get any errors reported.
in IDF 2.0, I try setting _FS_LOCK 10, and with the same code, it still works without problem. Is there any more reason?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby ESP_igrr » Thu Nov 23, 2017 8:24 am

Perhaps when you build your application against 2.0, concurrent access to the same file does not happen, so no error is reported?

abcdcadb
Posts: 36
Joined: Mon Aug 07, 2017 1:28 am

Re: _FS_LOCK makes f_open return error in IDF 3.0

Postby abcdcadb » Fri Nov 24, 2017 3:23 am

ESP_igrr

could you give me an example which use f_open to open a file and then do any handling (read or write) to that file which you are sure that it works on IDF3.0?

the sd_card example uses fopen (stdio.h) not f_open.

I really need a reference now

thanks

Who is online

Users browsing this forum: No registered users and 134 guests