- CONFIG_FATFS_LFN_HEAP=y
- CONFIG_FATFS_SECTOR_4096=y
- CONFIG_FATFS_USE_FASTSEEK=y
- CONFIG_FATFS_FAST_SEEK_BUFFER_SIZE=64
- CONFIG_FATFS_VFS_FSTAT_BLKSIZE=4092
The problem is that, and I have no idea why, when I put FA_CREATE_NEW as a parameter in the second call to f_open for when OPEN_EXISTING fails, it creates the file directly in the first call to f_open and completely ignore the FA_OPEN_EXISTING.
please, can someone try this out to see what I mean? I think I'm going mad it's been 3 hours debugging this and I can't understand why it is made this way.
All I want is open a file if it exists(FA_OPEN_EXISTING), if so execute a conditional block, and if it doesn't execute another conditional block where I try to create it(FA_CREATE_NEW).
if I use FA_CREATE_NEW only once(anywhere in my code) FA_OPEN_EXISTING doesn't work and acts as FA_CREATE_NEW in the first call
I am currently using the esp idf 5.0.2, this looks like a bug to me, if someone could confirm what I think..
Code: Select all
// Attempt to open the file
fr = f_open(&file, FILE_PATH, FA_OPEN_EXISTING | FA_READ | FA_WRITE);
if (fr == FR_OK) {
printf("File opened with success\n");
printf("Impossible to bypass this path even when the file doesn't exist yet when the second call contains FA_CREATE_NEW \n");
}
else if (fr == FR_NO_FILE) {
printf("Can't open file, creating it\n");
fr = f_open(&file, FILE_PATH, FA_CREATE_NEW | FA_READ | FA_WRITE);
if (fr == FR_OK) {
printf("File created successfully.\n");
f_expand(&file, 1000000, 1);
} else {
printf("Failed creating file\n");
}
} else {
printf("Failed to open file with error: %d\n", fr);
}