]> git.saurik.com Git - apple/hfs.git/blob - fsck_hfs/dfalib/SStubs.c
0223f5e42884803ccdaba9232219fb6ee7472ef4
[apple/hfs.git] / fsck_hfs / dfalib / SStubs.c
1 /*
2 * Copyright (c) 1999, 2002-2003, 2005-2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
12 *
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
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* SStubs.c */
24
25
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <errno.h>
30 #include <sys/time.h>
31
32 #include "Scavenger.h"
33 #include "../fsck_messages.h"
34
35
36 /*
37 * This is the straight GMT conversion constant:
38 * 00:00:00 January 1, 1970 - 00:00:00 January 1, 1904
39 * (3600 * 24 * ((365 * (1970 - 1904)) + (((1970 - 1904) / 4) + 1)))
40 */
41 #define MAC_GMT_FACTOR 2082844800UL
42
43 /*
44 * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904)
45 *
46 */
47 UInt32 GetTimeUTC(void)
48 {
49 struct timeval time;
50 struct timezone zone;
51
52 (void) gettimeofday(&time, &zone);
53
54 // Value will be bigger than UIN32_MAX in 2040
55 return (UInt32)(time.tv_sec + MAC_GMT_FACTOR);
56 }
57
58 /*
59 * GetTimeLocal - get the local Mac OS time (in seconds since 1/1/1904)
60 *
61 */
62 UInt32 GetTimeLocal(Boolean forHFS)
63 {
64 struct timeval time;
65 struct timezone zone;
66 time_t localTime;
67
68 (void) gettimeofday(&time, &zone);
69 localTime = time.tv_sec + MAC_GMT_FACTOR - (zone.tz_minuteswest * 60);
70
71 if (forHFS && zone.tz_dsttime)
72 localTime += 3600;
73
74 return (UInt32)localTime;
75 }
76
77
78 OSErr FlushVol(ConstStr63Param volName, short vRefNum)
79 {
80 sync();
81
82 return (0);
83 }
84
85
86 OSErr MemError()
87 {
88 return (0);
89 }
90
91 void DebugStr(ConstStr255Param debuggerMsg)
92 {
93 /* DebugStr is only called when built with DEBUG_BUILD set */
94 plog ("\t%.*s\n", debuggerMsg[0], &debuggerMsg[1]);
95 }
96
97
98 UInt32 TickCount()
99 {
100 return (0);
101 }
102
103
104 OSErr GetVolumeFeatures( SGlobPtr GPtr )
105 {
106 GPtr->volumeFeatures = supportsTrashVolumeCacheFeatureMask + supportsHFSPlusVolsFeatureMask;
107
108 return( noErr );
109 }
110
111
112 Handle NewHandleClear(Size byteCount)
113 {
114 return NewHandle(byteCount);
115 }
116
117 Handle NewHandle(Size byteCount)
118 {
119 Handle h;
120 Ptr p = NULL;
121
122 if (!(h = malloc(sizeof(Ptr) + sizeof(Size))))
123 return NULL;
124
125 if (byteCount)
126 if (!(p = calloc(1, byteCount)))
127 {
128 free(h);
129 return NULL;
130 }
131
132 *h = p;
133
134 *((Size *)(h + 1)) = byteCount;
135
136 return h;
137 }
138
139 void DisposeHandle(Handle h)
140 {
141 if (h)
142 {
143 if (*h)
144 free(*h);
145 free(h);
146 }
147 }
148
149 Size GetHandleSize(Handle h)
150 {
151 return h ? *((Size *)(h + 1)) : 0;
152 }
153
154 void SetHandleSize(Handle h, Size newSize)
155 {
156 Ptr p = NULL;
157
158 if (!h)
159 return;
160
161 if ((p = realloc(*h, newSize)))
162 {
163 *h = p;
164 *((Size *)(h + 1)) = newSize;
165 }
166 }
167
168
169 OSErr PtrAndHand(const void *ptr1, Handle hand2, long size)
170 {
171 Ptr p = NULL;
172 Size old_size = 0;
173
174 if (!hand2)
175 return -109;
176
177 if (!ptr1 || size < 1)
178 return 0;
179
180 old_size = *((Size *)(hand2 + 1));
181
182 if (!(p = realloc(*hand2, size + old_size)))
183 return -108;
184
185 *hand2 = p;
186 *((Size *)(hand2 + 1)) = size + old_size;
187
188 memcpy(*hand2 + old_size, ptr1, size);
189
190 return 0;
191 }
192
193
194 /* deprecated call, use fsckPrint() instead */
195 void WriteError( SGlobPtr GPtr, short msgID, UInt32 tarID, UInt64 tarBlock )
196 {
197 fsckPrint(GPtr->context, msgID);
198
199 if ((fsckGetVerbosity(GPtr->context) > 0) &&
200 (fsckGetOutputStyle(GPtr->context) == fsckOutputTraditional) &&
201 (tarID | tarBlock) != 0) {
202 plog("(%ld, %qd)\n", (long)tarID, tarBlock);
203 }
204 }