]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/MacOSStubs.c
xnu-792.24.17.tar.gz
[apple/xnu.git] / bsd / hfs / MacOSStubs.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
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 */
22 #include <sys/param.h>
23 #include <sys/systm.h>
24 #include <sys/kernel.h>
25 #include <sys/malloc.h>
26 #include <sys/types.h>
27
28 #include "hfs.h"
29 #include "hfs_dbg.h"
30 #include "hfscommon/headers/FileMgrInternal.h"
31
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
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 struct timeval tv;
47
48 microtime(&tv);
49
50 return (tv.tv_sec + MAC_GMT_FACTOR);
51 }
52
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 */
100 time_t to_bsd_time(u_int32_t hfs_time)
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
109 return (time_t)gmt;
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 */
116 u_int32_t to_hfs_time(time_t bsd_time)
117 {
118 u_int32_t hfs_time = (u_int32_t)bsd_time;
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
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