2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/kernel.h>
31 #include <sys/malloc.h>
32 #include <sys/types.h>
36 #include "hfscommon/headers/FileMgrInternal.h"
40 * gTimeZone should only be used for HFS volumes!
41 * It is initialized when an HFS volume is mounted.
43 struct timezone gTimeZone
= {8*60,1};
46 * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904)
48 * called by the Catalog Manager when creating/updating HFS Plus records
50 UInt32
GetTimeUTC(void)
56 return (tv
.tv_sec
+ MAC_GMT_FACTOR
);
61 * LocalToUTC - convert from Mac OS local time to Mac OS GMT time.
62 * This should only be called for HFS volumes (not for HFS Plus).
64 UInt32
LocalToUTC(UInt32 localTime
)
66 UInt32 gtime
= localTime
;
69 gtime
+= (gTimeZone
.tz_minuteswest
* 60);
71 * We no longer do DST adjustments here since we don't
72 * know if time supplied needs adjustment!
74 * if (gTimeZone.tz_dsttime)
82 * UTCToLocal - convert from Mac OS GMT time to Mac OS local time.
83 * This should only be called for HFS volumes (not for HFS Plus).
85 UInt32
UTCToLocal(UInt32 utcTime
)
87 UInt32 ltime
= utcTime
;
90 ltime
-= (gTimeZone
.tz_minuteswest
* 60);
92 * We no longer do DST adjustments here since we don't
93 * know if time supplied needs adjustment!
95 * if (gTimeZone.tz_dsttime)
103 * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904)
104 * to BSD time (seconds since 1/1/1970)
106 time_t to_bsd_time(u_int32_t hfs_time
)
108 u_int32_t gmt
= hfs_time
;
110 if (gmt
> MAC_GMT_FACTOR
)
111 gmt
-= MAC_GMT_FACTOR
;
113 gmt
= 0; /* don't let date go negative! */
119 * to_hfs_time - convert from BSD time (seconds since 1/1/1970)
120 * to Mac OS time (seconds since 1/1/1904)
122 u_int32_t
to_hfs_time(time_t bsd_time
)
124 u_int32_t hfs_time
= (u_int32_t
)bsd_time
;
126 /* don't adjust zero - treat as uninitialzed */
128 hfs_time
+= MAC_GMT_FACTOR
;
134 Ptr
NewPtrSysClear (Size byteCount
)
137 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
139 bzero(tmptr
, byteCount
);
145 Ptr
NewPtr (Size byteCount
)
148 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
153 void DisposePtr (Ptr p
)
159 void DebugStr (ConstStr255Param debuggerMsg
)
161 kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg
[1]);