]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - fs/cifsd/netmisc.c
cifsd: clean-up codes using chechpatch.pl --strict
[mirror_ubuntu-jammy-kernel.git] / fs / cifsd / netmisc.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2002,2008
4 * Author(s): Steve French (sfrench@us.ibm.com)
5 *
6 * Error mapping routines from Samba libsmb/errormap.c
7 * Copyright (C) Andrew Tridgell 2001
8 */
9
10 #include "glob.h"
11 #include "smberr.h"
12 #include "nterr.h"
13 #include "time_wrappers.h"
14
15 /*
16 * Convert the NT UTC (based 1601-01-01, in hundred nanosecond units)
17 * into Unix UTC (based 1970-01-01, in seconds).
18 */
19 struct timespec64 ksmbd_NTtimeToUnix(__le64 ntutc)
20 {
21 struct timespec64 ts;
22
23 /* Subtract the NTFS time offset, then convert to 1s intervals. */
24 s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
25 u64 abs_t;
26
27 /*
28 * Unfortunately can not use normal 64 bit division on 32 bit arch, but
29 * the alternative, do_div, does not work with negative numbers so have
30 * to special case them
31 */
32 if (t < 0) {
33 abs_t = -t;
34 ts.tv_nsec = do_div(abs_t, 10000000) * 100;
35 ts.tv_nsec = -ts.tv_nsec;
36 ts.tv_sec = -abs_t;
37 } else {
38 abs_t = t;
39 ts.tv_nsec = do_div(abs_t, 10000000) * 100;
40 ts.tv_sec = abs_t;
41 }
42
43 return ts;
44 }