2 * Copyright (c) 1999, 2002-2003, 2005-2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
32 #include "Scavenger.h"
33 #include "../fsck_messages.h"
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)))
41 #define MAC_GMT_FACTOR 2082844800UL
44 * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904)
47 UInt32
GetTimeUTC(void)
52 (void) gettimeofday(&time
, &zone
);
54 return time
.tv_sec
+ MAC_GMT_FACTOR
;
58 * GetTimeLocal - get the local Mac OS time (in seconds since 1/1/1904)
61 UInt32
GetTimeLocal(Boolean forHFS
)
67 (void) gettimeofday(&time
, &zone
);
68 localTime
= time
.tv_sec
+ MAC_GMT_FACTOR
- (zone
.tz_minuteswest
* 60);
70 if (forHFS
&& zone
.tz_dsttime
)
73 return (UInt32
)localTime
;
77 OSErr
FlushVol(ConstStr63Param volName
, short vRefNum
)
90 void DebugStr(ConstStr255Param debuggerMsg
)
92 /* DebugStr is only called when built with DEBUG_BUILD set */
93 plog ("\t%.*s\n", debuggerMsg
[0], &debuggerMsg
[1]);
103 OSErr
GetVolumeFeatures( SGlobPtr GPtr
)
105 GPtr
->volumeFeatures
= supportsTrashVolumeCacheFeatureMask
+ supportsHFSPlusVolsFeatureMask
;
111 Handle
NewHandleClear(Size byteCount
)
113 return NewHandle(byteCount
);
116 Handle
NewHandle(Size byteCount
)
121 if (!(h
= malloc(sizeof(Ptr
) + sizeof(Size
))))
125 if (!(p
= calloc(1, byteCount
)))
133 *((Size
*)(h
+ 1)) = byteCount
;
138 void DisposeHandle(Handle h
)
148 Size
GetHandleSize(Handle h
)
150 return h
? *((Size
*)(h
+ 1)) : 0;
153 void SetHandleSize(Handle h
, Size newSize
)
160 if ((p
= realloc(*h
, newSize
)))
163 *((Size
*)(h
+ 1)) = newSize
;
168 OSErr
PtrAndHand(const void *ptr1
, Handle hand2
, long size
)
176 if (!ptr1
|| size
< 1)
179 old_size
= *((Size
*)(hand2
+ 1));
181 if (!(p
= realloc(*hand2
, size
+ old_size
)))
185 *((Size
*)(hand2
+ 1)) = size
+ old_size
;
187 memcpy(*hand2
+ old_size
, ptr1
, size
);
193 /* deprecated call, use fsckPrint() instead */
194 void WriteError( SGlobPtr GPtr
, short msgID
, UInt32 tarID
, UInt64 tarBlock
)
196 fsckPrint(GPtr
->context
, msgID
);
198 if ((fsckGetVerbosity(GPtr
->context
) > 0) &&
199 (fsckGetOutputStyle(GPtr
->context
) == fsckOutputTraditional
) &&
200 (tarID
| tarBlock
) != 0) {
201 plog("(%ld, %qd)\n", (long)tarID
, tarBlock
);