Brian A. Henning
Brian A. Henning

Reputation: 1511

readdir is returning lots of all-0xFF 8.3 names from fat32 filesystem

I'm working on an ESP32 platform with IDF 4.1, using code like this:

struct dirent * dirent;
while((dirent = readdir(dir)) != nullptr) {
   ESP_LOGI("ConfigServer", "Found %s, id %d, type %d", dirent->d_name, dirent->d_ino, dirent->d_type);
   if(dirent->d_name[0] == '\377') {
      ++invalid_ctr;
   } else {
      // do something with the file info
   }
}
closedir(dir);

I had to add the bit where invalid_ctr is incremented, because I started getting loads of iterations where dirent->d_name was "\377\377\377\377\377\377\377\377.\377\377\377" (rendered as inverse-video "?" characters in my terminal). The code not shown involves feeding that name to stat(), which would return the same values as the last valid file encountered. The log entry would look like this:

 I (608261) ConfigServer: Found ��������.���, id 0, type 2

Type 2 represents a directory. This is happening on a partition on the onboard flash, formatted by the IDF library's "format if mount failed" option at mount. So perhaps my assumption of FAT32 is invalid. I do know that IDF uses FatFs internally.

Is this indicative of an error on the filesystem? Is it expected to need to filter out such trash on a typical iteration with readdir()?

Upvotes: 0

Views: 512

Answers (1)

Tarmo
Tarmo

Reputation: 4762

The FAT component in ESP IDF has support for long file names disabled by default. Run idf.py menuconfig, then "Component config → FAT Filesystem support → Long filename support" to enable it.

Upvotes: 1

Related Questions