2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #include <sys/param.h>
26 #include <sys/systm.h>
27 #include <sys/kernel.h>
28 #include <sys/malloc.h>
29 #include <sys/types.h>
33 #include "hfscommon/headers/FileMgrInternal.h"
37 * gTimeZone should only be used for HFS volumes!
38 * It is initialized when an HFS volume is mounted.
40 struct timezone gTimeZone
= {8*60,1};
43 * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904)
45 * called by the Catalog Manager when creating/updating HFS Plus records
47 UInt32
GetTimeUTC(void)
49 return (time
.tv_sec
+ MAC_GMT_FACTOR
);
54 * LocalToUTC - convert from Mac OS local time to Mac OS GMT time.
55 * This should only be called for HFS volumes (not for HFS Plus).
57 UInt32
LocalToUTC(UInt32 localTime
)
59 UInt32 gtime
= localTime
;
62 gtime
+= (gTimeZone
.tz_minuteswest
* 60);
64 * We no longer do DST adjustments here since we don't
65 * know if time supplied needs adjustment!
67 * if (gTimeZone.tz_dsttime)
75 * UTCToLocal - convert from Mac OS GMT time to Mac OS local time.
76 * This should only be called for HFS volumes (not for HFS Plus).
78 UInt32
UTCToLocal(UInt32 utcTime
)
80 UInt32 ltime
= utcTime
;
83 ltime
-= (gTimeZone
.tz_minuteswest
* 60);
85 * We no longer do DST adjustments here since we don't
86 * know if time supplied needs adjustment!
88 * if (gTimeZone.tz_dsttime)
96 * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904)
97 * to BSD time (seconds since 1/1/1970)
99 u_int32_t
to_bsd_time(u_int32_t hfs_time
)
101 u_int32_t gmt
= hfs_time
;
103 if (gmt
> MAC_GMT_FACTOR
)
104 gmt
-= MAC_GMT_FACTOR
;
106 gmt
= 0; /* don't let date go negative! */
112 * to_hfs_time - convert from BSD time (seconds since 1/1/1970)
113 * to Mac OS time (seconds since 1/1/1904)
115 u_int32_t
to_hfs_time(u_int32_t bsd_time
)
117 u_int32_t hfs_time
= bsd_time
;
119 /* don't adjust zero - treat as uninitialzed */
121 hfs_time
+= MAC_GMT_FACTOR
;
127 Ptr
NewPtrSysClear (Size byteCount
)
130 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
132 bzero(tmptr
, byteCount
);
138 Ptr
NewPtr (Size byteCount
)
141 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
146 void DisposePtr (Ptr p
)
152 void DebugStr (ConstStr255Param debuggerMsg
)
154 kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg
[1]);