espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.91k stars 7.09k forks source link

ESP-IDF Littlefs + esp_vfs_readdir (IDFGH-8649) #10095

Open ifoxbr opened 1 year ago

ifoxbr commented 1 year ago

Answers checklist.

General issue report

Can someone explain to me what this routine does? When debugging my program, the debug always stops at this routine. I use littlefs, does anyone know what I'm doing wrong and how to avoid this error?

struct dirent* esp_vfs_readdir(DIR* pdir)
{
    const vfs_entry_t* vfs = get_vfs_for_index(pdir->dd_vfs_idx);
    struct _reent* r = __getreent();
    if (vfs == NULL) {
       __errno_r(r) = EBADF;
        return NULL;
    }
    struct dirent* ret;
    CHECK_AND_CALLP(ret, r, vfs, readdir, pdir);
    return ret;
}
dobairoland commented 1 year ago

Calls to readdir() are redirected to esp_vfs_readdir() which will redirect the call to readdir implementation of the driver. It decides which driver to use, i.e. fatfs if the directory is in fatfs.

You can find more information about this topic on this site: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/vfs.html

dobairoland commented 1 year ago

The callback for littlefs is registered here: https://github.com/joltwallet/esp_littlefs/blob/master/src/esp_littlefs.c#L255

ifoxbr commented 1 year ago

Thank you Dobairoland

I get this breakpoint when debugging (Esp-IDF/ VsCode), and when running without debug the program crashes, I Iassume it's the same callback. I´m using Littlefs and instantiate as

     esp_vfs_littlefs_conf_t conf = 
    {
        .base_path = "/littlefs",
        .partition_label = "littlefs", // este nome é o Name do arquivo "partition.csv"
        .format_if_mount_failed = true,
        .dont_mount = false,
    };

Regards