2 * Copyright (c) 2000-2002 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)
46 return (time
.tv_sec
+ MAC_GMT_FACTOR
);
51 * LocalToUTC - convert from Mac OS local time to Mac OS GMT time.
52 * This should only be called for HFS volumes (not for HFS Plus).
54 UInt32
LocalToUTC(UInt32 localTime
)
56 UInt32 gtime
= localTime
;
59 gtime
+= (gTimeZone
.tz_minuteswest
* 60);
61 * We no longer do DST adjustments here since we don't
62 * know if time supplied needs adjustment!
64 * if (gTimeZone.tz_dsttime)
72 * UTCToLocal - convert from Mac OS GMT time to Mac OS local time.
73 * This should only be called for HFS volumes (not for HFS Plus).
75 UInt32
UTCToLocal(UInt32 utcTime
)
77 UInt32 ltime
= utcTime
;
80 ltime
-= (gTimeZone
.tz_minuteswest
* 60);
82 * We no longer do DST adjustments here since we don't
83 * know if time supplied needs adjustment!
85 * if (gTimeZone.tz_dsttime)
93 * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904)
94 * to BSD time (seconds since 1/1/1970)
96 u_int32_t
to_bsd_time(u_int32_t hfs_time
)
98 u_int32_t gmt
= hfs_time
;
100 if (gmt
> MAC_GMT_FACTOR
)
101 gmt
-= MAC_GMT_FACTOR
;
103 gmt
= 0; /* don't let date go negative! */
109 * to_hfs_time - convert from BSD time (seconds since 1/1/1970)
110 * to Mac OS time (seconds since 1/1/1904)
112 u_int32_t
to_hfs_time(u_int32_t bsd_time
)
114 u_int32_t hfs_time
= bsd_time
;
116 /* don't adjust zero - treat as uninitialzed */
118 hfs_time
+= MAC_GMT_FACTOR
;
124 Ptr
NewPtrSysClear (Size byteCount
)
127 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
129 bzero(tmptr
, byteCount
);
135 Ptr
NewPtr (Size byteCount
)
138 MALLOC (tmptr
, Ptr
, byteCount
, M_TEMP
, M_WAITOK
);
143 void DisposePtr (Ptr p
)
149 void DebugStr (ConstStr255Param debuggerMsg
)
151 kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg
[1]);