xref: /onnv-gate/usr/src/lib/libntfs/common/include/ntfs/ntfstime.h (revision 9663:ace9a2ac3683)
1*9663SMark.Logan@Sun.COM /*
2*9663SMark.Logan@Sun.COM  * ntfstime.h - NTFS time related functions.  Part of the Linux-NTFS project.
3*9663SMark.Logan@Sun.COM  *
4*9663SMark.Logan@Sun.COM  * Copyright (c) 2005      Anton Altaparmakov
5*9663SMark.Logan@Sun.COM  * Copyright (c) 2005-2007 Yura Pakhuchiy
6*9663SMark.Logan@Sun.COM  *
7*9663SMark.Logan@Sun.COM  * This program/include file is free software; you can redistribute it and/or
8*9663SMark.Logan@Sun.COM  * modify it under the terms of the GNU General Public License as published
9*9663SMark.Logan@Sun.COM  * by the Free Software Foundation; either version 2 of the License, or
10*9663SMark.Logan@Sun.COM  * (at your option) any later version.
11*9663SMark.Logan@Sun.COM  *
12*9663SMark.Logan@Sun.COM  * This program/include file is distributed in the hope that it will be
13*9663SMark.Logan@Sun.COM  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14*9663SMark.Logan@Sun.COM  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*9663SMark.Logan@Sun.COM  * GNU General Public License for more details.
16*9663SMark.Logan@Sun.COM  *
17*9663SMark.Logan@Sun.COM  * You should have received a copy of the GNU General Public License
18*9663SMark.Logan@Sun.COM  * along with this program (in the main directory of the Linux-NTFS
19*9663SMark.Logan@Sun.COM  * distribution in the file COPYING); if not, write to the Free Software
20*9663SMark.Logan@Sun.COM  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21*9663SMark.Logan@Sun.COM  */
22*9663SMark.Logan@Sun.COM 
23*9663SMark.Logan@Sun.COM #ifndef _NTFS_NTFSTIME_H
24*9663SMark.Logan@Sun.COM #define _NTFS_NTFSTIME_H
25*9663SMark.Logan@Sun.COM 
26*9663SMark.Logan@Sun.COM #ifdef HAVE_TIME_H
27*9663SMark.Logan@Sun.COM #include <time.h>
28*9663SMark.Logan@Sun.COM #endif
29*9663SMark.Logan@Sun.COM 
30*9663SMark.Logan@Sun.COM #include "types.h"
31*9663SMark.Logan@Sun.COM 
32*9663SMark.Logan@Sun.COM #define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000)
33*9663SMark.Logan@Sun.COM 
34*9663SMark.Logan@Sun.COM /**
35*9663SMark.Logan@Sun.COM  * ntfs2utc - Convert an NTFS time to Unix time
36*9663SMark.Logan@Sun.COM  * @ntfs_time:  An NTFS time in 100ns units since 1601
37*9663SMark.Logan@Sun.COM  *
38*9663SMark.Logan@Sun.COM  * NTFS stores times as the number of 100ns intervals since January 1st 1601 at
39*9663SMark.Logan@Sun.COM  * 00:00 UTC.  This system will not suffer from Y2K problems until ~57000AD.
40*9663SMark.Logan@Sun.COM  *
41*9663SMark.Logan@Sun.COM  * Return:  n  A Unix time (number of seconds since 1970)
42*9663SMark.Logan@Sun.COM  */
ntfs2utc(sle64 ntfs_time)43*9663SMark.Logan@Sun.COM static __inline__ time_t ntfs2utc(sle64 ntfs_time)
44*9663SMark.Logan@Sun.COM {
45*9663SMark.Logan@Sun.COM 	return (sle64_to_cpu(ntfs_time) - (NTFS_TIME_OFFSET)) / 10000000;
46*9663SMark.Logan@Sun.COM }
47*9663SMark.Logan@Sun.COM 
48*9663SMark.Logan@Sun.COM /**
49*9663SMark.Logan@Sun.COM  * utc2ntfs - Convert Linux time to NTFS time
50*9663SMark.Logan@Sun.COM  * @utc_time:  Linux time to convert to NTFS
51*9663SMark.Logan@Sun.COM  *
52*9663SMark.Logan@Sun.COM  * Convert the Linux time @utc_time to its corresponding NTFS time.
53*9663SMark.Logan@Sun.COM  *
54*9663SMark.Logan@Sun.COM  * Linux stores time in a long at present and measures it as the number of
55*9663SMark.Logan@Sun.COM  * 1-second intervals since 1st January 1970, 00:00:00 UTC.
56*9663SMark.Logan@Sun.COM  *
57*9663SMark.Logan@Sun.COM  * NTFS uses Microsoft's standard time format which is stored in a s64 and is
58*9663SMark.Logan@Sun.COM  * measured as the number of 100 nano-second intervals since 1st January 1601,
59*9663SMark.Logan@Sun.COM  * 00:00:00 UTC.
60*9663SMark.Logan@Sun.COM  *
61*9663SMark.Logan@Sun.COM  * Return:  n  An NTFS time (100ns units since Jan 1601)
62*9663SMark.Logan@Sun.COM  */
utc2ntfs(time_t utc_time)63*9663SMark.Logan@Sun.COM static __inline__ sle64 utc2ntfs(time_t utc_time)
64*9663SMark.Logan@Sun.COM {
65*9663SMark.Logan@Sun.COM 	/* Convert to 100ns intervals and then add the NTFS time offset. */
66*9663SMark.Logan@Sun.COM 	return cpu_to_sle64((s64)utc_time * 10000000 + NTFS_TIME_OFFSET);
67*9663SMark.Logan@Sun.COM }
68*9663SMark.Logan@Sun.COM 
69*9663SMark.Logan@Sun.COM #endif /* _NTFS_NTFSTIME_H */
70