Reading files from SD Card using sdmmc_read_sectors()

_0b00t_
Posts: 12
Joined: Mon Dec 30, 2019 6:56 pm

Reading files from SD Card using sdmmc_read_sectors()

Postby _0b00t_ » Tue Dec 31, 2019 3:30 pm

Hi,
I can read raw sectors from a SD Card with sdmmc_read_sectors() fonction. But I want to read raw sectors of a specific huge file that is stored in the SD Card. But I don't know the value of his first sector ?
I have mounted a file sytem partition using :
  1. esp_vfs_fat_sdmmc_mount_config_t mount_config = {
  2.                 .format_if_mount_failed = 0,
  3.                 .max_files = 5,
  4.                 .allocation_unit_size = 16 * 1024
  5.         };
  6.  
  7.     esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
But I don't know how to have a list of all the files with their first cluster value ?
That way I could have the flexibility of a FAT partition (just drag and drop files to the SD card) and read/write really fast files
Thanks for reading

_0b00t_
Posts: 12
Joined: Mon Dec 30, 2019 6:56 pm

Re: Reading files from SD Card using sdmmc_read_sectors()

Postby _0b00t_ » Thu Jan 02, 2020 10:37 am

In fact, I want to read for example directly the cluster of myfile.txt without using POSIX/SdFat fonctions for speed. But I don't know how to know the number of the first cluster
sd.PNG
sd.PNG (11.73 KiB) Viewed 5122 times
*
Is there a way to read the File Allocation Table to know in which clusters the file is stored.

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

Re: Reading files from SD Card using sdmmc_read_sectors()

Postby ESP_igrr » Thu Jan 02, 2020 1:15 pm

There doesn't seem to be a standard way (as in, POSIX) of getting the file allocation table information. FATFS library also doesn't expose any such functions, as far as I can tell. The file structure used by FATFS (called FIL) is public, though, in ff.h (https://github.com/espressif/esp-idf/bl ... #L196-L213).
C standard library functions such as fopen/fwrite don't give you a way to access the underlying FIL structure. If you use FATFS APIs (f_open, f_read, f_write) directly, then you may get the information you need from the FIL structure (FIL::clust).

_0b00t_
Posts: 12
Joined: Mon Dec 30, 2019 6:56 pm

Re: Reading files from SD Card using sdmmc_read_sectors()

Postby _0b00t_ » Mon Jan 06, 2020 5:13 pm

In fact, I realized that clusters of a file are not necessarily following each others (in hardware).
So I couldn't read all clusters of a file with just one read command using sdmmc_read_sectors().
But I have done a script in Python that write any file in binary on a SD Card at a chosen sectors. It's start writing at a specific sector offset and write on the next sector, and so on.

Who is online

Users browsing this forum: No registered users and 71 guests