File System Component  Version 6.16.6
MDK Middleware for Devices with Flash File System
File Time Support Routines

File time support routines return the current date and time. More...

Functions

fsStatus ftime_set (const char *path, fsTime *create, fsTime *access, fsTime *write)
 Set file or directory timestamp. More...
 
fsStatus ftime_get (const char *path, fsTime *create, fsTime *access, fsTime *write)
 Get file or directory timestamp. More...
 
fsStatus fs_get_time (fsTime *time)
 Callback function used to provide the current date and time to the File System. More...
 

Description

File time support routines return the current date and time.

They can be used to set the file timestamp. The file timestamp information is available in devices with the FAT file system, it is not supported for non-FAT volumes.

Function Documentation

◆ fs_get_time()

fsStatus fs_get_time ( fsTime time)

Callback function used to provide the current date and time to the File System.

Parameters
[out]timePointer to the fsTime structure.
Returns
execution status fsStatus
  • fsOK = Operation successful.
  • fsError = Failed to get the current time
Note
This function supports FAT drives only.

The function fs_get_time function returns a time value.

The argument time is a pointer to the values of the hour, minute, second, day, month, and year in a fsTime structure.

Code Example

..
// Real time should be read from the RTC
..
// Fill the FS_TIME structure with the time information
time->hr = 12; // Hours: 0 - 23
time->min = 0; // Minutes: 0 - 59
time->sec = 0; // Seconds: 0 - 59
time->day = 1; // Day: 1 - 31
time->mon = 1; // Month: 1 - 12
time->year = 2013; // Year: 1980 - 2107
return (fsOK);
}

◆ ftime_get()

fsStatus ftime_get ( const char *  path,
fsTime create,
fsTime access,
fsTime write 
)

Get file or directory timestamp.

Parameters
[in]pathstring specifying the file or directory path.
[out]createfsTime structure for storing the create time.
[out]accessfsTime structure for storing the last access time.
[out]writefsTime structure for storing the last write time.
Returns
execution status fsStatus
Note
This function supports FAT drives only.

The function ftime_get retrieves the file or directory timestamp information.

The path argument is specifying the file or directory path. If the drive prefix is omitted, the Current Drive is used.

The argument create is specifying a pointer to the fsTime structure where the create time will be stored and can be NULL.

The argument access is specifying a pointer to the fsTime structure where the last access time will be stored and can be NULL.

The argument write is specifying a pointer to the fsTime structure where the last write time will be stored and can be NULL.

The timestamp of the corresponding argument is not retrieved if that argument equals to NULL.

Note
This function supports FAT drives only.
FAT last access timestamp only stores date and therefore the time members (hour, min, sec) in the fsTime structure will be set to 0 (zero).

Code Example

void get_timestamp (void) {
fsTime create, access, write;
// Get the timestamps
if (ftime_get ("file.txt", &create, &access, &write) == fsOK) {
printf ("File create, last access and last write time were successfully retrieved.\n");
//Output the file create time and date information
printf ("Create Time: %d:%d:%d, %d.%d.%d\n", create.hr, create.min, create.sec, \
create.day, create.mon, create.year);
}
else {
printf ("Failed to get the file timestamp.\n");
}
}

◆ ftime_set()

fsStatus ftime_set ( const char *  path,
fsTime create,
fsTime access,
fsTime write 
)

Set file or directory timestamp.

Parameters
[in]pathstring specifying the file or directory path.
[in]createfsTime structure specifying the create time.
[in]accessfsTime structure specifying the last access time.
[in]writefsTime structure specifying the last write time.
Returns
execution status fsStatus
Note
This function supports FAT drives only.

The function ftime_set sets the file or directory timestamp information.

The path argument is specifying the file or directory path. If the drive prefix is omitted, the Current Drive is used.

The argument create is specifying a pointer to the fsTime structure containing the create time and can be NULL.

The argument access is specifying a pointer to the fsTime structure containing the last access time and can be NULL.

The argument write is specifying a pointer to the fsTime structure containing the last write time and can be NULL.

The timestamp of the corresponding argument is not modified if that argument equals to NULL.

Note
This function supports FAT drives only.
FAT last access timestamp only stores date and therefore the time members (hour, min, sec) in the fsTime structure are ignored.

Code Example

void set_timestamp (void) {
fsTime timedate;
// Set time and date
timedate.hr = 17;
timedate.min = 30;
timedate.sec = 2;
timedate.day = 25;
timedate.mon = 10;
timedate.year = 2019;
// Modify the timestamps
if (ftime_set ("file.txt", &timedate, &timedate, &timedate) == fsOK) {
printf ("File create, last access and last write time were successfully modified.\n");
}
else {
printf ("Failed to set the file timestamp.\n");
}
}