]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
9bccf70c | 2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
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 | { | |
46 | return (time.tv_sec + MAC_GMT_FACTOR); | |
47 | } | |
48 | ||
1c79356b A |
49 | |
50 | /* | |
51 | * LocalToUTC - convert from Mac OS local time to Mac OS GMT time. | |
52 | * This should only be called for HFS volumes (not for HFS Plus). | |
53 | */ | |
54 | UInt32 LocalToUTC(UInt32 localTime) | |
55 | { | |
56 | UInt32 gtime = localTime; | |
57 | ||
58 | if (gtime != 0) { | |
59 | gtime += (gTimeZone.tz_minuteswest * 60); | |
60 | /* | |
61 | * We no longer do DST adjustments here since we don't | |
62 | * know if time supplied needs adjustment! | |
63 | * | |
64 | * if (gTimeZone.tz_dsttime) | |
65 | * gtime -= 3600; | |
66 | */ | |
67 | } | |
68 | return (gtime); | |
69 | } | |
70 | ||
71 | /* | |
72 | * UTCToLocal - convert from Mac OS GMT time to Mac OS local time. | |
73 | * This should only be called for HFS volumes (not for HFS Plus). | |
74 | */ | |
75 | UInt32 UTCToLocal(UInt32 utcTime) | |
76 | { | |
77 | UInt32 ltime = utcTime; | |
78 | ||
79 | if (ltime != 0) { | |
80 | ltime -= (gTimeZone.tz_minuteswest * 60); | |
81 | /* | |
82 | * We no longer do DST adjustments here since we don't | |
83 | * know if time supplied needs adjustment! | |
84 | * | |
85 | * if (gTimeZone.tz_dsttime) | |
86 | * ltime += 3600; | |
87 | */ | |
88 | } | |
89 | return (ltime); | |
90 | } | |
91 | ||
92 | /* | |
93 | * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904) | |
94 | * to BSD time (seconds since 1/1/1970) | |
95 | */ | |
96 | u_int32_t to_bsd_time(u_int32_t hfs_time) | |
97 | { | |
98 | u_int32_t gmt = hfs_time; | |
99 | ||
100 | if (gmt > MAC_GMT_FACTOR) | |
101 | gmt -= MAC_GMT_FACTOR; | |
102 | else | |
103 | gmt = 0; /* don't let date go negative! */ | |
104 | ||
105 | return gmt; | |
106 | } | |
107 | ||
108 | /* | |
109 | * to_hfs_time - convert from BSD time (seconds since 1/1/1970) | |
110 | * to Mac OS time (seconds since 1/1/1904) | |
111 | */ | |
112 | u_int32_t to_hfs_time(u_int32_t bsd_time) | |
113 | { | |
114 | u_int32_t hfs_time = bsd_time; | |
115 | ||
116 | /* don't adjust zero - treat as uninitialzed */ | |
117 | if (hfs_time != 0) | |
118 | hfs_time += MAC_GMT_FACTOR; | |
119 | ||
120 | return (hfs_time); | |
121 | } | |
122 | ||
123 | ||
1c79356b A |
124 | Ptr NewPtrSysClear (Size byteCount) |
125 | { | |
126 | Ptr tmptr; | |
127 | MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK); | |
128 | if (tmptr) | |
129 | bzero(tmptr, byteCount); | |
130 | return tmptr; | |
131 | } | |
132 | ||
133 | ||
134 | ||
135 | Ptr NewPtr (Size byteCount) | |
136 | { | |
137 | Ptr tmptr; | |
138 | MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK); | |
139 | return tmptr; | |
140 | } | |
141 | ||
142 | ||
143 | void DisposePtr (Ptr p) | |
144 | { | |
145 | FREE (p, M_TEMP); | |
146 | } | |
147 | ||
148 | ||
149 | void DebugStr (ConstStr255Param debuggerMsg) | |
150 | { | |
151 | kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg[1]); | |
152 | DEBUG_BREAK; | |
153 | } | |
154 |