Enable Time stamp on FatFs SD card

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Mon Sep 17, 2018 11:00 pm

Thanks for reply. I will double check my f_utime function call in few days. sorry busy with other tasks.

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Sun Oct 14, 2018 2:46 pm

Hi,
As my esp32 will not have public internet access. It will running on local LAN with private IP address.

I can upload via OTA. I can pass time stamp with upload file. I can keep save time stamp. when I create/update files using fopen. I need to set this same time stamp for all files after files/folder creation.
Just to clarify. After files/folders gets created.
I need to set time stamp.

Should f_utime works? or any other method.

Kindly do reply.

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

Re: Enable Time stamp on FatFs SD card

Postby ESP_igrr » Sun Oct 14, 2018 9:05 pm

Yes, f_utime should work, provided that you pass the correct path (e.g. 0:file.txt where 0 is volume number and file.txt is the file name inside FAT partition)

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Mon Oct 15, 2018 8:26 am

Kindly check this example code. I am using SD card. how I specify volume?

Code: Select all

FRESULT set_timestamp (
    char *obj,     /* Pointer to the file name */
    int year,
    int month,
    int mday,
    int hour,
    int min,
    int sec
)
{
    FILINFO fno;

    fno.fdate = (WORD)(((year - 1980) * 512U) | month * 32U | mday);
    fno.ftime = (WORD)(hour * 2048U | min * 32U | sec / 2U);

    return f_utime(obj, &fno);
}

void app_main(void)
{
    ESP_LOGI(TAG, "Initializing SD card");

    sdmmc_card_t* card;
    esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);

    if (ret != ESP_OK) {
        if (ret == ESP_FAIL) {
            ESP_LOGE(TAG, "Failed to mount filesystem. "
                "If you want the card to be formatted, set format_if_mount_failed = true.");
        } else {
            ESP_LOGE(TAG, "Failed to initialize the card (%s). "
                "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
        }
        return;
    }

  FRESULT result = set_timestamp("/sdcard/foo.txt", 2018, 9, 15, 1, 1, 1);
 ESP_LOGI(TAG, "set_timestamp result=%d", (int)result);
}

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

Re: Enable Time stamp on FatFs SD card

Postby ESP_igrr » Mon Oct 15, 2018 8:37 am

In this case the path is going to be "0:foo.txt" (instead of "/sdcard/foo.txt").

See http://elm-chan.org/fsw/ff/doc/filename.html for the fatfs library format of file names.
Normally when you use C library functions or POSIX functions which work with files, these functions translate full paths (such as /sdcard/foo.txt) into paths inside specific filesystem (such as 0:/foo.txt). When you call a fatfs function directly, you have to pass the path in the format which fatfs expects.

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: Enable Time stamp on FatFs SD card

Postby snahmad75 » Mon Oct 15, 2018 10:48 am

ok, thanks. I will try this in few days time.

zmolnar
Posts: 1
Joined: Mon Dec 06, 2021 7:51 am

Re: Enable Time stamp on FatFs SD card

Postby zmolnar » Mon Dec 06, 2021 7:59 am

I saw in older posts, that overriding of get_fattime() is not supported by the IDF. I'm wondering if it is still the case, or has it been added to the framework already? I didn't find anything related though.

I modified the implementation of get_fattime() to be weak and implemented my custom solution. It did the trick, but I want to avoid using patched framework.

What is the official way of overriding get_fattime()?

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

Re: Enable Time stamp on FatFs SD card

Postby ESP_igrr » Tue Dec 07, 2021 3:45 pm

I think you can use -Wl,--wrap=get_fattime linker flag, and then implement __wrap_get_fattime function in your application or library code. This would allow you to override this function without patching ESP-IDF.

Who is online

Users browsing this forum: No registered users and 131 guests