kernel: scheduling fix for ARM
[minix.git] / lib / libhgfs / time.c
blob1dc80605691e0e0beff5edc1b4d3aa974f35d2cb
1 /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
3 #include "inc.h"
5 static u64_t time_offset;
7 /*===========================================================================*
8 * time_init *
9 *===========================================================================*/
10 void time_init(void)
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 /*===========================================================================*
25 * time_put *
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
31 * zero instead.
33 u64_t hgfstime;
35 if (tsp != NULL) {
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);
41 } else {
42 RPC_NEXT32 = 0;
43 RPC_NEXT32 = 0;
47 /*===========================================================================*
48 * time_get *
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.
56 u64_t hgfstime;
57 u32_t time_lo, time_hi;
59 if (tsp != NULL) {
60 time_lo = RPC_NEXT32;
61 time_hi = RPC_NEXT32;
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);