adding file timestamps to file_status
This commit is contained in:
parent
15a8e2ae22
commit
a275b3da28
|
@ -85,6 +85,7 @@ void oc_clock_init()
|
|||
//RandomSeedFromDevice();
|
||||
}
|
||||
|
||||
/*
|
||||
u64 oc_clock_timestamp(oc_clock_kind clock)
|
||||
{
|
||||
u64 ts = 0;
|
||||
|
@ -120,16 +121,9 @@ u64 oc_clock_timestamp(oc_clock_kind clock)
|
|||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
//NOTE(martin): add a random fuzz between 0 and 1 times the system fuzz
|
||||
//TODO(martin): ensure that we always return a value greater than the last value
|
||||
f64 fuzz = RandomU32()/(f64)(~(0UL)) * OC_CLOCK_FUZZ;
|
||||
ts_timediff tdfuzz = TimediffFromSeconds(fuzz);
|
||||
ts = TimestampAdd(ts, tdfuzz);
|
||||
*/
|
||||
|
||||
return (ts);
|
||||
}
|
||||
*/
|
||||
|
||||
f64 oc_clock_time(oc_clock_kind clock)
|
||||
{
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
#include "util/typedefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
typedef enum
|
||||
|
@ -24,8 +23,10 @@ extern "C"
|
|||
OC_CLOCK_DATE // clock that is driven by the platform time
|
||||
} oc_clock_kind;
|
||||
|
||||
#if !defined(OC_PLATFORM_ORCA) || !OC_PLATFORM_ORCA
|
||||
ORCA_API void oc_clock_init(); // initialize the clock subsystem
|
||||
ORCA_API u64 oc_clock_timestamp(oc_clock_kind clock);
|
||||
#endif
|
||||
|
||||
ORCA_API f64 oc_clock_time(oc_clock_kind clock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -206,6 +206,13 @@ enum oc_file_perm
|
|||
OC_FILE_SET_UID = 1 << 11,
|
||||
};
|
||||
|
||||
typedef struct oc_datestamp
|
||||
{
|
||||
i64 seconds; // seconds relative to NTP epoch.
|
||||
u64 fraction; // fraction of seconds elapsed since the time specified by seconds.
|
||||
|
||||
} oc_datestamp;
|
||||
|
||||
typedef struct oc_file_status
|
||||
{
|
||||
u64 uid;
|
||||
|
@ -213,7 +220,9 @@ typedef struct oc_file_status
|
|||
oc_file_perm perm;
|
||||
u64 size;
|
||||
|
||||
//TODO times
|
||||
oc_datestamp creationDate;
|
||||
oc_datestamp accessDate;
|
||||
oc_datestamp modificationDate;
|
||||
|
||||
} oc_file_status;
|
||||
|
||||
|
|
|
@ -280,6 +280,17 @@ static oc_file_type oc_io_convert_type_from_stat(u16 mode)
|
|||
return (type);
|
||||
}
|
||||
|
||||
static const u64 OC_NTP_JAN_1970 = 2208988800ULL; // seconds from january 1900 to january 1970
|
||||
|
||||
oc_datestamp oc_datestamp_from_timespec(struct timespec ts)
|
||||
{
|
||||
oc_datestamp d = { 0 };
|
||||
d.seconds = ts.tv_sec + OC_NTP_JAN_1970;
|
||||
d.fraction = (ts.tv_nsec * (1ULL << 32)) / 1000000000;
|
||||
|
||||
return (d);
|
||||
}
|
||||
|
||||
oc_io_error oc_io_raw_fstat(oc_file_desc fd, oc_file_status* status)
|
||||
{
|
||||
oc_io_error error = OC_IO_OK;
|
||||
|
@ -294,7 +305,10 @@ oc_io_error oc_io_raw_fstat(oc_file_desc fd, oc_file_status* status)
|
|||
status->perm = oc_io_convert_perm_from_stat(s.st_mode);
|
||||
status->type = oc_io_convert_type_from_stat(s.st_mode);
|
||||
status->size = s.st_size;
|
||||
//TODO: times
|
||||
|
||||
status->creationDate = oc_datestamp_from_timespec(s.st_birthtimespec);
|
||||
status->accessDate = oc_datestamp_from_timespec(s.st_atimespec);
|
||||
status->modificationDate = oc_datestamp_from_timespec(s.st_mtimespec);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
|
|
@ -229,6 +229,36 @@ bool oc_io_raw_file_exists_at(oc_file_desc dirFd, oc_str8 path, oc_file_open_fla
|
|||
return (result);
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
OC_NTP_01_JAN_1601 = -9435484800LL,
|
||||
OC_WIN32_TICKS_PER_SECOND = 10000000LL
|
||||
};
|
||||
|
||||
oc_datestamp oc_datestamp_from_win32_filetime(FILETIME ft)
|
||||
{
|
||||
oc_datestamp d = { 0 };
|
||||
|
||||
i64 win32Ticks = (((u64)ft.high) << 32) | (u64)ft.low;
|
||||
|
||||
i64 win32Seconds = win32Ticks / OC_WIN32_TICKS_PER_SECOND;
|
||||
u64 win32Rem = 0;
|
||||
if(winTicks < 0)
|
||||
{
|
||||
win32Seconds -= OC_WIN32_TICKS_PER_SECOND;
|
||||
win32Rem = win32Ticks - seconds * OC_WIN32_TICKS_PER_SECOND;
|
||||
}
|
||||
else
|
||||
{
|
||||
win32Rem = win32Ticks % OC_WIN32_TICKS_PER_SECOND;
|
||||
}
|
||||
|
||||
d.seconds = win32Seconds + OC_NTP_01_JAN_1601;
|
||||
d.fraction = (win32Rem * (1ULL << 32)) / OC_WIN32_TICKS_PER_SECOND;
|
||||
|
||||
return (d);
|
||||
}
|
||||
|
||||
oc_io_error oc_io_raw_fstat(oc_file_desc fd, oc_file_status* status)
|
||||
{
|
||||
oc_io_error error = OC_IO_OK;
|
||||
|
@ -290,7 +320,16 @@ oc_io_error oc_io_raw_fstat(oc_file_desc fd, oc_file_status* status)
|
|||
{
|
||||
status->perm = OC_FILE_OWNER_WRITE | OC_FILE_GROUP_WRITE | OC_FILE_OTHER_WRITE;
|
||||
}
|
||||
//TODO: times
|
||||
|
||||
FILETIME win32CreationDate;
|
||||
FILETIME win32AccessDate;
|
||||
FILETIME win32ModificationDate;
|
||||
|
||||
GetFileTime(fd, &win32CreationDate, &win32AccessDate, &win32ModificationDate);
|
||||
|
||||
status->creationDate = oc_datestamp_from_win32_filetime(win32CreationDate);
|
||||
status->accessDate = oc_datestamp_from_win32_filetime(win32AccessDate);
|
||||
status->modificationDate = oc_datestamp_from_win32_filetime(win32ModificationDate);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue