1 #ifndef _LINUX_TIME64_H
2 #define _LINUX_TIME64_H
4 #include <linux/types.h>
6 #define timespec64 timespec
8 typedef __s64 time64_t;
10 /* Parameters used to convert the timespec values: */
11 #define MSEC_PER_SEC 1000L
12 #define USEC_PER_MSEC 1000L
13 #define NSEC_PER_USEC 1000L
14 #define NSEC_PER_MSEC 1000000L
15 #define USEC_PER_SEC 1000000L
16 #define NSEC_PER_SEC 1000000000L
17 #define FSEC_PER_SEC 1000000000000000LL
19 static inline struct timespec ns_to_timespec(const u64 nsec)
21 return (struct timespec) {
22 .tv_sec = nsec / NSEC_PER_SEC,
23 .tv_nsec = nsec % NSEC_PER_SEC,
27 static inline s64 timespec_to_ns(const struct timespec *ts)
29 return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
32 static inline struct timespec timespec_trunc(struct timespec t, unsigned gran)
34 /* Avoid division in the common cases 1 ns and 1 s. */
37 } else if (gran == NSEC_PER_SEC) {
39 } else if (gran > 1 && gran < NSEC_PER_SEC) {
40 t.tv_nsec -= t.tv_nsec % gran;
42 WARN(1, "illegal file time granularity: %u", gran);
47 #define ns_to_timespec64 ns_to_timespec
48 #define timespec64_to_ns timespec_to_ns
49 #define timespec64_trunc timespec_trunc
51 #endif /* _LINUX_TIME64_H */