From a9f36efa62c0f095994e2a711a689b3b3e81aea2 Mon Sep 17 00:00:00 2001 From: James Buren Date: Thu, 8 Jul 2021 17:45:57 +0000 Subject: file/fat: rework utime function as modtime extension This eliminates the dependence on a special struct since we were only using the modtime anyway. But it no longer fits any known standard APIs so I have converted it to our own extension instead. This can still be adapted to existing hosted APIs if the need arises. Change-Id: Ic8800698ddfd3a1a48b7cf921c0d0f865302d034 --- firmware/common/file.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'firmware/common') diff --git a/firmware/common/file.c b/firmware/common/file.c index c090c40be5..c048d182f4 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -1123,9 +1123,11 @@ file_error: return rc; } -int utime(const char *path, const struct utimbuf* times) +/** Extensions **/ + +int modtime(const char *path, time_t modtime) { - DEBUGF("utime(path=\"%s\",times->modtime=%u)\n", path, times->modtime); + DEBUGF("modtime(path=\"%s\",modtime=%d)\n", path, (int) modtime); int rc, open1rc = -1; struct filestr_base pathstr; @@ -1133,25 +1135,22 @@ int utime(const char *path, const struct utimbuf* times) file_internal_lock_WRITER(); - if (!times) - FILE_ERROR(EINVAL, -1); - open1rc = open_stream_internal(path, FF_ANYTYPE | FF_PARENTINFO, &pathstr, &pathinfo); if (open1rc <= 0) { DEBUGF("Failed opening path: %d\n", open1rc); if (open1rc == 0) - FILE_ERROR(ENOENT, -2); + FILE_ERROR(ENOENT, -1); else FILE_ERROR(ERRNO, open1rc * 10 - 1); } - rc = fat_utime(&pathinfo.parentinfo.fatfile, pathstr.fatstr.fatfilep, - times); + rc = fat_modtime(&pathinfo.parentinfo.fatfile, pathstr.fatstr.fatfilep, + modtime); if (rc < 0) { - DEBUGF("I/O error during utime: %d\n", rc); + DEBUGF("I/O error during modtime: %d\n", rc); FILE_ERROR(ERRNO, rc * 10 - 2); } @@ -1162,8 +1161,6 @@ file_error: return rc; } -/** Extensions **/ - /* get the binary size of a file (in bytes) */ off_t filesize(int fildes) { -- cgit v1.2.3