can't fail to open file

kernic
Posts: 11
Joined: Tue Aug 20, 2024 10:33 pm

Re: can't fail to open file

Postby kernic » Mon Aug 26, 2024 12:33 am

At this point reading microsoft fat32 implementation and the wikipedia page is easier, I'm just gonna do it myself :lol:

Did you try the code I gave you? even the simplest sample I gave at the end? please try it. I tried formatting my card more than 100 times while trying to debug this. I and about f_sync, did you notice how in the simplest sample I gave you I call f_close just after checking if the file exists? This should have the same effect ?

Code: Select all

    f_open(&file, FILE_PATH, FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
    
    if(f_size(&file) == 0) {
        printf("init file for the first time (size == 0)\n");

        f_expand(&file, 10000, 1);
    }
    else {
        printf("File opened with success\n");
    }

    f_close(&file);
Using the above code works only once, when you change the file_path and try calling the same code again, the new file won't exist and it'll directly say 'file opened with success' instead of 'init file for the first time' when you try creating a second file with that same code.

So the first time it works and says "init file for first time" then 'file opened with success' while the second time it doesn't work and when you open 2nd file it says 'file opened with success' then 'file opened with success' and the file isn't discoverable on windows.

You guys should at least activate the long file names extension. 8 character name in maj looks like crap
even the Standard C Library I/O with the FILE object is buggy when you check if a file was already existing, and can only have 8 characters names by default.

fopen() in c has the exact same behavior, presumably because it relies on the same filesystem.
https://www.tutorialspoint.com/c_standa ... _fopen.htm
This function is normally stable on linux, and on windows, and on any other you can think of

kernic
Posts: 11
Joined: Tue Aug 20, 2024 10:33 pm

Re: can't fail to open file

Postby kernic » Mon Aug 26, 2024 8:13 am

so when you flash the esp32, it execute the main at least once without showing you, that's why it had problem with showing me the first init. If I flash the esp32 without the sd card it works fine. also for some reason, calling the f_expand function inside the conditional statement was problematic, but their doc says that

"The function can fail with FR_DENIED due to some reasons below.
Size of the file was not zero."

so once the file is created, subsequent calls to f_expand will fail anyway, so I don't need to put it in a conditional anyway I guess..
thanks for trying to help..

Who is online

Users browsing this forum: No registered users and 123 guests