]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
8ad349bb | 2 | * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 3 | * |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb 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 | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b | 29 | */ |
1c79356b A |
30 | #include <sys/param.h> |
31 | #include <sys/systm.h> | |
32 | #include <sys/kernel.h> | |
1c79356b | 33 | #include <sys/malloc.h> |
1c79356b | 34 | #include <sys/types.h> |
9bccf70c | 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 | /* | |
42 | * gTimeZone should only be used for HFS volumes! | |
43 | * It is initialized when an HFS volume is mounted. | |
44 | */ | |
45 | struct timezone gTimeZone = {8*60,1}; | |
46 | ||
1c79356b A |
47 | /* |
48 | * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904) | |
49 | * | |
50 | * called by the Catalog Manager when creating/updating HFS Plus records | |
51 | */ | |
52 | UInt32 GetTimeUTC(void) | |
53 | { | |
91447636 A |
54 | struct timeval tv; |
55 | ||
56 | microtime(&tv); | |
57 | ||
58 | return (tv.tv_sec + MAC_GMT_FACTOR); | |
1c79356b A |
59 | } |
60 | ||
1c79356b A |
61 | |
62 | /* | |
63 | * LocalToUTC - convert from Mac OS local time to Mac OS GMT time. | |
64 | * This should only be called for HFS volumes (not for HFS Plus). | |
65 | */ | |
66 | UInt32 LocalToUTC(UInt32 localTime) | |
67 | { | |
68 | UInt32 gtime = localTime; | |
69 | ||
70 | if (gtime != 0) { | |
71 | gtime += (gTimeZone.tz_minuteswest * 60); | |
72 | /* | |
73 | * We no longer do DST adjustments here since we don't | |
74 | * know if time supplied needs adjustment! | |
75 | * | |
76 | * if (gTimeZone.tz_dsttime) | |
77 | * gtime -= 3600; | |
78 | */ | |
79 | } | |
80 | return (gtime); | |
81 | } | |
82 | ||
83 | /* | |
84 | * UTCToLocal - convert from Mac OS GMT time to Mac OS local time. | |
85 | * This should only be called for HFS volumes (not for HFS Plus). | |
86 | */ | |
87 | UInt32 UTCToLocal(UInt32 utcTime) | |
88 | { | |
89 | UInt32 ltime = utcTime; | |
90 | ||
91 | if (ltime != 0) { | |
92 | ltime -= (gTimeZone.tz_minuteswest * 60); | |
93 | /* | |
94 | * We no longer do DST adjustments here since we don't | |
95 | * know if time supplied needs adjustment! | |
96 | * | |
97 | * if (gTimeZone.tz_dsttime) | |
98 | * ltime += 3600; | |
99 | */ | |
100 | } | |
101 | return (ltime); | |
102 | } | |
103 | ||
104 | /* | |
105 | * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904) | |
106 | * to BSD time (seconds since 1/1/1970) | |
107 | */ | |
91447636 | 108 | time_t to_bsd_time(u_int32_t hfs_time) |
1c79356b A |
109 | { |
110 | u_int32_t gmt = hfs_time; | |
111 | ||
112 | if (gmt > MAC_GMT_FACTOR) | |
113 | gmt -= MAC_GMT_FACTOR; | |
114 | else | |
115 | gmt = 0; /* don't let date go negative! */ | |
116 | ||
91447636 | 117 | return (time_t)gmt; |
1c79356b A |
118 | } |
119 | ||
120 | /* | |
121 | * to_hfs_time - convert from BSD time (seconds since 1/1/1970) | |
122 | * to Mac OS time (seconds since 1/1/1904) | |
123 | */ | |
91447636 | 124 | u_int32_t to_hfs_time(time_t bsd_time) |
1c79356b | 125 | { |
91447636 | 126 | u_int32_t hfs_time = (u_int32_t)bsd_time; |
1c79356b A |
127 | |
128 | /* don't adjust zero - treat as uninitialzed */ | |
129 | if (hfs_time != 0) | |
130 | hfs_time += MAC_GMT_FACTOR; | |
131 | ||
132 | return (hfs_time); | |
133 | } | |
134 | ||
135 | ||
1c79356b A |
136 | Ptr NewPtrSysClear (Size byteCount) |
137 | { | |
138 | Ptr tmptr; | |
139 | MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK); | |
140 | if (tmptr) | |
141 | bzero(tmptr, byteCount); | |
142 | return tmptr; | |
143 | } | |
144 | ||
145 | ||
146 | ||
147 | Ptr NewPtr (Size byteCount) | |
148 | { | |
149 | Ptr tmptr; | |
150 | MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK); | |
151 | return tmptr; | |
152 | } | |
153 | ||
154 | ||
155 | void DisposePtr (Ptr p) | |
156 | { | |
157 | FREE (p, M_TEMP); | |
158 | } | |
159 | ||
160 | ||
161 | void DebugStr (ConstStr255Param debuggerMsg) | |
162 | { | |
163 | kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg[1]); | |
164 | DEBUG_BREAK; | |
165 | } | |
166 |