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/drivers/fat.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'firmware/drivers/fat.c') diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index cc9735d0f7..28d4eb1987 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -2276,6 +2276,41 @@ fat_error: return rc; } +int fat_utime(struct fat_file *parent, struct fat_file *file, + const struct utimbuf *times) +{ + struct bpb * const fat_bpb = FAT_BPB(parent->volume); + + if (!fat_bpb) + return -1; + + int rc; + + struct fat_filestr parentstr; + fat_filestr_init(&parentstr, parent); + + dc_lock_cache(); + + union raw_dirent *ent = cache_direntry(fat_bpb, &parentstr, file->e.entry); + if (!ent) + FAT_ERROR(-2); + + uint16_t date; + uint16_t time; + dostime_localtime(times->modtime, &date, &time); + + ent->wrttime = htole16(time); + ent->wrtdate = htole16(date); + ent->lstaccdate = htole16(date); + + dc_dirty_buf(ent); + + rc = 0; +fat_error: + dc_unlock_cache(); + cache_commit(fat_bpb); + return rc; +} /** File stream functions **/ -- cgit v1.2.3