]> git.sesse.net Git - bcachefs-tools-debian/blob - c_src/include/linux/time64.h
rust: bump rpassword to v7.x
[bcachefs-tools-debian] / c_src / include / linux / time64.h
1 #ifndef _LINUX_TIME64_H
2 #define _LINUX_TIME64_H
3
4 #include <linux/types.h>
5
6 #define timespec64  timespec
7
8 typedef __s64 time64_t;
9
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
18
19 static inline struct timespec ns_to_timespec(const u64 nsec)
20 {
21         return (struct timespec) {
22                 .tv_sec = nsec / NSEC_PER_SEC,
23                 .tv_nsec = nsec % NSEC_PER_SEC,
24         };
25 }
26
27 static inline s64 timespec_to_ns(const struct timespec *ts)
28 {
29         return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
30 }
31
32 static inline struct timespec timespec_trunc(struct timespec t, unsigned gran)
33 {
34         /* Avoid division in the common cases 1 ns and 1 s. */
35         if (gran == 1) {
36                 /* nothing */
37         } else if (gran == NSEC_PER_SEC) {
38                 t.tv_nsec = 0;
39         } else if (gran > 1 && gran < NSEC_PER_SEC) {
40                 t.tv_nsec -= t.tv_nsec % gran;
41         } else {
42                 WARN(1, "illegal file time granularity: %u", gran);
43         }
44         return t;
45 }
46
47 #define ns_to_timespec64        ns_to_timespec
48 #define timespec64_to_ns        timespec_to_ns
49 #define timespec64_trunc        timespec_trunc
50
51 #endif /* _LINUX_TIME64_H */