2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/types.h>
38 #include "hfscommon/headers/FileMgrInternal.h"
42 * gTimeZone should only be used for HFS volumes!
43 * It is initialized when an HFS volume is mounted.
45 struct timezone gTimeZone
= {8*60,1};
48 * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904)
50 * called by the Catalog Manager when creating/updating HFS Plus records
52 UInt32
GetTimeUTC(void)
58 return (tv
.tv_sec
+ MAC_GMT_FACTOR
);
63 * LocalToUTC - convert from Mac OS local time to Mac OS GMT time.
64 * This should only be called for HFS volumes (not for HFS Plus).
66 UInt32
LocalToUTC(UInt32 localTime
)
68 UInt32 gtime
= localTime
;
71 gtime
+= (gTimeZone
.tz_minuteswest
* 60);
73 * We no longer do DST adjustments here since we don't
74 * know if time supplied needs adjustment!
76 * if (gTimeZone.tz_dsttime)
84 * UTCToLocal - convert from Mac OS GMT time to Mac OS local time.
85 * This should only be called for HFS volumes (not for HFS Plus).
87 UInt32
UTCToLocal(UInt32 utcTime
)
89 UInt32 ltime
= utcTime
;
92 ltime
-= (gTimeZone
.tz_minuteswest
* 60);
94 * We no longer do DST adjustments here since we don't
95 * know if time supplied needs adjustment!
97 * if (gTimeZone.tz_dsttime)
105 * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904)
106 * to BSD time (seconds since 1/1/1970)
108 time_t to_bsd_time(u_int32_t hfs_time
)
110 u_int32_t gmt
= hfs_time
;
112 if (gmt
> MAC_GMT_FACTOR
)
113 gmt
-= MAC_GMT_FACTOR
;
115 gmt
= 0; /* don't let date go negative! */
121 * to_hfs_time - convert from BSD time (seconds since 1/1/1970)
122 * to Mac OS time (seconds since 1/1/1904)
124 u_int32_t
to_hfs_time(time_t bsd_time
)
126 u_int32_t hfs_time
= (u_int32_t
)bsd_time
;
128 /* don't adjust zero - treat as uninitialzed */
130 hfs_time
+= MAC_GMT_FACTOR
;
136 Ptr
NewPtrSysClear (Size byteCount
)
139 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
141 bzero(tmptr
, byteCount
);
147 Ptr
NewPtr (Size byteCount
)
150 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
155 void DisposePtr (Ptr p
)
161 void DebugStr (ConstStr255Param debuggerMsg
)
163 kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg
[1]);