home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ntfs-3g / ntfstime.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-26  |  2.3 KB  |  70 lines

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