From 22654a4de71a8a4411b2e217f51e88448f619c5c Mon Sep 17 00:00:00 2001 From: sheinz Date: Thu, 14 Jul 2016 16:13:03 +0300 Subject: [PATCH] SPIFFS: Support lseek, stat, fstat Support for lseek, stat, fstat added. Test extended to covert those functions. --- core/newlib_syscalls.c | 7 +++++-- examples/posix_fs/fs-test | 2 +- extras/spiffs/esp_spiffs.c | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/core/newlib_syscalls.c b/core/newlib_syscalls.c index c8104a9..577ecda 100644 --- a/core/newlib_syscalls.c +++ b/core/newlib_syscalls.c @@ -88,10 +88,13 @@ int _close_r(struct _reent *r, int fd); __attribute__((weak, alias("syscall_returns_enosys"))) int _unlink_r(struct _reent *r, const char *path); -__attribute__((alias("syscall_returns_enosys"))) +__attribute__((weak, alias("syscall_returns_enosys"))) int _fstat_r(struct _reent *r, int fd, void *buf); -__attribute__((alias("syscall_returns_enosys"))) +__attribute__((weak, alias("syscall_returns_enosys"))) +int _stat_r(struct _reent *r, const char *pathname, void *buf); + +__attribute__((weak, alias("syscall_returns_enosys"))) off_t _lseek_r(struct _reent *r, int fd, off_t offset, int whence); /* Generic stub for any newlib syscall that fails with errno ENOSYS diff --git a/examples/posix_fs/fs-test b/examples/posix_fs/fs-test index 218c523..12b1023 160000 --- a/examples/posix_fs/fs-test +++ b/examples/posix_fs/fs-test @@ -1 +1 @@ -Subproject commit 218c5235584429f407d619e5e35f90732ad505f3 +Subproject commit 12b10230cc56970857e6890bdd5663fbae74c4c3 diff --git a/extras/spiffs/esp_spiffs.c b/extras/spiffs/esp_spiffs.c index 4b5ef77..72419a1 100644 --- a/extras/spiffs/esp_spiffs.c +++ b/extras/spiffs/esp_spiffs.c @@ -253,3 +253,30 @@ int _unlink_r(struct _reent *r, const char *path) { return SPIFFS_remove(&fs, path); } + +int _fstat_r(struct _reent *r, int fd, void *buf) +{ + spiffs_stat s; + struct stat *sb = (struct stat*)buf; + + int result = SPIFFS_fstat(&fs, (spiffs_file)(fd - FD_OFFSET), &s); + sb->st_size = s.size; + + return result; +} + +int _stat_r(struct _reent *r, const char *pathname, void *buf) +{ + spiffs_stat s; + struct stat *sb = (struct stat*)buf; + + int result = SPIFFS_stat(&fs, pathname, &s); + sb->st_size = s.size; + + return result; +} + +off_t _lseek_r(struct _reent *r, int fd, off_t offset, int whence) +{ + return SPIFFS_lseek(&fs, (spiffs_file)(fd - FD_OFFSET), offset, whence); +}