2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #include <sys/param.h>
23 #include <sys/systm.h>
24 #include <sys/kernel.h>
25 #include <sys/malloc.h>
26 #include <sys/types.h>
30 #include "hfscommon/headers/FileMgrInternal.h"
34 * gTimeZone should only be used for HFS volumes!
35 * It is initialized when an HFS volume is mounted.
37 struct timezone gTimeZone
= {8*60,1};
40 * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904)
42 * called by the Catalog Manager when creating/updating HFS Plus records
44 UInt32
GetTimeUTC(void)
50 return (tv
.tv_sec
+ MAC_GMT_FACTOR
);
55 * LocalToUTC - convert from Mac OS local time to Mac OS GMT time.
56 * This should only be called for HFS volumes (not for HFS Plus).
58 UInt32
LocalToUTC(UInt32 localTime
)
60 UInt32 gtime
= localTime
;
63 gtime
+= (gTimeZone
.tz_minuteswest
* 60);
65 * We no longer do DST adjustments here since we don't
66 * know if time supplied needs adjustment!
68 * if (gTimeZone.tz_dsttime)
76 * UTCToLocal - convert from Mac OS GMT time to Mac OS local time.
77 * This should only be called for HFS volumes (not for HFS Plus).
79 UInt32
UTCToLocal(UInt32 utcTime
)
81 UInt32 ltime
= utcTime
;
84 ltime
-= (gTimeZone
.tz_minuteswest
* 60);
86 * We no longer do DST adjustments here since we don't
87 * know if time supplied needs adjustment!
89 * if (gTimeZone.tz_dsttime)
97 * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904)
98 * to BSD time (seconds since 1/1/1970)
100 time_t to_bsd_time(u_int32_t hfs_time
)
102 u_int32_t gmt
= hfs_time
;
104 if (gmt
> MAC_GMT_FACTOR
)
105 gmt
-= MAC_GMT_FACTOR
;
107 gmt
= 0; /* don't let date go negative! */
113 * to_hfs_time - convert from BSD time (seconds since 1/1/1970)
114 * to Mac OS time (seconds since 1/1/1904)
116 u_int32_t
to_hfs_time(time_t bsd_time
)
118 u_int32_t hfs_time
= (u_int32_t
)bsd_time
;
120 /* don't adjust zero - treat as uninitialzed */
122 hfs_time
+= MAC_GMT_FACTOR
;
128 Ptr
NewPtrSysClear (Size byteCount
)
131 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
133 bzero(tmptr
, byteCount
);
139 Ptr
NewPtr (Size byteCount
)
142 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
147 void DisposePtr (Ptr p
)
153 void DebugStr (ConstStr255Param debuggerMsg
)
155 kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg
[1]);