aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ntfs/time.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/ntfs/time.h
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/ntfs/time.h')
-rw-r--r--fs/ntfs/time.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/fs/ntfs/time.h b/fs/ntfs/time.h
new file mode 100644
index 00000000000..a09a51dabe4
--- /dev/null
+++ b/fs/ntfs/time.h
@@ -0,0 +1,100 @@
1/*
2 * time.h - NTFS time conversion functions. Part of the Linux-NTFS project.
3 *
4 * Copyright (c) 2001-2004 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#ifndef _LINUX_NTFS_TIME_H
23#define _LINUX_NTFS_TIME_H
24
25#include <linux/time.h> /* For current_kernel_time(). */
26#include <asm/div64.h> /* For do_div(). */
27
28#include "endian.h"
29
30#define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000)
31
32/**
33 * utc2ntfs - convert Linux UTC time to NTFS time
34 * @ts: Linux UTC time to convert to NTFS time
35 *
36 * Convert the Linux UTC time @ts to its corresponding NTFS time and return
37 * that in little endian format.
38 *
39 * Linux stores time in a struct timespec consisting of a time_t (long at
40 * present) tv_sec and a long tv_nsec where tv_sec is the number of 1-second
41 * intervals since 1st January 1970, 00:00:00 UTC and tv_nsec is the number of
42 * 1-nano-second intervals since the value of tv_sec.
43 *
44 * NTFS uses Microsoft's standard time format which is stored in a s64 and is
45 * measured as the number of 100-nano-second intervals since 1st January 1601,
46 * 00:00:00 UTC.
47 */
48static inline sle64 utc2ntfs(const struct timespec ts)
49{
50 /*
51 * Convert the seconds to 100ns intervals, add the nano-seconds
52 * converted to 100ns intervals, and then add the NTFS time offset.
53 */
54 return cpu_to_sle64((s64)ts.tv_sec * 10000000 + ts.tv_nsec / 100 +
55 NTFS_TIME_OFFSET);
56}
57
58/**
59 * get_current_ntfs_time - get the current time in little endian NTFS format
60 *
61 * Get the current time from the Linux kernel, convert it to its corresponding
62 * NTFS time and return that in little endian format.
63 */
64static inline sle64 get_current_ntfs_time(void)
65{
66 return utc2ntfs(current_kernel_time());
67}
68
69/**
70 * ntfs2utc - convert NTFS time to Linux time
71 * @time: NTFS time (little endian) to convert to Linux UTC
72 *
73 * Convert the little endian NTFS time @time to its corresponding Linux UTC
74 * time and return that in cpu format.
75 *
76 * Linux stores time in a struct timespec consisting of a time_t (long at
77 * present) tv_sec and a long tv_nsec where tv_sec is the number of 1-second
78 * intervals since 1st January 1970, 00:00:00 UTC and tv_nsec is the number of
79 * 1-nano-second intervals since the value of tv_sec.
80 *
81 * NTFS uses Microsoft's standard time format which is stored in a s64 and is
82 * measured as the number of 100 nano-second intervals since 1st January 1601,
83 * 00:00:00 UTC.
84 */
85static inline struct timespec ntfs2utc(const sle64 time)
86{
87 struct timespec ts;
88
89 /* Subtract the NTFS time offset. */
90 s64 t = sle64_to_cpu(time) - NTFS_TIME_OFFSET;
91 /*
92 * Convert the time to 1-second intervals and the remainder to
93 * 1-nano-second intervals.
94 */
95 ts.tv_nsec = do_div(t, 10000000) * 100;
96 ts.tv_sec = t;
97 return ts;
98}
99
100#endif /* _LINUX_NTFS_TIME_H */