From c174d3a544b92be55bc0d09443522386363129f5 Mon Sep 17 00:00:00 2001 From: James Buren Date: Wed, 7 Jul 2021 21:06:31 +0000 Subject: file/fat: add utime function This emulates the traditional utime function from UNIX clones to allow for manual updates of the modification timestamp on files and directories. This should only prove useful for non-native targets as those usually have a libc version of utime. Change-Id: Iea8a1d328e78b92c400d3354ee80689c7cf53af8 --- firmware/common/file.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'firmware/common/file.c') diff --git a/firmware/common/file.c b/firmware/common/file.c index cb918c6eab..c090c40be5 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -1123,6 +1123,44 @@ file_error: return rc; } +int utime(const char *path, const struct utimbuf* times) +{ + DEBUGF("utime(path=\"%s\",times->modtime=%u)\n", path, times->modtime); + + int rc, open1rc = -1; + struct filestr_base pathstr; + struct path_component_info pathinfo; + + 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); + else + FILE_ERROR(ERRNO, open1rc * 10 - 1); + } + + rc = fat_utime(&pathinfo.parentinfo.fatfile, pathstr.fatstr.fatfilep, + times); + if (rc < 0) + { + DEBUGF("I/O error during utime: %d\n", rc); + FILE_ERROR(ERRNO, rc * 10 - 2); + } + +file_error: + if (open1rc >= 0) + close_stream_internal(&pathstr); + file_internal_unlock_WRITER(); + return rc; +} /** Extensions **/ -- cgit v1.2.3