summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Buren <braewoods+rb@braewoods.net>2021-07-03 00:19:58 +0000
committerJames Buren <braewoods+rb@braewoods.net>2021-07-03 00:19:58 +0000
commitc9f2308a1d4401ceefaac47b1ea851530d07e47d (patch)
tree81f75a26707bd8583f5117a7a0febba894787996
parentd1a92aafff55defefcb8cf8f4b045701325088b2 (diff)
downloadrockbox-c9f2308a1d.tar.gz
rockbox-c9f2308a1d.zip
fat: move fattime_mktime to timefuncs
This moves the time conversion function to timefuncs since it has uses on ports that don't use the FAT driver. This function has no dependency on the FAT driver as it is so this should not cause any issues. To reflect this separation the function was renamed to dostime_mktime since it is really for DOS timestamps. The places where it was used have also been updated. Change-Id: Id98b1448d5c6fcda286846e1d2c736db682bfb52
-rw-r--r--firmware/common/dir.c3
-rw-r--r--firmware/common/dircache.c2
-rw-r--r--firmware/common/timefuncs.c14
-rw-r--r--firmware/drivers/fat.c14
-rw-r--r--firmware/export/fat.h1
-rw-r--r--firmware/include/timefuncs.h2
6 files changed, 19 insertions, 17 deletions
diff --git a/firmware/common/dir.c b/firmware/common/dir.c
index f89129ae34..245947b134 100644
--- a/firmware/common/dir.c
+++ b/firmware/common/dir.c
@@ -26,6 +26,7 @@
#include "debug.h"
#include "dir.h"
#include "pathfuncs.h"
+#include "timefuncs.h"
#include "fileobj_mgr.h"
#include "dircache_redirect.h"
@@ -406,7 +407,7 @@ struct dirinfo dir_get_info(DIR *dirp, struct dirent *entry)
{
.attribute = entry->info.attr,
.size = entry->info.size,
- .mtime = fattime_mktime(entry->info.wrtdate, entry->info.wrttime),
+ .mtime = dostime_mktime(entry->info.wrtdate, entry->info.wrttime),
};
file_error:
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c
index 589986911c..3b880d3382 100644
--- a/firmware/common/dircache.c
+++ b/firmware/common/dircache.c
@@ -2956,7 +2956,7 @@ void dircache_dump(void)
FOR_EACH_CACHE_ENTRY(ce)
{
#ifdef DIRCACHE_NATIVE
- time_t mtime = fattime_mktime(ce->wrtdate, ce->wrttime);
+ time_t mtime = dostime_mktime(ce->wrtdate, ce->wrttime);
#else
time_t mtime = ce->mtime;
#endif
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index 108431753a..d87e6b67f2 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -32,6 +32,20 @@
static struct tm tm;
+time_t dostime_mktime(uint16_t dosdate, uint16_t dostime)
+{
+ /* this knows our mktime() only uses these struct tm fields */
+ struct tm tm;
+ tm.tm_sec = ((dostime ) & 0x1f) * 2;
+ tm.tm_min = ((dostime >> 5) & 0x3f);
+ tm.tm_hour = ((dostime >> 11) );
+ tm.tm_mday = ((dosdate ) & 0x1f);
+ tm.tm_mon = ((dosdate >> 5) & 0x0f) - 1;
+ tm.tm_year = ((dosdate >> 9) ) + 80;
+
+ return mktime(&tm);
+}
+
#if !CONFIG_RTC
static inline bool rtc_dirty(void)
{
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 337e29a1bc..cc9735d0f7 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -2954,20 +2954,6 @@ void fat_empty_fat_direntry(struct fat_direntry *entry)
entry->firstcluster = 0;
}
-time_t fattime_mktime(uint16_t fatdate, uint16_t fattime)
-{
- /* this knows our mktime() only uses these struct tm fields */
- struct tm tm;
- tm.tm_sec = ((fattime ) & 0x1f) * 2;
- tm.tm_min = ((fattime >> 5) & 0x3f);
- tm.tm_hour = ((fattime >> 11) );
- tm.tm_mday = ((fatdate ) & 0x1f);
- tm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
- tm.tm_year = ((fatdate >> 9) ) + 80;
-
- return mktime(&tm);
-}
-
void fat_init(void)
{
dc_lock_cache();
diff --git a/firmware/export/fat.h b/firmware/export/fat.h
index b8092290e6..27c2a161f6 100644
--- a/firmware/export/fat.h
+++ b/firmware/export/fat.h
@@ -174,7 +174,6 @@ void fat_recalc_free(IF_MV_NONVOID(int volume));
bool fat_size(IF_MV(int volume,) unsigned long *size, unsigned long *free);
/** Misc. **/
-time_t fattime_mktime(uint16_t fatdate, uint16_t fattime);
void fat_empty_fat_direntry(struct fat_direntry *entry);
void fat_init(void);
diff --git a/firmware/include/timefuncs.h b/firmware/include/timefuncs.h
index c72508e862..2e8ef01ca6 100644
--- a/firmware/include/timefuncs.h
+++ b/firmware/include/timefuncs.h
@@ -24,8 +24,10 @@
#include "config.h"
#include <stdbool.h>
+#include <stdint.h>
#include "time.h"
+time_t dostime_mktime(uint16_t dosdate, uint16_t dostime);
struct tm *get_time(void);
int set_time(const struct tm *tm);
#if CONFIG_RTC