diff --git a/CMakeLists.txt b/CMakeLists.txt index 146f9ef..91f14ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ target_include_directories(filesystem_vfs INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include ) target_compile_options(filesystem_vfs INTERFACE -Werror -Wall -Wextra -Wnull-dereference) -target_link_libraries(filesystem_vfs INTERFACE pico_sync) +target_link_libraries(filesystem_vfs INTERFACE pico_sync -Wl,--wrap=_ftello_r) # Default file system library add_library(filesystem_default INTERFACE) diff --git a/include/filesystem/filesystem.h b/include/filesystem/filesystem.h index decff94..4458642 100644 --- a/include/filesystem/filesystem.h +++ b/include/filesystem/filesystem.h @@ -17,10 +17,9 @@ extern "C" { #include #include #include +#include #include "blockdevice/blockdevice.h" -#define PATH_MAX 256 - enum { FILESYSTEM_TYPE_FAT, FILESYSTEM_TYPE_LITTLEFS, diff --git a/src/filesystem/fat.c b/src/filesystem/fat.c index 309183e..b772b2a 100644 --- a/src/filesystem/fat.c +++ b/src/filesystem/fat.c @@ -396,12 +396,22 @@ static int file_stat(filesystem_t *fs, const char *path, struct stat *st) { if (res != FR_OK) { return fat_error_remap(res); } + + struct tm mtime = {0}; + mtime.tm_year = (f.fdate >> 9) + 80; + mtime.tm_mon = ((f.fdate >> 5) & 0b1111) - 1; + mtime.tm_mday = f.fdate & 0b11111; + mtime.tm_hour = f.ftime >> 11; + mtime.tm_min = (f.ftime >> 5) & 0b111111; + mtime.tm_sec = (f.ftime & 0b11111) << 1; + st->st_size = f.fsize; st->st_mode = 0; st->st_mode |= (f.fattrib & AM_DIR) ? S_IFDIR : S_IFREG; st->st_mode |= (f.fattrib & AM_RDO) ? (S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) : (S_IRWXU | S_IRWXG | S_IRWXO); + st->st_mtime = mktime(&mtime); return 0; } diff --git a/src/filesystem/vfs.c b/src/filesystem/vfs.c index ebf4a67..7ded859 100644 --- a/src/filesystem/vfs.c +++ b/src/filesystem/vfs.c @@ -562,7 +562,7 @@ off_t _lseek(int fildes, off_t offset, int whence) { return _error_remap(pos); } -off_t _ftello_r(struct _reent *ptr, register FILE *fp) { +off_t __wrap__ftello_r(struct _reent *ptr, register FILE *fp) { (void)ptr; int fildes = fp->_file; auto_init_recursive_mutex(_mutex);