1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */ 2 3 #include "inc.h" 4 5 static u64_t time_offset; 6 7 /*===========================================================================* 8 * time_init * 9 *===========================================================================*/ 10 void time_init(void) 11 { 12 /* Initialize the time conversion module. 13 */ 14 15 /* Generate a 64-bit value for the offset to use in time conversion. The 16 * HGFS time format uses Windows' FILETIME standard, expressing time in 17 * 100ns-units since Jan 1, 1601 UTC. The value that is generated is 18 * the difference between that time and the UNIX epoch, in 100ns units. 19 */ 20 /* FIXME: we currently do not take into account timezones. */ 21 time_offset = (u64_t)116444736 * 1000000000; 22 } 23 24 /*===========================================================================* 25 * time_put * 26 *===========================================================================*/ 27 void time_put(struct timespec *tsp) 28 { 29 /* Store a POSIX timestamp pointed to by the given pointer onto the RPC buffer, 30 * in HGFS timestamp format. If a NULL pointer is given, store a timestamp of 31 * zero instead. 32 */ 33 u64_t hgfstime; 34 35 if (tsp != NULL) { 36 hgfstime = ((u64_t)tsp->tv_sec * 10000000) + (tsp->tv_nsec / 100); 37 hgfstime += time_offset; 38 39 RPC_NEXT32 = ex64lo(hgfstime); 40 RPC_NEXT32 = ex64hi(hgfstime); 41 } else { 42 RPC_NEXT32 = 0; 43 RPC_NEXT32 = 0; 44 } 45 } 46 47 /*===========================================================================* 48 * time_get * 49 *===========================================================================*/ 50 void time_get(struct timespec *tsp) 51 { 52 /* Get a HGFS timestamp from the RPC buffer, convert it into a POSIX timestamp, 53 * and store the result in the given time pointer. If the given pointer is 54 * NULL, however, simply skip over the timestamp in the RPC buffer. 55 */ 56 u64_t hgfstime; 57 u32_t time_lo, time_hi; 58 59 if (tsp != NULL) { 60 time_lo = RPC_NEXT32; 61 time_hi = RPC_NEXT32; 62 63 hgfstime = make64(time_lo, time_hi) - time_offset; 64 65 tsp->tv_sec = (unsigned long)(hgfstime / 10000000); 66 tsp->tv_nsec = (unsigned)(hgfstime % 10000000) * 100; 67 } 68 else RPC_ADVANCE(sizeof(u32_t) * 2); 69 } 70