forked from cifsd-team/ksmbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_wrappers.h
70 lines (58 loc) · 1.65 KB
/
time_wrappers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2019 Samsung Electronics Co., Ltd.
*/
#ifndef __CIFSD_TIME_WRAPPERS_H
#define __CIFSD_TIME_WRAPPERS_H
/*
* A bunch of ugly hacks to workaoround all the API differences
* between different kernel versions.
*/
#define NTFS_TIME_OFFSET ((u64)(369*365 + 89) * 24 * 3600 * 10000000)
/* Convert the Unix UTC into NT UTC. */
static inline u64 cifs_UnixTimeToNT(struct timespec t)
{
/* Convert to 100ns intervals and then add the NTFS time offset. */
return (u64) t.tv_sec * 10000000 + t.tv_nsec / 100 + NTFS_TIME_OFFSET;
}
static inline struct timespec cifs_NTtimeToUnix(__le64 ntutc)
{
struct timespec ts;
u64 t;
/* Subtract the NTFS time offset, then convert to 1s intervals. */
t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
ts.tv_nsec = do_div(t, 10000000) * 100;
ts.tv_sec = t;
return ts;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
static inline struct timespec64 to_kern_timespec(struct timespec ts)
{
return timespec_to_timespec64(ts);
}
static inline struct timespec from_kern_timespec(struct timespec64 ts)
{
return timespec64_to_timespec(ts);
}
#else
#define to_kern_timespec(ts) (ts)
#define from_kern_timespec(ts) (ts)
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,20, 0)
#define CIFSD_TIME_TO_TM time64_to_tm
#else
#define CIFSD_TIME_TO_TM time_to_tm
#endif
static inline long long cifsd_systime(void)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
struct timespec64 ts;
getnstimeofday64(&ts);
return cifs_UnixTimeToNT(timespec64_to_timespec(ts));
#else
struct timespec ts;
getnstimeofday(&ts);
return cifs_UnixTimeToNT(ts);
#endif
}
#endif /* __CIFSD_TIME_WRAPPERS_H */