summaryrefslogtreecommitdiff
path: root/include/linux/time64.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2017-12-21 18:00:30 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2017-12-21 18:06:45 -0500
commit1cf4d51dc4661f336f5318c176a3561ddf5bf04f (patch)
tree8b390ccd48361ba1408be6799d46e62c6382cc39 /include/linux/time64.h
parent8acc54456e11ee0ec80ed0c6abb6d68abae60592 (diff)
Update bcachefs sources to 14ce2a2031 bcachefs: fixes for building in userspace
Diffstat (limited to 'include/linux/time64.h')
-rw-r--r--include/linux/time64.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/time64.h b/include/linux/time64.h
index 2d9f8291..870bdef4 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -204,4 +204,19 @@ static __always_inline void timespec64_add_ns(struct timespec64 *a, u64 ns)
extern struct timespec64 timespec64_add_safe(const struct timespec64 lhs,
const struct timespec64 rhs);
+static inline struct timespec timespec_trunc(struct timespec t, unsigned gran)
+{
+ /* Avoid division in the common cases 1 ns and 1 s. */
+ if (gran == 1) {
+ /* nothing */
+ } else if (gran == NSEC_PER_SEC) {
+ t.tv_nsec = 0;
+ } else if (gran > 1 && gran < NSEC_PER_SEC) {
+ t.tv_nsec -= t.tv_nsec % gran;
+ } else {
+ WARN(1, "illegal file time granularity: %u", gran);
+ }
+ return t;
+}
+
#endif /* _LINUX_TIME64_H */