minor corrections by M.Taguchi
[reactos.git] / reactos / drivers / fs / ntfs / linux-ntfs / time.c
1 /*
2 * time.c - NTFS time conversion functions. Part of the Linux-NTFS project.
3 *
4 * Copyright (c) 2001 Anton Altaparmakov.
5 *
6 * This program/include file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program/include file is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program (in the main directory of the Linux-NTFS
18 * distribution in the file COPYING); if not, write to the Free Software
19 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include <linux/sched.h> /* For CURRENT_TIME. */
23 #include <asm/div64.h> /* For do_div(). */
24
25 #include "ntfs.h"
26
27 #define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000)
28
29 /**
30 * utc2ntfs - convert Linux time to NTFS time
31 * @time: Linux time to convert to NTFS
32 *
33 * Convert the Linux time @time to its corresponding NTFS time and return that
34 * in little endian format.
35 *
36 * Linux stores time in a long at present and measures it as the number of
37 * 1-second intervals since 1st January 1970, 00:00:00 UTC.
38 *
39 * NTFS uses Microsoft's standard time format which is stored in a s64 and is
40 * measured as the number of 100 nano-second intervals since 1st January 1601,
41 * 00:00:00 UTC.
42 */
43 inline s64 utc2ntfs(const time_t time)
44 {
45 /* Convert to 100ns intervals and then add the NTFS time offset. */
46 return cpu_to_sle64((s64)time * 10000000 + NTFS_TIME_OFFSET);
47 }
48
49 /**
50 * get_current_ntfs_time - get the current time in little endian NTFS format
51 *
52 * Get the current time from the Linux kernel, convert it to its corresponding
53 * NTFS time and return that in little endian format.
54 */
55 inline s64 get_current_ntfs_time(void)
56 {
57 /* ignores leap second */
58 return utc2ntfs(get_seconds()) + xtime.tv_nsec/1000;
59 }
60
61 /**
62 * ntfs2utc - convert NTFS time to Linux time
63 * @time: NTFS time (little endian) to convert to Linux
64 *
65 * Convert the little endian NTFS time @time to its corresponding Linux time
66 * and return that in cpu format.
67 *
68 * Linux stores time in a long at present and measures it as the number of
69 * 1-second intervals since 1st January 1970, 00:00:00 UTC.
70 *
71 * NTFS uses Microsoft's standard time format which is stored in a s64 and is
72 * measured as the number of 100 nano-second intervals since 1st January 1601,
73 * 00:00:00 UTC.
74 */
75 inline time_t ntfs2utc(const s64 time)
76 {
77 /* Subtract the NTFS time offset, then convert to 1s intervals. */
78 s64 t = sle64_to_cpu(time) - NTFS_TIME_OFFSET;
79 do_div(t, 10000000);
80 return (time_t)t;
81 }
82