summaryrefslogtreecommitdiff
path: root/firmware/common/file.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/common/file.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/common/file.c')
-rw-r--r--firmware/common/file.c38
1 files changed, 38 insertions, 0 deletions
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:
1123 return rc; 1123 return rc;
1124} 1124}
1125 1125
1126int utime(const char *path, const struct utimbuf* times)
1127{
1128 DEBUGF("utime(path=\"%s\",times->modtime=%u)\n", path, times->modtime);
1129
1130 int rc, open1rc = -1;
1131 struct filestr_base pathstr;
1132 struct path_component_info pathinfo;
1133
1134 file_internal_lock_WRITER();
1135
1136 if (!times)
1137 FILE_ERROR(EINVAL, -1);
1138
1139 open1rc = open_stream_internal(path, FF_ANYTYPE | FF_PARENTINFO,
1140 &pathstr, &pathinfo);
1141 if (open1rc <= 0)
1142 {
1143 DEBUGF("Failed opening path: %d\n", open1rc);
1144 if (open1rc == 0)
1145 FILE_ERROR(ENOENT, -2);
1146 else
1147 FILE_ERROR(ERRNO, open1rc * 10 - 1);
1148 }
1149
1150 rc = fat_utime(&pathinfo.parentinfo.fatfile, pathstr.fatstr.fatfilep,
1151 times);
1152 if (rc < 0)
1153 {
1154 DEBUGF("I/O error during utime: %d\n", rc);
1155 FILE_ERROR(ERRNO, rc * 10 - 2);
1156 }
1157
1158file_error:
1159 if (open1rc >= 0)
1160 close_stream_internal(&pathstr);
1161 file_internal_unlock_WRITER();
1162 return rc;
1163}
1126 1164
1127/** Extensions **/ 1165/** Extensions **/
1128 1166