]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
3 | * | |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
8f6c56a5 A |
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. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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 | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b | 27 | */ |
1c79356b A |
28 | #include <sys/param.h> |
29 | #include <sys/systm.h> | |
30 | #include <sys/kernel.h> | |
1c79356b | 31 | #include <sys/malloc.h> |
1c79356b | 32 | #include <sys/types.h> |
9bccf70c | 33 | |
1c79356b A |
34 | #include "hfs.h" |
35 | #include "hfs_dbg.h" | |
1c79356b A |
36 | #include "hfscommon/headers/FileMgrInternal.h" |
37 | ||
1c79356b A |
38 | |
39 | /* | |
40 | * gTimeZone should only be used for HFS volumes! | |
41 | * It is initialized when an HFS volume is mounted. | |
42 | */ | |
43 | struct timezone gTimeZone = {8*60,1}; | |
44 | ||
1c79356b A |
45 | /* |
46 | * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904) | |
47 | * | |
48 | * called by the Catalog Manager when creating/updating HFS Plus records | |
49 | */ | |
50 | UInt32 GetTimeUTC(void) | |
51 | { | |
91447636 A |
52 | struct timeval tv; |
53 | ||
54 | microtime(&tv); | |
55 | ||
56 | return (tv.tv_sec + MAC_GMT_FACTOR); | |
1c79356b A |
57 | } |
58 | ||
1c79356b A |
59 | |
60 | /* | |
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). | |
63 | */ | |
64 | UInt32 LocalToUTC(UInt32 localTime) | |
65 | { | |
66 | UInt32 gtime = localTime; | |
67 | ||
68 | if (gtime != 0) { | |
69 | gtime += (gTimeZone.tz_minuteswest * 60); | |
70 | /* | |
71 | * We no longer do DST adjustments here since we don't | |
72 | * know if time supplied needs adjustment! | |
73 | * | |
74 | * if (gTimeZone.tz_dsttime) | |
75 | * gtime -= 3600; | |
76 | */ | |
77 | } | |
78 | return (gtime); | |
79 | } | |
80 | ||
81 | /* | |
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). | |
84 | */ | |
85 | UInt32 UTCToLocal(UInt32 utcTime) | |
86 | { | |
87 | UInt32 ltime = utcTime; | |
88 | ||
89 | if (ltime != 0) { | |
90 | ltime -= (gTimeZone.tz_minuteswest * 60); | |
91 | /* | |
92 | * We no longer do DST adjustments here since we don't | |
93 | * know if time supplied needs adjustment! | |
94 | * | |
95 | * if (gTimeZone.tz_dsttime) | |
96 | * ltime += 3600; | |
97 | */ | |
98 | } | |
99 | return (ltime); | |
100 | } | |
101 | ||
102 | /* | |
103 | * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904) | |
104 | * to BSD time (seconds since 1/1/1970) | |
105 | */ | |
91447636 | 106 | time_t to_bsd_time(u_int32_t hfs_time) |
1c79356b A |
107 | { |
108 | u_int32_t gmt = hfs_time; | |
109 | ||
110 | if (gmt > MAC_GMT_FACTOR) | |
111 | gmt -= MAC_GMT_FACTOR; | |
112 | else | |
113 | gmt = 0; /* don't let date go negative! */ | |
114 | ||
91447636 | 115 | return (time_t)gmt; |
1c79356b A |
116 | } |
117 | ||
118 | /* | |
119 | * to_hfs_time - convert from BSD time (seconds since 1/1/1970) | |
120 | * to Mac OS time (seconds since 1/1/1904) | |
121 | */ | |
91447636 | 122 | u_int32_t to_hfs_time(time_t bsd_time) |
1c79356b | 123 | { |
91447636 | 124 | u_int32_t hfs_time = (u_int32_t)bsd_time; |
1c79356b A |
125 | |
126 | /* don't adjust zero - treat as uninitialzed */ | |
127 | if (hfs_time != 0) | |
128 | hfs_time += MAC_GMT_FACTOR; | |
129 | ||
130 | return (hfs_time); | |
131 | } | |
132 | ||
133 | ||
1c79356b A |
134 | Ptr NewPtrSysClear (Size byteCount) |
135 | { | |
136 | Ptr tmptr; | |
137 | MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK); | |
138 | if (tmptr) | |
139 | bzero(tmptr, byteCount); | |
140 | return tmptr; | |
141 | } | |
142 | ||
143 | ||
144 | ||
145 | Ptr NewPtr (Size byteCount) | |
146 | { | |
147 | Ptr tmptr; | |
148 | MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK); | |
149 | return tmptr; | |
150 | } | |
151 | ||
152 | ||
153 | void DisposePtr (Ptr p) | |
154 | { | |
155 | FREE (p, M_TEMP); | |
156 | } | |
157 | ||
158 | ||
159 | void DebugStr (ConstStr255Param debuggerMsg) | |
160 | { | |
161 | kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg[1]); | |
162 | DEBUG_BREAK; | |
163 | } | |
164 |