diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index fd3ff8aa..bdc3c93e 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -168,14 +168,14 @@ typedef enum FsWriteOption_Flush = BIT(0), ///< Forces a flush after write. } FsWriteOption; -typedef enum -{ - FsStorageId_None = 0, - FsStorageId_Host = 1, - FsStorageId_GameCard = 2, - FsStorageId_NandSystem = 3, - FsStorageId_NandUser = 4, - FsStorageId_SdCard = 5, +/// StorageId +typedef enum { + FsStorageId_None = 0, ///< None + FsStorageId_Host = 1, ///< Host + FsStorageId_GameCard = 2, ///< GameCard + FsStorageId_NandSystem = 3, ///< NandSystem + FsStorageId_NandUser = 4, ///< NandUser + FsStorageId_SdCard = 5, ///< SdCard } FsStorageId; typedef enum diff --git a/nx/include/switch/services/time.h b/nx/include/switch/services/time.h index da3d644f..a76ebd25 100644 --- a/nx/include/switch/services/time.h +++ b/nx/include/switch/services/time.h @@ -65,8 +65,8 @@ Result timeLoadLocationNameList(u32 index, TimeLocationName *location_name_array Result timeLoadTimeZoneRule(const TimeLocationName *name, TimeZoneRule *rule); -Result timeToPosixTime(const TimeZoneRule *rule, const TimeCalendarTime *caltime, u64 *timestamp_list, size_t timestamp_list_size, u32 *timestamp_count); -Result timeToPosixTimeWithMyRule(const TimeCalendarTime *caltime, u64 *timestamp_list, size_t timestamp_list_size, u32 *timestamp_count); +Result timeToPosixTime(const TimeZoneRule *rule, const TimeCalendarTime *caltime, u64 *timestamp_list, size_t timestamp_list_count, u32 *timestamp_count); +Result timeToPosixTimeWithMyRule(const TimeCalendarTime *caltime, u64 *timestamp_list, size_t timestamp_list_count, u32 *timestamp_count); Result timeToCalendarTime(const TimeZoneRule *rule, u64 timestamp, TimeCalendarTime *caltime, TimeCalendarAdditionalInfo *info); Result timeToCalendarTimeWithMyRule(u64 timestamp, TimeCalendarTime *caltime, TimeCalendarAdditionalInfo *info); diff --git a/nx/source/runtime/devices/fs_dev.c b/nx/source/runtime/devices/fs_dev.c index e02a8c0f..84d642df 100644 --- a/nx/source/runtime/devices/fs_dev.c +++ b/nx/source/runtime/devices/fs_dev.c @@ -7,10 +7,12 @@ #include #include #include +#include #include "runtime/devices/fs_dev.h" #include "runtime/util/utf.h" #include "services/fs.h" +#include "services/time.h" /*! @internal @@ -256,6 +258,28 @@ static ssize_t fsdev_convertfromfspath(uint8_t *out, uint8_t *in, size_t len) return strnlen((char*)out, len); } +static time_t fsdev_converttimetoutc(u64 timestamp) +{ + // Parse timestamp into y/m/d h:m:s + time_t posixtime = (time_t)timestamp; + struct tm *t = gmtime(&posixtime); + + // Convert time/date into an actual UTC POSIX timestamp using the system's timezone rules + TimeCalendarTime caltime; + caltime.year = 1900 + t->tm_year; + caltime.month = 1 + t->tm_mon; + caltime.day = t->tm_mday; + caltime.hour = t->tm_hour; + caltime.minute = t->tm_min; + caltime.second = t->tm_sec; + u64 new_timestamp; + Result rc = timeToPosixTimeWithMyRule(&caltime, &new_timestamp, 1, NULL); + if (R_SUCCEEDED(rc)) + posixtime = (time_t)new_timestamp; + + return posixtime; +} + extern int __system_argc; extern char** __system_argv; @@ -965,9 +989,9 @@ fsdev_fstat(struct _reent *r, if(file->timestamps.is_valid) { - st->st_ctime = file->timestamps.created; - st->st_mtime = file->timestamps.modified; - st->st_atime = file->timestamps.accessed; + st->st_ctime = fsdev_converttimetoutc(file->timestamps.created); + st->st_mtime = fsdev_converttimetoutc(file->timestamps.modified); + st->st_atime = fsdev_converttimetoutc(file->timestamps.accessed); } return 0; @@ -1030,9 +1054,9 @@ fsdev_stat(struct _reent *r, rc = fsFsGetFileTimeStampRaw(&device->fs, fs_path, ×tamps); if(R_SUCCEEDED(rc) && timestamps.is_valid) { - st->st_ctime = timestamps.created; - st->st_mtime = timestamps.modified; - st->st_atime = timestamps.accessed; + st->st_ctime = fsdev_converttimetoutc(timestamps.created); + st->st_mtime = fsdev_converttimetoutc(timestamps.modified); + st->st_atime = fsdev_converttimetoutc(timestamps.accessed); } } diff --git a/nx/source/services/time.c b/nx/source/services/time.c index 4e18c4d3..5e4b8531 100644 --- a/nx/source/services/time.c +++ b/nx/source/services/time.c @@ -440,11 +440,14 @@ Result timeToCalendarTimeWithMyRule(u64 timestamp, TimeCalendarTime *caltime, Ti return rc; } -Result timeToPosixTime(const TimeZoneRule *rule, const TimeCalendarTime *caltime, u64 *timestamp_list, size_t timestamp_list_size, u32 *timestamp_count) { +Result timeToPosixTime(const TimeZoneRule *rule, const TimeCalendarTime *caltime, u64 *timestamp_list, size_t timestamp_list_count, u32 *timestamp_count) { + if (!serviceIsActive(&g_timeTimeZoneService)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + IpcCommand c; ipcInitialize(&c); ipcAddSendBuffer(&c, rule, sizeof(TimeZoneRule), BufferType_Normal); - ipcAddRecvStatic(&c, timestamp_list, timestamp_list_size, 0); + ipcAddRecvStatic(&c, timestamp_list, sizeof(u64)*timestamp_list_count, 0); struct { u64 magic; @@ -478,10 +481,13 @@ Result timeToPosixTime(const TimeZoneRule *rule, const TimeCalendarTime *caltime return rc; } -Result timeToPosixTimeWithMyRule(const TimeCalendarTime *caltime, u64 *timestamp_list, size_t timestamp_list_size, u32 *timestamp_count) { +Result timeToPosixTimeWithMyRule(const TimeCalendarTime *caltime, u64 *timestamp_list, size_t timestamp_list_count, u32 *timestamp_count) { + if (!serviceIsActive(&g_timeTimeZoneService)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + IpcCommand c; ipcInitialize(&c); - ipcAddRecvStatic(&c, timestamp_list, timestamp_list_size, 0); + ipcAddRecvStatic(&c, timestamp_list, sizeof(u64)*timestamp_list_count, 0); struct { u64 magic;