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