]> git.saurik.com Git - apple/hfs.git/blame - fsck_hfs/dfalib/SStubs.c
hfs-522.100.5.tar.gz
[apple/hfs.git] / fsck_hfs / dfalib / SStubs.c
CommitLineData
51e135ce
A
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 */
47UInt32 GetTimeUTC(void)
48{
49 struct timeval time;
50 struct timezone zone;
51
52 (void) gettimeofday(&time, &zone);
53
54 return time.tv_sec + MAC_GMT_FACTOR;
55}
56
57/*
58 * GetTimeLocal - get the local Mac OS time (in seconds since 1/1/1904)
59 *
60 */
61UInt32 GetTimeLocal(Boolean forHFS)
62{
63 struct timeval time;
64 struct timezone zone;
65 time_t localTime;
66
67 (void) gettimeofday(&time, &zone);
68 localTime = time.tv_sec + MAC_GMT_FACTOR - (zone.tz_minuteswest * 60);
69
70 if (forHFS && zone.tz_dsttime)
71 localTime += 3600;
72
73 return (UInt32)localTime;
74}
75
76
77OSErr FlushVol(ConstStr63Param volName, short vRefNum)
78{
79 sync();
80
81 return (0);
82}
83
84
85OSErr MemError()
86{
87 return (0);
88}
89
90void DebugStr(ConstStr255Param debuggerMsg)
91{
92 /* DebugStr is only called when built with DEBUG_BUILD set */
93 plog ("\t%.*s\n", debuggerMsg[0], &debuggerMsg[1]);
94}
95
96
97UInt32 TickCount()
98{
99 return (0);
100}
101
102
103OSErr GetVolumeFeatures( SGlobPtr GPtr )
104{
105 GPtr->volumeFeatures = supportsTrashVolumeCacheFeatureMask + supportsHFSPlusVolsFeatureMask;
106
107 return( noErr );
108}
109
110
111Handle NewHandleClear(Size byteCount)
112{
113 return NewHandle(byteCount);
114}
115
116Handle NewHandle(Size byteCount)
117{
118 Handle h;
119 Ptr p = NULL;
120
121 if (!(h = malloc(sizeof(Ptr) + sizeof(Size))))
122 return NULL;
123
124 if (byteCount)
125 if (!(p = calloc(1, byteCount)))
126 {
127 free(h);
128 return NULL;
129 }
130
131 *h = p;
132
133 *((Size *)(h + 1)) = byteCount;
134
135 return h;
136}
137
138void DisposeHandle(Handle h)
139{
140 if (h)
141 {
142 if (*h)
143 free(*h);
144 free(h);
145 }
146}
147
148Size GetHandleSize(Handle h)
149{
150 return h ? *((Size *)(h + 1)) : 0;
151}
152
153void SetHandleSize(Handle h, Size newSize)
154{
155 Ptr p = NULL;
156
157 if (!h)
158 return;
159
160 if ((p = realloc(*h, newSize)))
161 {
162 *h = p;
163 *((Size *)(h + 1)) = newSize;
164 }
165}
166
167
168OSErr PtrAndHand(const void *ptr1, Handle hand2, long size)
169{
170 Ptr p = NULL;
171 Size old_size = 0;
172
173 if (!hand2)
174 return -109;
175
176 if (!ptr1 || size < 1)
177 return 0;
178
179 old_size = *((Size *)(hand2 + 1));
180
181 if (!(p = realloc(*hand2, size + old_size)))
182 return -108;
183
184 *hand2 = p;
185 *((Size *)(hand2 + 1)) = size + old_size;
186
187 memcpy(*hand2 + old_size, ptr1, size);
188
189 return 0;
190}
191
192
193/* deprecated call, use fsckPrint() instead */
194void WriteError( SGlobPtr GPtr, short msgID, UInt32 tarID, UInt64 tarBlock )
195{
196 fsckPrint(GPtr->context, msgID);
197
198 if ((fsckGetVerbosity(GPtr->context) > 0) &&
199 (fsckGetOutputStyle(GPtr->context) == fsckOutputTraditional) &&
200 (tarID | tarBlock) != 0) {
201 plog("(%ld, %qd)\n", (long)tarID, tarBlock);
202 }
203}