]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 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 | |
2d21ac55 A |
34 | #include <pexpert/pexpert.h> |
35 | ||
1c79356b A |
36 | #include "hfs.h" |
37 | #include "hfs_dbg.h" | |
1c79356b A |
38 | #include "hfscommon/headers/FileMgrInternal.h" |
39 | ||
1c79356b A |
40 | /* |
41 | * gTimeZone should only be used for HFS volumes! | |
42 | * It is initialized when an HFS volume is mounted. | |
43 | */ | |
44 | struct timezone gTimeZone = {8*60,1}; | |
45 | ||
1c79356b A |
46 | /* |
47 | * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904) | |
48 | * | |
49 | * called by the Catalog Manager when creating/updating HFS Plus records | |
50 | */ | |
2d21ac55 | 51 | u_int32_t GetTimeUTC(void) |
1c79356b | 52 | { |
91447636 A |
53 | struct timeval tv; |
54 | ||
55 | microtime(&tv); | |
56 | ||
57 | return (tv.tv_sec + MAC_GMT_FACTOR); | |
1c79356b A |
58 | } |
59 | ||
1c79356b A |
60 | |
61 | /* | |
62 | * LocalToUTC - convert from Mac OS local time to Mac OS GMT time. | |
63 | * This should only be called for HFS volumes (not for HFS Plus). | |
64 | */ | |
2d21ac55 | 65 | u_int32_t LocalToUTC(u_int32_t localTime) |
1c79356b | 66 | { |
2d21ac55 | 67 | u_int32_t gtime = localTime; |
1c79356b A |
68 | |
69 | if (gtime != 0) { | |
70 | gtime += (gTimeZone.tz_minuteswest * 60); | |
71 | /* | |
72 | * We no longer do DST adjustments here since we don't | |
73 | * know if time supplied needs adjustment! | |
74 | * | |
75 | * if (gTimeZone.tz_dsttime) | |
76 | * gtime -= 3600; | |
77 | */ | |
78 | } | |
79 | return (gtime); | |
80 | } | |
81 | ||
82 | /* | |
83 | * UTCToLocal - convert from Mac OS GMT time to Mac OS local time. | |
84 | * This should only be called for HFS volumes (not for HFS Plus). | |
85 | */ | |
2d21ac55 | 86 | u_int32_t UTCToLocal(u_int32_t utcTime) |
1c79356b | 87 | { |
2d21ac55 | 88 | u_int32_t ltime = utcTime; |
1c79356b A |
89 | |
90 | if (ltime != 0) { | |
91 | ltime -= (gTimeZone.tz_minuteswest * 60); | |
92 | /* | |
93 | * We no longer do DST adjustments here since we don't | |
94 | * know if time supplied needs adjustment! | |
95 | * | |
96 | * if (gTimeZone.tz_dsttime) | |
97 | * ltime += 3600; | |
98 | */ | |
99 | } | |
100 | return (ltime); | |
101 | } | |
102 | ||
103 | /* | |
104 | * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904) | |
105 | * to BSD time (seconds since 1/1/1970) | |
106 | */ | |
91447636 | 107 | time_t to_bsd_time(u_int32_t hfs_time) |
1c79356b A |
108 | { |
109 | u_int32_t gmt = hfs_time; | |
110 | ||
111 | if (gmt > MAC_GMT_FACTOR) | |
112 | gmt -= MAC_GMT_FACTOR; | |
113 | else | |
114 | gmt = 0; /* don't let date go negative! */ | |
115 | ||
91447636 | 116 | return (time_t)gmt; |
1c79356b A |
117 | } |
118 | ||
119 | /* | |
120 | * to_hfs_time - convert from BSD time (seconds since 1/1/1970) | |
121 | * to Mac OS time (seconds since 1/1/1904) | |
122 | */ | |
91447636 | 123 | u_int32_t to_hfs_time(time_t bsd_time) |
1c79356b | 124 | { |
91447636 | 125 | u_int32_t hfs_time = (u_int32_t)bsd_time; |
1c79356b A |
126 | |
127 | /* don't adjust zero - treat as uninitialzed */ | |
128 | if (hfs_time != 0) | |
129 | hfs_time += MAC_GMT_FACTOR; | |
130 | ||
131 | return (hfs_time); | |
132 | } | |
133 | ||
134 | ||
1c79356b A |
135 | Ptr NewPtrSysClear (Size byteCount) |
136 | { | |
137 | Ptr tmptr; | |
138 | MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK); | |
139 | if (tmptr) | |
140 | bzero(tmptr, byteCount); | |
141 | return tmptr; | |
142 | } | |
143 | ||
144 | ||
145 | ||
146 | Ptr NewPtr (Size byteCount) | |
147 | { | |
148 | Ptr tmptr; | |
149 | MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK); | |
150 | return tmptr; | |
151 | } | |
152 | ||
153 | ||
154 | void DisposePtr (Ptr p) | |
155 | { | |
156 | FREE (p, M_TEMP); | |
157 | } | |
158 | ||
159 | ||
2d21ac55 A |
160 | void |
161 | DebugStr( | |
b0d623f7 | 162 | const char * debuggerMsg |
2d21ac55 | 163 | ) |
1c79356b | 164 | { |
b0d623f7 | 165 | kprintf ("*** Mac OS Debugging Message: %s\n", debuggerMsg); |
1c79356b A |
166 | DEBUG_BREAK; |
167 | } | |
168 |