1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _LINUX_TIME_H
31da177e4SLinus Torvalds #define _LINUX_TIME_H
41da177e4SLinus Torvalds
582644459SThomas Gleixner # include <linux/cache.h>
6f595ec96SJeremy Fitzhardinge # include <linux/math64.h>
7361a3bf0SJohn Stultz # include <linux/time64.h>
81da177e4SLinus Torvalds
9b418da16SChristoph Hellwig extern struct timezone sys_tz;
10b418da16SChristoph Hellwig
11f59dd9c8SDeepa Dinamani int get_timespec64(struct timespec64 *ts,
12ea2ce8f3SDeepa Dinamani const struct __kernel_timespec __user *uts);
13f59dd9c8SDeepa Dinamani int put_timespec64(const struct timespec64 *ts,
14ea2ce8f3SDeepa Dinamani struct __kernel_timespec __user *uts);
15d5b7ffbfSDeepa Dinamani int get_itimerspec64(struct itimerspec64 *it,
16d0dd63a8SDeepa Dinamani const struct __kernel_itimerspec __user *uit);
17d5b7ffbfSDeepa Dinamani int put_itimerspec64(const struct itimerspec64 *it,
18d0dd63a8SDeepa Dinamani struct __kernel_itimerspec __user *uit);
19f59dd9c8SDeepa Dinamani
2090b6ce9cSpang.xunlei extern time64_t mktime64(const unsigned int year, const unsigned int mon,
21f4818900SIngo Molnar const unsigned int day, const unsigned int hour,
22f4818900SIngo Molnar const unsigned int min, const unsigned int sec);
23f4818900SIngo Molnar
24ddbc7d06SArnd Bergmann #ifdef CONFIG_POSIX_TIMERS
25ddbc7d06SArnd Bergmann extern void clear_itimer(void);
26ddbc7d06SArnd Bergmann #else
clear_itimer(void)27ddbc7d06SArnd Bergmann static inline void clear_itimer(void) {}
28ddbc7d06SArnd Bergmann #endif
291da177e4SLinus Torvalds
30aaed2dd8SDeepa Dinamani extern long do_utimes(int dfd, const char __user *filename, struct timespec64 *times, int flags);
311da177e4SLinus Torvalds
3257f1f087SZhaolei /*
3357f1f087SZhaolei * Similar to the struct tm in userspace <time.h>, but it needs to be here so
3457f1f087SZhaolei * that the kernel source is self contained.
3557f1f087SZhaolei */
3657f1f087SZhaolei struct tm {
3757f1f087SZhaolei /*
3857f1f087SZhaolei * the number of seconds after the minute, normally in the range
3957f1f087SZhaolei * 0 to 59, but can be up to 60 to allow for leap seconds
4057f1f087SZhaolei */
4157f1f087SZhaolei int tm_sec;
4257f1f087SZhaolei /* the number of minutes after the hour, in the range 0 to 59*/
4357f1f087SZhaolei int tm_min;
4457f1f087SZhaolei /* the number of hours past midnight, in the range 0 to 23 */
4557f1f087SZhaolei int tm_hour;
4657f1f087SZhaolei /* the day of the month, in the range 1 to 31 */
4757f1f087SZhaolei int tm_mday;
4857f1f087SZhaolei /* the number of months since January, in the range 0 to 11 */
4957f1f087SZhaolei int tm_mon;
5057f1f087SZhaolei /* the number of years since 1900 */
5157f1f087SZhaolei long tm_year;
5257f1f087SZhaolei /* the number of days since Sunday, in the range 0 to 6 */
5357f1f087SZhaolei int tm_wday;
5457f1f087SZhaolei /* the number of days since January 1, in the range 0 to 365 */
5557f1f087SZhaolei int tm_yday;
5657f1f087SZhaolei };
5757f1f087SZhaolei
58e6c2682aSDeepa Dinamani void time64_to_tm(time64_t totalsecs, int offset, struct tm *result);
59e6c2682aSDeepa Dinamani
605dbf2012SArnd Bergmann # include <linux/time32.h>
618b3d1cdaSH. Peter Anvin
itimerspec64_valid(const struct itimerspec64 * its)62d5b7ffbfSDeepa Dinamani static inline bool itimerspec64_valid(const struct itimerspec64 *its)
63d5b7ffbfSDeepa Dinamani {
64d5b7ffbfSDeepa Dinamani if (!timespec64_valid(&(its->it_interval)) ||
65d5b7ffbfSDeepa Dinamani !timespec64_valid(&(its->it_value)))
66d5b7ffbfSDeepa Dinamani return false;
67d5b7ffbfSDeepa Dinamani
68d5b7ffbfSDeepa Dinamani return true;
69d5b7ffbfSDeepa Dinamani }
70d5b7ffbfSDeepa Dinamani
71b5f51573SAndreas Dilger /**
72b5f51573SAndreas Dilger * time_after32 - compare two 32-bit relative times
73b5f51573SAndreas Dilger * @a: the time which may be after @b
74b5f51573SAndreas Dilger * @b: the time which may be before @a
75b5f51573SAndreas Dilger *
76b5f51573SAndreas Dilger * time_after32(a, b) returns true if the time @a is after time @b.
77b5f51573SAndreas Dilger * time_before32(b, a) returns true if the time @b is before time @a.
78b5f51573SAndreas Dilger *
79b5f51573SAndreas Dilger * Similar to time_after(), compare two 32-bit timestamps for relative
80b5f51573SAndreas Dilger * times. This is useful for comparing 32-bit seconds values that can't
81b5f51573SAndreas Dilger * be converted to 64-bit values (e.g. due to disk format or wire protocol
82b5f51573SAndreas Dilger * issues) when it is known that the times are less than 68 years apart.
83b5f51573SAndreas Dilger */
84b5f51573SAndreas Dilger #define time_after32(a, b) ((s32)((u32)(b) - (u32)(a)) < 0)
85b5f51573SAndreas Dilger #define time_before32(b, a) time_after32(a, b)
8604d26e7bSGuillaume Nault
8704d26e7bSGuillaume Nault /**
8804d26e7bSGuillaume Nault * time_between32 - check if a 32-bit timestamp is within a given time range
8904d26e7bSGuillaume Nault * @t: the time which may be within [l,h]
9004d26e7bSGuillaume Nault * @l: the lower bound of the range
9104d26e7bSGuillaume Nault * @h: the higher bound of the range
9204d26e7bSGuillaume Nault *
9304d26e7bSGuillaume Nault * time_before32(t, l, h) returns true if @l <= @t <= @h. All operands are
9404d26e7bSGuillaume Nault * treated as 32-bit integers.
9504d26e7bSGuillaume Nault *
9604d26e7bSGuillaume Nault * Equivalent to !(time_before32(@t, @l) || time_after32(@t, @h)).
9704d26e7bSGuillaume Nault */
9804d26e7bSGuillaume Nault #define time_between32(t, l, h) ((u32)(h) - (u32)(l) >= (u32)(t) - (u32)(l))
99660fd04fSThomas Gleixner
100*639fff1cSVincenzo Frascino # include <vdso/time.h>
101660fd04fSThomas Gleixner
1021da177e4SLinus Torvalds #endif
103