summaryrefslogtreecommitdiff
path: root/firmware/drivers/fat.c
diff options
context:
space:
mode:
authorJames Buren <braewoods+rb@braewoods.net>2021-07-07 21:06:31 +0000
committerSolomon Peachy <pizza@shaftnet.org>2021-07-08 13:15:30 +0000
commitc174d3a544b92be55bc0d09443522386363129f5 (patch)
treec0462544de28dff56285a55ff2824daee06c0f34 /firmware/drivers/fat.c
parente6ee3dd17cf040cf38c8751c99edaec67f7a5ab5 (diff)
downloadrockbox-c174d3a544b92be55bc0d09443522386363129f5.tar.gz
rockbox-c174d3a544b92be55bc0d09443522386363129f5.zip
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
Diffstat (limited to 'firmware/drivers/fat.c')
-rw-r--r--firmware/drivers/fat.c35
1 files changed, 35 insertions, 0 deletions
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:
2276 return rc; 2276 return rc;
2277} 2277}
2278 2278
2279int fat_utime(struct fat_file *parent, struct fat_file *file,
2280 const struct utimbuf *times)
2281{
2282 struct bpb * const fat_bpb = FAT_BPB(parent->volume);
2283
2284 if (!fat_bpb)
2285 return -1;
2286
2287 int rc;
2288
2289 struct fat_filestr parentstr;
2290 fat_filestr_init(&parentstr, parent);
2291
2292 dc_lock_cache();
2293
2294 union raw_dirent *ent = cache_direntry(fat_bpb, &parentstr, file->e.entry);
2295 if (!ent)
2296 FAT_ERROR(-2);
2297
2298 uint16_t date;
2299 uint16_t time;
2300 dostime_localtime(times->modtime, &date, &time);
2301
2302 ent->wrttime = htole16(time);
2303 ent->wrtdate = htole16(date);
2304 ent->lstaccdate = htole16(date);
2305
2306 dc_dirty_buf(ent);
2307
2308 rc = 0;
2309fat_error:
2310 dc_unlock_cache();
2311 cache_commit(fat_bpb);
2312 return rc;
2313}
2279 2314
2280/** File stream functions **/ 2315/** File stream functions **/
2281 2316