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