1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
5 static u64_t time_offset
;
7 /*===========================================================================*
9 *===========================================================================*/
12 /* Initialize the time conversion module.
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.
20 /* FIXME: we currently do not take into account timezones. */
21 time_offset
= mul64u(116444736, 1000000000);
24 /*===========================================================================*
26 *===========================================================================*/
27 void time_put(struct timespec
*tsp
)
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
36 hgfstime
= add64ul(mul64u(tsp
->tv_sec
, 10000000), tsp
->tv_nsec
/ 100);
37 hgfstime
= add64(hgfstime
, time_offset
);
39 RPC_NEXT32
= ex64lo(hgfstime
);
40 RPC_NEXT32
= ex64hi(hgfstime
);
47 /*===========================================================================*
49 *===========================================================================*/
50 void time_get(struct timespec
*tsp
)
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.
57 u32_t time_lo
, time_hi
;
63 hgfstime
= sub64(make64(time_lo
, time_hi
), time_offset
);
65 tsp
->tv_sec
= div64u(hgfstime
, 10000000);
66 tsp
->tv_nsec
= rem64u(hgfstime
, 10000000) * 100;
68 else RPC_ADVANCE(sizeof(u32_t
) * 2);