1 | /*␊ |
2 | * Copyright (c) 2000-2003 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 2.0 (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 | /*␊ |
23 | * hfs.c - File System Module for HFS and HFS+.␊ |
24 | *␊ |
25 | * Copyright (c) 1999-2002 Apple Computer, Inc.␊ |
26 | *␊ |
27 | * DRI: Josh de Cesare␊ |
28 | */␊ |
29 | ␊ |
30 | #include <sl.h>␊ |
31 | #include <hfs/hfs_format.h>␊ |
32 | ␊ |
33 | #include "hfs.h"␊ |
34 | ␊ |
35 | #define kBlockSize (0x200)␊ |
36 | ␊ |
37 | #define kMDBBaseOffset (2 * kBlockSize)␊ |
38 | ␊ |
39 | #define kBTreeCatalog (0)␊ |
40 | #define kBTreeExtents (1)␊ |
41 | ␊ |
42 | #ifdef __i386__␊ |
43 | ␊ |
44 | static CICell gCurrentIH;␊ |
45 | static long long gAllocationOffset;␊ |
46 | static long gIsHFSPlus;␊ |
47 | static long gCaseSensitive;␊ |
48 | static long gBlockSize;␊ |
49 | static long gCacheBlockSize;␊ |
50 | static char *gBTreeHeaderBuffer;␊ |
51 | static BTHeaderRec *gBTHeaders[2];␊ |
52 | static char *gHFSMdbVib;␊ |
53 | static HFSMasterDirectoryBlock *gHFSMDB;␊ |
54 | static char *gHFSPlusHeader;␊ |
55 | static HFSPlusVolumeHeader *gHFSPlus;␊ |
56 | static char *gLinkTemp;␊ |
57 | static long long gVolID;␊ |
58 | static char *gTempStr;␊ |
59 | ␊ |
60 | #else /* !__i386__ */␊ |
61 | ␊ |
62 | static CICell gCurrentIH;␊ |
63 | static long long gAllocationOffset;␊ |
64 | static long gIsHFSPlus;␊ |
65 | static long gBlockSize;␊ |
66 | static long gCaseSensitive;␊ |
67 | static long gCacheBlockSize;␊ |
68 | static char gBTreeHeaderBuffer[512];␊ |
69 | static BTHeaderRec *gBTHeaders[2];␊ |
70 | static char gHFSMdbVib[kBlockSize];␊ |
71 | static HFSMasterDirectoryBlock *gHFSMDB =(HFSMasterDirectoryBlock*)gHFSMdbVib;␊ |
72 | static char gHFSPlusHeader[kBlockSize];␊ |
73 | static HFSPlusVolumeHeader *gHFSPlus =(HFSPlusVolumeHeader*)gHFSPlusHeader;␊ |
74 | static char gLinkTemp[64];␊ |
75 | static long long gVolID;␊ |
76 | ␊ |
77 | #endif /* !__i386__ */␊ |
78 | ␊ |
79 | static long ReadFile(void *file, uint64_t *length, void *base, uint64_t offset);␊ |
80 | static long GetCatalogEntryInfo(void *entry, long *flags, long *time, FinderInfo *finderInfo, long *infoValid);␊ |
81 | static long ResolvePathToCatalogEntry(char *filePath, long *flags, void *entry, long dirID, long long *dirIndex);␊ |
82 | ␊ |
83 | static long GetCatalogEntry(long long *dirIndex, char **name, long *flags, long *time, FinderInfo *finderInfo, long *infoValid);␊ |
84 | static long ReadCatalogEntry(char *fileName, long dirID, void *entry, long long *dirIndex);␊ |
85 | static long ReadExtentsEntry(long fileID, long startBlock, void *entry);␊ |
86 | ␊ |
87 | static long ReadBTreeEntry(long btree, void *key, char *entry, long long *dirIndex);␊ |
88 | static void GetBTreeRecord(long index, char *nodeBuffer, long nodeSize, char **key, char **data);␊ |
89 | ␊ |
90 | static long ReadExtent(char *extent, uint64_t extentSize, long extentFile, uint64_t offset, uint64_t size, void *buffer, long cache);␊ |
91 | ␊ |
92 | static long GetExtentStart(void *extents, long index);␊ |
93 | static long GetExtentSize(void *extents, long index);␊ |
94 | ␊ |
95 | static long CompareHFSCatalogKeys(void *key, void *testKey);␊ |
96 | static long CompareHFSPlusCatalogKeys(void *key, void *testKey);␊ |
97 | static long CompareHFSExtentsKeys(void *key, void *testKey);␊ |
98 | static long CompareHFSPlusExtentsKeys(void *key, void *testKey);␊ |
99 | ␊ |
100 | extern long FastRelString(u_int8_t *str1, u_int8_t *str2);␊ |
101 | extern long BinaryUnicodeCompare(u_int16_t *uniStr1, u_int32_t len1, u_int16_t *uniStr2, u_int32_t len2);␊ |
102 | ␊ |
103 | ␊ |
104 | //==============================================================================␊ |
105 | ␊ |
106 | static void SwapFinderInfo(FndrFileInfo *dst, FndrFileInfo *src)␊ |
107 | {␊ |
108 | ␉dst->fdType = SWAP_BE32(src->fdType);␊ |
109 | ␉dst->fdCreator = SWAP_BE32(src->fdCreator);␊ |
110 | ␉dst->fdFlags = SWAP_BE16(src->fdFlags);␊ |
111 | ␉// Don't bother with location␊ |
112 | }␊ |
113 | ␊ |
114 | ␊ |
115 | //==============================================================================␊ |
116 | ␊ |
117 | void HFSFree(CICell ih)␊ |
118 | {␊ |
119 | ␉if(gCurrentIH == ih)␊ |
120 | ␉{␊ |
121 | ␉␉gCurrentIH = 0;␊ |
122 | ␉}␊ |
123 | ␉free(ih);␊ |
124 | }␊ |
125 | ␊ |
126 | ␊ |
127 | //==============================================================================␊ |
128 | ␊ |
129 | bool HFSProbe (const void *buf)␊ |
130 | {␊ |
131 | ␉const HFSMasterDirectoryBlock *mdb;␊ |
132 | ␉const HFSPlusVolumeHeader *header;␊ |
133 | ␉mdb = (const HFSMasterDirectoryBlock *)(((const char*)buf)+kMDBBaseOffset);␊ |
134 | ␉header = (const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset);␊ |
135 | ␉␊ |
136 | ␉if ( SWAP_BE16(mdb->drSigWord) == kHFSSigWord )␊ |
137 | ␉{␊ |
138 | ␉␉return true;␊ |
139 | ␉}␊ |
140 | ␊ |
141 | ␉if (SWAP_BE16(header->signature) != kHFSPlusSigWord && SWAP_BE16(header->signature) != kHFSXSigWord)␊ |
142 | ␉{␊ |
143 | ␉␉return false;␊ |
144 | ␉}␊ |
145 | ␉return true;␊ |
146 | }␊ |
147 | ␊ |
148 | ␊ |
149 | //==============================================================================␊ |
150 | ␊ |
151 | long HFSInitPartition(CICell ih)␊ |
152 | {␊ |
153 | ␉long extentSize, extentFile, nodeSize;␊ |
154 | ␉void *extent;␊ |
155 | ␊ |
156 | ␉if (ih == gCurrentIH)␊ |
157 | ␉{␊ |
158 | #ifdef __i386__␊ |
159 | ␉␉CacheInit(ih, gCacheBlockSize);␊ |
160 | #endif␊ |
161 | ␉return 0;␊ |
162 | ␉}␊ |
163 | ␊ |
164 | #ifdef __i386__␊ |
165 | ␉if (!gTempStr)␊ |
166 | ␉{␊ |
167 | ␉␉gTempStr = (char *)malloc(4096);␊ |
168 | ␉}␊ |
169 | ␉if (!gLinkTemp)␊ |
170 | ␉{␊ |
171 | ␉␉gLinkTemp = (char *)malloc(64);␊ |
172 | ␉}␊ |
173 | ␉if (!gBTreeHeaderBuffer)␊ |
174 | ␉{␊ |
175 | ␉␉gBTreeHeaderBuffer = (char *)malloc(512);␊ |
176 | ␉}␊ |
177 | ␉if (!gHFSMdbVib)␊ |
178 | ␉{␊ |
179 | ␉␉gHFSMdbVib = (char *)malloc(kBlockSize);␊ |
180 | ␉␉gHFSMDB = (HFSMasterDirectoryBlock *)gHFSMdbVib;␊ |
181 | ␉}␊ |
182 | ␉if (!gHFSPlusHeader)␊ |
183 | ␉{␊ |
184 | ␉␉gHFSPlusHeader = (char *)malloc(kBlockSize);␊ |
185 | ␉␉gHFSPlus = (HFSPlusVolumeHeader *)gHFSPlusHeader;␊ |
186 | ␉}␊ |
187 | ␉if (!gTempStr || !gLinkTemp || !gBTreeHeaderBuffer || !gHFSMdbVib || !gHFSPlusHeader)␊ |
188 | ␉{␊ |
189 | ␉␉return -1;␊ |
190 | ␉}␊ |
191 | #endif /* __i386__ */␊ |
192 | ␊ |
193 | ␉gAllocationOffset = 0;␊ |
194 | ␉gIsHFSPlus = 0;␊ |
195 | ␉gCaseSensitive = 0;␊ |
196 | ␉gBTHeaders[0] = 0;␊ |
197 | ␉gBTHeaders[1] = 0;␊ |
198 | ␊ |
199 | ␉// Look for the HFS MDB␊ |
200 | ␉Seek(ih, kMDBBaseOffset);␊ |
201 | ␉Read(ih, (long)gHFSMdbVib, kBlockSize);␊ |
202 | ␊ |
203 | ␉if (SWAP_BE16(gHFSMDB->drSigWord) == kHFSSigWord)␊ |
204 | ␉{␊ |
205 | ␉␉gAllocationOffset = SWAP_BE16(gHFSMDB->drAlBlSt) * kBlockSize;␊ |
206 | ␊ |
207 | ␉␉// See if it is HFSPlus␊ |
208 | ␉␉if (SWAP_BE16(gHFSMDB->drEmbedSigWord) != kHFSPlusSigWord)␊ |
209 | ␉␉{␊ |
210 | ␉␉␉// Normal HFS;␊ |
211 | ␉␉␉gCacheBlockSize = gBlockSize = SWAP_BE32(gHFSMDB->drAlBlkSiz);␊ |
212 | ␉␉␉CacheInit(ih, gCacheBlockSize);␊ |
213 | ␉␉␉gCurrentIH = ih;␊ |
214 | ␊ |
215 | ␉␉␉// grab the 64 bit volume ID␊ |
216 | ␉␉␉bcopy(&gHFSMDB->drFndrInfo[6], &gVolID, 8);␊ |
217 | ␊ |
218 | ␉␉␉// Get the Catalog BTree node size.␊ |
219 | ␉␉␉extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;␊ |
220 | ␉␉␉extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);␊ |
221 | ␉␉␉extentFile = kHFSCatalogFileID;␊ |
222 | ␉␉␉ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + kBTreeCatalog * 256, 0);␊ |
223 | ␊ |
224 | ␉␉␉nodeSize = SWAP_BE16(((BTHeaderRec *)(gBTreeHeaderBuffer + kBTreeCatalog * 256 + sizeof(BTNodeDescriptor)))->nodeSize);␊ |
225 | ␊ |
226 | ␉␉␉// If the BTree node size is larger than the block size, reset the cache.␊ |
227 | ␉␉␉if (nodeSize > gBlockSize)␊ |
228 | ␉␉␉{␊ |
229 | ␉␉␉␉gCacheBlockSize = nodeSize;␊ |
230 | ␉␉␉␉CacheInit(ih, gCacheBlockSize);␊ |
231 | ␉␉␉}␊ |
232 | ␊ |
233 | ␉␉return 0;␊ |
234 | ␉␉}␊ |
235 | ␊ |
236 | ␉␉// Calculate the offset to the embeded HFSPlus volume.␊ |
237 | ␉␉gAllocationOffset += (long long)SWAP_BE16(gHFSMDB->drEmbedExtent.startBlock) *␊ |
238 | SWAP_BE32(gHFSMDB->drAlBlkSiz);␊ |
239 | ␉}␊ |
240 | ␊ |
241 | ␉// Look for the HFSPlus Header␊ |
242 | ␉Seek(ih, gAllocationOffset + kMDBBaseOffset);␊ |
243 | ␉Read(ih, (long)gHFSPlusHeader, kBlockSize);␊ |
244 | ␊ |
245 | ␉// Not a HFS+ or HFSX volume.␊ |
246 | ␉if (SWAP_BE16(gHFSPlus->signature) != kHFSPlusSigWord && SWAP_BE16(gHFSPlus->signature) != kHFSXSigWord)␊ |
247 | ␉{␊ |
248 | ␉␉verbose("HFS signature was not present.\n");␊ |
249 | ␉␉gCurrentIH = 0;␊ |
250 | ␉␉return -1;␊ |
251 | ␉}␊ |
252 | ␊ |
253 | ␉gIsHFSPlus = 1;␊ |
254 | ␉gCacheBlockSize = gBlockSize = SWAP_BE32(gHFSPlus->blockSize);␊ |
255 | ␉CacheInit(ih, gCacheBlockSize);␊ |
256 | ␉gCurrentIH = ih;␊ |
257 | ␊ |
258 | ␉ih->modTime = SWAP_BE32(gHFSPlus->modifyDate) - 2082844800;␊ |
259 | ␊ |
260 | ␉// grab the 64 bit volume ID␊ |
261 | ␉bcopy(&gHFSPlus->finderInfo[24], &gVolID, 8);␊ |
262 | ␊ |
263 | ␉// Get the Catalog BTree node size.␊ |
264 | ␉extent = &gHFSPlus->catalogFile.extents;␊ |
265 | ␉extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize);␊ |
266 | ␉extentFile = kHFSCatalogFileID;␊ |
267 | ␊ |
268 | ␉ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + kBTreeCatalog * 256, 0);␊ |
269 | ␊ |
270 | ␉nodeSize = SWAP_BE16(((BTHeaderRec *)(gBTreeHeaderBuffer + kBTreeCatalog * 256 + sizeof(BTNodeDescriptor)))->nodeSize);␊ |
271 | ␊ |
272 | ␉// If the BTree node size is larger than the block size, reset the cache.␊ |
273 | ␉if (nodeSize > gBlockSize)␊ |
274 | ␉{␊ |
275 | ␉␉gCacheBlockSize = nodeSize;␊ |
276 | ␉␉CacheInit(ih, gCacheBlockSize);␊ |
277 | ␉}␊ |
278 | ␊ |
279 | ␉return 0;␊ |
280 | }␊ |
281 | ␊ |
282 | ␊ |
283 | //==============================================================================␊ |
284 | ␊ |
285 | long HFSLoadFile(CICell ih, char * filePath)␊ |
286 | {␊ |
287 | ␉return HFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);␊ |
288 | }␊ |
289 | ␊ |
290 | long HFSReadFile(CICell ih, char * filePath, void *base, uint64_t offset, uint64_t length)␊ |
291 | {␊ |
292 | ␉char entry[512];␊ |
293 | ␉char devStr[12];␊ |
294 | ␉long dirID, result, flags =0;␊ |
295 | ␊ |
296 | ␉if (HFSInitPartition(ih) == -1)␊ |
297 | ␉{␊ |
298 | ␉␉return -1;␊ |
299 | ␉}␊ |
300 | ␊ |
301 | ␉dirID = kHFSRootFolderID;␊ |
302 | ␉// Skip a lead '\'. Start in the system folder if there are two.␊ |
303 | ␉if (filePath[0] == '/')␊ |
304 | ␉{␊ |
305 | ␉␉if (filePath[1] == '/')␊ |
306 | ␉␉{␊ |
307 | ␉␉␉if (gIsHFSPlus)␊ |
308 | ␉␉␉{␊ |
309 | ␉␉␉␉dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]);␊ |
310 | ␉␉␉}␊ |
311 | ␉␉␉else␊ |
312 | ␉␉␉{␊ |
313 | ␉␉␉␉dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);␊ |
314 | ␉␉␉}␊ |
315 | ␊ |
316 | ␉␉␉if (dirID == 0)␊ |
317 | ␉␉␉{␊ |
318 | ␉␉␉␉return -1;␊ |
319 | ␉␉␉}␊ |
320 | ␊ |
321 | ␉␉␉filePath++;␊ |
322 | ␉␉}␊ |
323 | ␊ |
324 | ␉␉filePath++;␊ |
325 | ␉}␊ |
326 | ␊ |
327 | ␉result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0);␊ |
328 | ␊ |
329 | ␉if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
330 | ␉{␊ |
331 | ␉␉return -1;␊ |
332 | ␉}␊ |
333 | ␊ |
334 | #if UNUSED␊ |
335 | ␉// Not yet for Intel. System.config/Default.table will fail this check.␊ |
336 | ␉// Check file owner and permissions.␊ |
337 | ␉if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite))␊ |
338 | ␉{␊ |
339 | ␉␉return -1;␊ |
340 | ␉}␊ |
341 | #endif␊ |
342 | ␊ |
343 | ␉result = ReadFile(entry, &length, base, offset);␊ |
344 | ␉if (result == -1)␊ |
345 | ␉{␊ |
346 | ␉␉return -1;␊ |
347 | ␉}␊ |
348 | ␊ |
349 | ␉getDeviceDescription(ih, devStr);␊ |
350 | /*␊ |
351 | ␉verbose("Read HFS%s file: [%s/%s] %d bytes.\n", (gIsHFSPlus ? "+" : ""), devStr, filePath, (uint32_t)length);␊ |
352 | */␊ |
353 | ␉return length;␊ |
354 | }␊ |
355 | ␊ |
356 | long HFSGetDirEntry(CICell ih, char * dirPath, long long * dirIndex, char ** name, long * flags, long * time, FinderInfo * finderInfo, long * infoValid)␊ |
357 | {␊ |
358 | ␉char entry[512];␊ |
359 | ␊ |
360 | ␉long dirID, dirFlags = 0;␊ |
361 | ␊ |
362 | ␉if (HFSInitPartition(ih) == -1)␊ |
363 | ␉{␊ |
364 | ␉␉return -1;␊ |
365 | ␉}␊ |
366 | ␊ |
367 | ␉if (*dirIndex == -1)␊ |
368 | ␉{␊ |
369 | ␉␉return -1;␊ |
370 | ␉}␊ |
371 | ␊ |
372 | ␉dirID = kHFSRootFolderID;␊ |
373 | ␊ |
374 | ␉// Skip a lead '\'. Start in the system folder if there are two.␊ |
375 | ␉if (dirPath[0] == '/')␊ |
376 | ␉{␊ |
377 | ␉␉if (dirPath[1] == '/')␊ |
378 | ␉␉{␊ |
379 | ␉␉␉if (gIsHFSPlus)␊ |
380 | ␉␉␉{␊ |
381 | ␉␉␉␉dirID = SWAP_BE32(((long *)gHFSPlus->finderInfo)[5]);␊ |
382 | ␉␉␉}␊ |
383 | ␉␉␉else␊ |
384 | ␉␉␉{␊ |
385 | ␉␉␉␉dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);␊ |
386 | ␉␉␉}␊ |
387 | ␊ |
388 | ␉␉␉if (dirID == 0)␊ |
389 | ␉␉␉{␊ |
390 | ␉␉␉␉return -1;␊ |
391 | ␉␉␉}␊ |
392 | ␊ |
393 | ␉␉␉dirPath++;␊ |
394 | ␉␉}␊ |
395 | ␊ |
396 | ␉␉dirPath++;␊ |
397 | ␉}␊ |
398 | ␊ |
399 | ␉if (*dirIndex == 0)␊ |
400 | ␉{␊ |
401 | ␉␉ResolvePathToCatalogEntry(dirPath, &dirFlags, entry, dirID, dirIndex);␊ |
402 | ␊ |
403 | ␉␉if (*dirIndex == 0)␊ |
404 | ␉␉{␊ |
405 | ␉␉␉*dirIndex = -1;␊ |
406 | ␉␉}␊ |
407 | ␊ |
408 | ␉␉if ((dirFlags & kFileTypeMask) != kFileTypeUnknown)␊ |
409 | ␉␉{␊ |
410 | ␉␉␉return -1;␊ |
411 | ␉␉}␊ |
412 | ␉}␊ |
413 | ␊ |
414 | ␉GetCatalogEntry(dirIndex, name, flags, time, finderInfo, infoValid);␊ |
415 | ␊ |
416 | ␉if (*dirIndex == 0)␊ |
417 | ␉{␊ |
418 | ␉␉*dirIndex = -1;␊ |
419 | ␉}␊ |
420 | ␊ |
421 | ␉if ((*flags & kFileTypeMask) == kFileTypeUnknown)␊ |
422 | ␉{␊ |
423 | ␉␉return -1;␊ |
424 | ␉}␊ |
425 | ␊ |
426 | ␉return 0;␊ |
427 | }␊ |
428 | ␊ |
429 | //==============================================================================␊ |
430 | ␊ |
431 | void HFSGetDescription(CICell ih, char *str, long strMaxLen)␊ |
432 | {␊ |
433 | ␊ |
434 | ␉UInt16 nodeSize;␊ |
435 | ␉UInt32 firstLeafNode;␊ |
436 | ␉long long dirIndex;␊ |
437 | ␉char *name;␊ |
438 | ␉long flags =0, time;␊ |
439 | ␊ |
440 | ␉if (HFSInitPartition(ih) == -1)␊ |
441 | ␉{␊ |
442 | ␉␉return;␊ |
443 | ␉}␊ |
444 | ␊ |
445 | ␉/* Fill some crucial data structures by side effect. */␊ |
446 | ␉dirIndex = 0;␊ |
447 | ␉HFSGetDirEntry(ih, "/", &dirIndex, &name, &flags, &time, 0, 0);␊ |
448 | ␊ |
449 | ␉/* Now we can loook up the volume name node. */␊ |
450 | ␉nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize);␊ |
451 | ␉firstLeafNode = SWAP_BE32(gBTHeaders[kBTreeCatalog]->firstLeafNode);␊ |
452 | ␊ |
453 | ␉dirIndex = (long long) firstLeafNode * nodeSize;␊ |
454 | ␊ |
455 | ␉GetCatalogEntry(&dirIndex, &name, &flags, &time, 0, 0);␊ |
456 | ␊ |
457 | ␉strncpy(str, name, strMaxLen);␊ |
458 | ␉str[strMaxLen] = '\0';␊ |
459 | }␊ |
460 | ␊ |
461 | ␊ |
462 | //==============================================================================␊ |
463 | ␊ |
464 | long HFSGetFileBlock(CICell ih, char *filePath, unsigned long long *firstBlock)␊ |
465 | {␊ |
466 | ␉char entry[512];␊ |
467 | ␉long dirID, result, flags =0;␊ |
468 | ␉void *extents;␊ |
469 | ␉HFSCatalogFile *hfsFile = (void *)entry;␊ |
470 | ␉HFSPlusCatalogFile *hfsPlusFile = (void *)entry;␊ |
471 | ␊ |
472 | ␉if (HFSInitPartition(ih) == -1)␊ |
473 | ␉{␊ |
474 | ␉␉return -1;␊ |
475 | ␉}␊ |
476 | ␊ |
477 | ␉dirID = kHFSRootFolderID;␊ |
478 | ␊ |
479 | ␉// Skip a lead '\'. Start in the system folder if there are two.␊ |
480 | ␊ |
481 | ␉if (filePath[0] == '/')␊ |
482 | ␉{␊ |
483 | ␉␉if (filePath[1] == '/')␊ |
484 | ␉␉{␊ |
485 | ␉␉␉if (gIsHFSPlus)␊ |
486 | ␉␉␉{␊ |
487 | ␉␉␉␉dirID = SWAP_BE32(((long *) gHFSPlus->finderInfo)[5]);␊ |
488 | ␉␉␉}␊ |
489 | ␉␉␉else␊ |
490 | ␉␉␉{␊ |
491 | ␉␉␉␉dirID = SWAP_BE32(gHFSMDB->drFndrInfo[5]);␊ |
492 | ␉␉␉}␊ |
493 | ␊ |
494 | ␉␉␉if (dirID == 0)␊ |
495 | ␉␉␉{␊ |
496 | ␉␉␉␉return -1;␊ |
497 | ␉␉␉}␊ |
498 | ␉␉␉filePath++;␊ |
499 | ␉␉}␊ |
500 | ␉␉filePath++;␊ |
501 | ␉}␊ |
502 | ␊ |
503 | ␉result = ResolvePathToCatalogEntry(filePath, &flags, entry, dirID, 0);␊ |
504 | ␊ |
505 | ␉if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
506 | ␉{␊ |
507 | ␉␉printf("HFS: Resolve path %s failed\n", filePath);␊ |
508 | ␉␉return -1;␊ |
509 | ␉}␊ |
510 | ␊ |
511 | ␉if (gIsHFSPlus)␊ |
512 | ␉{␊ |
513 | ␉␉extents = &hfsPlusFile->dataFork.extents;␊ |
514 | ␉}␊ |
515 | ␉else␊ |
516 | ␉{␊ |
517 | ␉␉extents = &hfsFile->dataExtents;␊ |
518 | ␉}␊ |
519 | ␊ |
520 | #if DEBUG␊ |
521 | ␉printf("extent start 0x%x\n", (unsigned long)GetExtentStart(extents, 0));␊ |
522 | ␉printf("block size 0x%x\n", (unsigned long)gBlockSize);␊ |
523 | ␉printf("Allocation offset 0x%x\n", (unsigned long)gAllocationOffset);␊ |
524 | #endif␊ |
525 | ␊ |
526 | ␉*firstBlock = ((unsigned long long)GetExtentStart(extents, 0) * (unsigned long long) gBlockSize + gAllocationOffset) / 512ULL;␊ |
527 | ␊ |
528 | ␉return 0;␊ |
529 | }␊ |
530 | ␊ |
531 | ␊ |
532 | //==============================================================================␊ |
533 | ␊ |
534 | long HFSGetUUID(CICell ih, char *uuidStr)␊ |
535 | {␊ |
536 | ␉if (HFSInitPartition(ih) == -1)␊ |
537 | ␉{␊ |
538 | ␉␉return -1;␊ |
539 | ␉}␊ |
540 | ␊ |
541 | ␉if (gVolID == 0LL)␊ |
542 | ␉{␊ |
543 | ␉␉return -1;␊ |
544 | ␉}␊ |
545 | ␊ |
546 | ␉return CreateUUIDString((uint8_t*)(&gVolID), sizeof(gVolID), uuidStr);␊ |
547 | }␊ |
548 | ␊ |
549 | //==============================================================================␊ |
550 | // Private Functions␊ |
551 | ␊ |
552 | static long ReadFile(void * file, uint64_t * length, void * base, uint64_t offset)␊ |
553 | {␊ |
554 | ␉void␉␉␉*extents;␊ |
555 | ␉long␉␉␉fileID;␊ |
556 | ␊ |
557 | ␉uint64_t␉␉fileLength;␊ |
558 | ␊ |
559 | ␉HFSCatalogFile␉␉*hfsFile = file;␊ |
560 | ␉HFSPlusCatalogFile␉*hfsPlusFile = file;␊ |
561 | ␊ |
562 | ␉if (gIsHFSPlus)␊ |
563 | ␉{␊ |
564 | ␉␉fileID = SWAP_BE32(hfsPlusFile->fileID);␊ |
565 | ␉␉fileLength = (uint64_t)SWAP_BE64(hfsPlusFile->dataFork.logicalSize);␊ |
566 | ␉␉extents = &hfsPlusFile->dataFork.extents;␊ |
567 | ␉}␊ |
568 | ␉else␊ |
569 | ␉{␊ |
570 | ␉␉fileID = SWAP_BE32(hfsFile->fileID);␊ |
571 | ␉␉fileLength = SWAP_BE32(hfsFile->dataLogicalSize);␊ |
572 | ␉␉extents = &hfsFile->dataExtents;␊ |
573 | ␉}␊ |
574 | ␊ |
575 | ␉if (offset > fileLength)␊ |
576 | ␉{␊ |
577 | ␉␉printf("Offset is too large.\n");␊ |
578 | ␊ |
579 | ␉␉return -1;␊ |
580 | ␉}␊ |
581 | ␊ |
582 | ␉if ((*length == 0) || ((offset + *length) > fileLength))␊ |
583 | ␉{␊ |
584 | ␉␉*length = fileLength - offset;␊ |
585 | ␉}␊ |
586 | ␊ |
587 | /*␊ |
588 | ␉if (*length > kLoadSize)␊ |
589 | ␉{␊ |
590 | ␉␉printf("File is too large.\n");␊ |
591 | ␉␉return -1;␊ |
592 | ␉}␊ |
593 | */␊ |
594 | ␊ |
595 | ␉*length = ReadExtent((char *)extents, fileLength, fileID, offset, *length, (char *)base, 0);␊ |
596 | ␊ |
597 | ␉return 0;␊ |
598 | }␊ |
599 | ␊ |
600 | //==============================================================================␊ |
601 | ␊ |
602 | static long GetCatalogEntryInfo(void * entry, long * flags, long * time, FinderInfo * finderInfo, long * infoValid)␊ |
603 | {␊ |
604 | ␉long tmpTime = 0;␊ |
605 | ␉long valid = 0;␊ |
606 | ␊ |
607 | ␉// Get information about the file.␊ |
608 | ␊ |
609 | ␉switch (SWAP_BE16(*(short *)entry))␊ |
610 | ␉{␊ |
611 | ␉case kHFSFolderRecord :␊ |
612 | ␉␉*flags = kFileTypeDirectory;␊ |
613 | ␉␉tmpTime = SWAP_BE32(((HFSCatalogFolder *)entry)->modifyDate);␊ |
614 | ␉␉break;␊ |
615 | ␊ |
616 | ␉case kHFSPlusFolderRecord :␊ |
617 | ␉␉*flags = kFileTypeDirectory | (SWAP_BE16(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode) & kPermMask);␊ |
618 | ␉␉if (SWAP_BE32(((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID) != 0)␊ |
619 | ␉␉{␊ |
620 | ␉␉␉*flags |= kOwnerNotRoot;␊ |
621 | ␉␉}␊ |
622 | ␉␉tmpTime = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->contentModDate);␊ |
623 | ␉␉break;␊ |
624 | ␊ |
625 | ␉case kHFSFileRecord :␊ |
626 | ␉␉*flags = kFileTypeFlat;␊ |
627 | ␉␉tmpTime = SWAP_BE32(((HFSCatalogFile *)entry)->modifyDate);␊ |
628 | ␉␉if (finderInfo)␊ |
629 | ␉␉{␊ |
630 | ␉␉␉SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSCatalogFile *)entry)->userInfo);␊ |
631 | ␉␉␉valid = 1;␊ |
632 | ␉␉}␊ |
633 | ␉␉break;␊ |
634 | ␊ |
635 | ␉case kHFSPlusFileRecord :␊ |
636 | ␉␉*flags = kFileTypeFlat | (SWAP_BE16(((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode) & kPermMask);␊ |
637 | ␉␉if (SWAP_BE32(((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID) != 0)␊ |
638 | ␉␉{␊ |
639 | ␉␉␉*flags |= kOwnerNotRoot;␊ |
640 | ␉␉}␊ |
641 | ␉␉tmpTime = SWAP_BE32(((HFSPlusCatalogFile *)entry)->contentModDate);␊ |
642 | ␉␉if (finderInfo)␊ |
643 | ␉␉{␊ |
644 | ␉␉␉SwapFinderInfo((FndrFileInfo *)finderInfo, &((HFSPlusCatalogFile *)entry)->userInfo);␊ |
645 | ␉␉␉valid = 1;␊ |
646 | ␉␉}␊ |
647 | ␉␉break;␊ |
648 | ␊ |
649 | ␉case kHFSFileThreadRecord :␊ |
650 | ␉case kHFSPlusFileThreadRecord :␊ |
651 | ␉case kHFSFolderThreadRecord :␊ |
652 | ␉case kHFSPlusFolderThreadRecord :␊ |
653 | ␉␉*flags = kFileTypeUnknown;␊ |
654 | ␉␉tmpTime = 0;␊ |
655 | ␉␉break;␊ |
656 | ␉default:␊ |
657 | ␉␉break;␊ |
658 | ␉}␊ |
659 | ␊ |
660 | ␉if (time != 0)␊ |
661 | ␉{␊ |
662 | ␉␉// Convert base time from 1904 to 1970.␊ |
663 | ␉␉*time = tmpTime - 2082844800;␊ |
664 | ␉}␊ |
665 | ␊ |
666 | ␉if (infoValid)␊ |
667 | ␉{␊ |
668 | ␉␉*infoValid = valid;␊ |
669 | ␉}␊ |
670 | ␊ |
671 | ␉return 0;␊ |
672 | }␊ |
673 | ␊ |
674 | ␊ |
675 | //==============================================================================␊ |
676 | ␊ |
677 | static long ResolvePathToCatalogEntry(char * filePath, long * flags, void * entry, long dirID, long long * dirIndex)␊ |
678 | {␊ |
679 | ␉char␉␉␉*restPath;␊ |
680 | ␉long␉␉␉result, cnt, subFolderID = 0;␊ |
681 | ␉long long␉␉tmpDirIndex;␊ |
682 | ␉HFSPlusCatalogFile␉*hfsPlusFile;␊ |
683 | ␊ |
684 | ␉// Copy the file name to gTempStr␊ |
685 | ␉cnt = 0;␊ |
686 | ␉while ((filePath[cnt] != '/') && (filePath[cnt] != '\0'))␊ |
687 | ␉{␊ |
688 | ␉␉cnt++;␊ |
689 | ␉}␊ |
690 | ␊ |
691 | ␉strlcpy(gTempStr, filePath, cnt+1);␊ |
692 | ␊ |
693 | ␉// Move restPath to the right place.␊ |
694 | ␉if (filePath[cnt] != '\0')␊ |
695 | ␉{␊ |
696 | ␉␉cnt++;␊ |
697 | ␉}␊ |
698 | ␊ |
699 | ␉restPath = filePath + cnt;␊ |
700 | ␊ |
701 | ␉// gTempStr is a name in the current Dir.␊ |
702 | ␉// restPath is the rest of the path if any.␊ |
703 | ␊ |
704 | ␉result = ReadCatalogEntry(gTempStr, dirID, entry, dirIndex);␊ |
705 | ␊ |
706 | ␉if (result == -1)␊ |
707 | ␉{␊ |
708 | ␉␉return -1;␊ |
709 | ␉}␊ |
710 | ␊ |
711 | ␉GetCatalogEntryInfo(entry, flags, 0, 0, 0);␊ |
712 | ␊ |
713 | ␉if ((*flags & kFileTypeMask) == kFileTypeDirectory)␊ |
714 | ␉{␊ |
715 | ␉␉if (gIsHFSPlus)␊ |
716 | ␉␉{␊ |
717 | ␉␉␉subFolderID = SWAP_BE32(((HFSPlusCatalogFolder *)entry)->folderID);␊ |
718 | ␉␉}␊ |
719 | ␉␉else␊ |
720 | ␉␉{␊ |
721 | ␉␉␉subFolderID = SWAP_BE32(((HFSCatalogFolder *)entry)->folderID);␊ |
722 | ␉␉}␊ |
723 | ␉}␊ |
724 | ␊ |
725 | ␉if ((*flags & kFileTypeMask) == kFileTypeDirectory)␊ |
726 | ␉{␊ |
727 | ␉␉result = ResolvePathToCatalogEntry(restPath, flags, entry, subFolderID, dirIndex);␊ |
728 | ␉}␊ |
729 | ␊ |
730 | ␉if (gIsHFSPlus && ((*flags & kFileTypeMask) == kFileTypeFlat))␊ |
731 | ␉{␊ |
732 | ␉␉hfsPlusFile = (HFSPlusCatalogFile *)entry;␊ |
733 | ␊ |
734 | ␉␉if ((SWAP_BE32(hfsPlusFile->userInfo.fdType) == kHardLinkFileType) && (SWAP_BE32(hfsPlusFile->userInfo.fdCreator) == kHFSPlusCreator))␊ |
735 | ␉␉{␊ |
736 | ␉␉␉sprintf(gLinkTemp, "%s/%s%ld", HFSPLUSMETADATAFOLDER, HFS_INODE_PREFIX, SWAP_BE32(hfsPlusFile->bsdInfo.special.iNodeNum));␊ |
737 | ␉␉␉result = ResolvePathToCatalogEntry(gLinkTemp, flags, entry, kHFSRootFolderID, &tmpDirIndex);␊ |
738 | ␉␉}␊ |
739 | ␉}␊ |
740 | ␊ |
741 | ␉return result;␊ |
742 | }␊ |
743 | ␊ |
744 | ␊ |
745 | //==============================================================================␊ |
746 | ␊ |
747 | static long GetCatalogEntry(long long * dirIndex, char ** name, long * flags, long * time, FinderInfo * finderInfo, long * infoValid)␊ |
748 | {␊ |
749 | ␉long extentSize, nodeSize, curNode, index;␊ |
750 | ␉void *extent;␊ |
751 | ␉char *nodeBuf, *testKey, *entry;␊ |
752 | ␉BTNodeDescriptor *node;␊ |
753 | ␊ |
754 | ␉if (gIsHFSPlus)␊ |
755 | ␉{␊ |
756 | ␉␉extent = &gHFSPlus->catalogFile.extents;␊ |
757 | ␉␉extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize);␊ |
758 | ␉}␊ |
759 | ␉else␊ |
760 | ␉{␊ |
761 | ␉␉extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;␊ |
762 | ␉␉extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);␊ |
763 | ␉}␊ |
764 | ␊ |
765 | ␉nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize);␊ |
766 | ␉nodeBuf = (char *)malloc(nodeSize);␊ |
767 | ␉node = (BTNodeDescriptor *)nodeBuf;␊ |
768 | ␊ |
769 | ␉index = (long) (*dirIndex % nodeSize);␊ |
770 | ␉curNode = (long) (*dirIndex / nodeSize);␊ |
771 | ␊ |
772 | ␉// Read the BTree node and get the record for index.␊ |
773 | ␉ReadExtent(extent, extentSize, kHFSCatalogFileID, (long long) curNode * nodeSize, nodeSize, nodeBuf, 1);␊ |
774 | ␉GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &entry);␊ |
775 | ␊ |
776 | ␉GetCatalogEntryInfo(entry, flags, time, finderInfo, infoValid);␊ |
777 | ␊ |
778 | ␉// Get the file name.␊ |
779 | ␉if (gIsHFSPlus)␊ |
780 | ␉{␊ |
781 | ␉␉utf_encodestr(((HFSPlusCatalogKey *)testKey)->nodeName.unicode,␊ |
782 | SWAP_BE16(((HFSPlusCatalogKey *)testKey)->nodeName.length),␊ |
783 | (u_int8_t *)gTempStr, 256, OSBigEndian);␊ |
784 | ␉}␊ |
785 | ␉else␊ |
786 | ␉{␊ |
787 | ␉␉strncpy(gTempStr, (const char *)&((HFSCatalogKey *)testKey)->nodeName[1], ((HFSCatalogKey *)testKey)->nodeName[0]);␊ |
788 | ␊ |
789 | ␉␉gTempStr[((HFSCatalogKey *)testKey)->nodeName[0]] = '\0';␊ |
790 | ␉}␊ |
791 | ␉*name = gTempStr;␊ |
792 | ␊ |
793 | ␉// Update dirIndex.␊ |
794 | ␉index++;␊ |
795 | ␊ |
796 | ␉if (index == SWAP_BE16(node->numRecords))␊ |
797 | ␉{␊ |
798 | ␉␉index = 0;␊ |
799 | ␉␉curNode = SWAP_BE32(node->fLink);␊ |
800 | ␉}␊ |
801 | ␉*dirIndex = (long long) curNode * nodeSize + index;␊ |
802 | ␊ |
803 | ␉free(nodeBuf);␊ |
804 | ␊ |
805 | ␉return 0;␊ |
806 | }␊ |
807 | ␊ |
808 | ␊ |
809 | //==============================================================================␊ |
810 | ␊ |
811 | static long ReadCatalogEntry(char * fileName, long dirID, void * entry, long long * dirIndex)␊ |
812 | {␊ |
813 | ␉long length = 0;␊ |
814 | ␉char key[sizeof(HFSPlusCatalogKey)];␊ |
815 | ␉HFSCatalogKey *hfsKey = (HFSCatalogKey *)key;␊ |
816 | ␉HFSPlusCatalogKey *hfsPlusKey = (HFSPlusCatalogKey *)key;␊ |
817 | ␊ |
818 | ␉// Make the catalog key.␊ |
819 | ␉if (gIsHFSPlus)␊ |
820 | ␉{␊ |
821 | ␉␉hfsPlusKey->parentID = SWAP_BE32(dirID);␊ |
822 | ␉␉length = strlen(fileName);␊ |
823 | ␊ |
824 | ␉␉if (length > 255)␊ |
825 | ␉␉{␊ |
826 | ␉␉␉length = 255;␊ |
827 | ␉␉}␊ |
828 | ␊ |
829 | ␉␉utf_decodestr((u_int8_t *)fileName, hfsPlusKey->nodeName.unicode, &(hfsPlusKey->nodeName.length), 512, OSBigEndian);␊ |
830 | ␉}␊ |
831 | ␉else␊ |
832 | ␉{␊ |
833 | ␉␉hfsKey->parentID = SWAP_BE32(dirID);␊ |
834 | ␉␉length = strlen(fileName);␊ |
835 | ␊ |
836 | ␉␉if (length > 31)␊ |
837 | ␉␉{␊ |
838 | ␉␉␉length = 31;␊ |
839 | ␉␉}␊ |
840 | ␊ |
841 | ␉␉hfsKey->nodeName[0] = length;␊ |
842 | ␉␉strncpy((char *)(hfsKey->nodeName + 1), fileName, length);␊ |
843 | ␉}␊ |
844 | ␊ |
845 | ␉return ReadBTreeEntry(kBTreeCatalog, &key, entry, dirIndex);␊ |
846 | }␊ |
847 | ␊ |
848 | ␊ |
849 | //==============================================================================␊ |
850 | ␊ |
851 | static long ReadExtentsEntry(long fileID, long startBlock, void * entry)␊ |
852 | {␊ |
853 | ␉char key[sizeof(HFSPlusExtentKey)];␊ |
854 | ␉HFSExtentKey *hfsKey = (HFSExtentKey *)key;␊ |
855 | ␉HFSPlusExtentKey *hfsPlusKey = (HFSPlusExtentKey *)key;␊ |
856 | ␊ |
857 | ␉// Make the extents key.␊ |
858 | ␉if (gIsHFSPlus)␊ |
859 | ␉{␊ |
860 | ␉␉hfsPlusKey->forkType = 0;␊ |
861 | ␉␉hfsPlusKey->fileID = SWAP_BE32(fileID);␊ |
862 | ␉␉hfsPlusKey->startBlock = SWAP_BE32(startBlock);␊ |
863 | ␉}␊ |
864 | ␉else␊ |
865 | ␉{␊ |
866 | ␉␉hfsKey->forkType = 0;␊ |
867 | ␉␉hfsKey->fileID = SWAP_BE32(fileID);␊ |
868 | ␉␉hfsKey->startBlock = SWAP_BE16(startBlock);␊ |
869 | ␉}␊ |
870 | ␊ |
871 | ␉return ReadBTreeEntry(kBTreeExtents, &key, entry, 0);␊ |
872 | }␊ |
873 | ␊ |
874 | ␊ |
875 | //==============================================================================␊ |
876 | ␊ |
877 | static long ReadBTreeEntry(long btree, void * key, char * entry, long long * dirIndex)␊ |
878 | {␊ |
879 | ␉long extentSize;␊ |
880 | ␉void *extent;␊ |
881 | ␉short extentFile;␊ |
882 | ␉char *nodeBuf;␊ |
883 | ␉BTNodeDescriptor *node;␊ |
884 | ␉long nodeSize, result = 0, entrySize = 0;␊ |
885 | ␉long curNode, index = 0, lowerBound, upperBound;␊ |
886 | ␉char *testKey, *recordData =0;␊ |
887 | ␊ |
888 | ␉// Figure out which tree is being looked at.␊ |
889 | ␉if (btree == kBTreeCatalog)␊ |
890 | ␉{␊ |
891 | ␉␉if (gIsHFSPlus) ␊ |
892 | ␉␉{␊ |
893 | ␉␉␉extent = &gHFSPlus->catalogFile.extents;␊ |
894 | ␉␉␉extentSize = SWAP_BE64(gHFSPlus->catalogFile.logicalSize);␊ |
895 | ␉␉}␊ |
896 | ␉␉else␊ |
897 | ␉␉{␊ |
898 | ␉␉␉extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;␊ |
899 | ␉␉␉extentSize = SWAP_BE32(gHFSMDB->drCTFlSize);␊ |
900 | ␉␉}␊ |
901 | ␉␉extentFile = kHFSCatalogFileID;␊ |
902 | ␉}␊ |
903 | ␉else␊ |
904 | ␉{␊ |
905 | ␉␉if (gIsHFSPlus)␊ |
906 | ␉␉{␊ |
907 | ␉␉␉extent = &gHFSPlus->extentsFile.extents;␊ |
908 | ␉␉␉extentSize = SWAP_BE64(gHFSPlus->extentsFile.logicalSize);␊ |
909 | ␉␉}␊ |
910 | ␉␉else␊ |
911 | ␉␉{␊ |
912 | ␉␉␉extent = (HFSExtentDescriptor *)&gHFSMDB->drXTExtRec;␊ |
913 | ␉␉␉extentSize = SWAP_BE32(gHFSMDB->drXTFlSize);␊ |
914 | ␉␉}␊ |
915 | ␉␉extentFile = kHFSExtentsFileID;␊ |
916 | ␉}␊ |
917 | ␊ |
918 | ␉// Read the BTree Header if needed.␊ |
919 | ␉if (gBTHeaders[btree] == 0)␊ |
920 | ␉{␊ |
921 | ␉␉ReadExtent(extent, extentSize, extentFile, 0, 256, gBTreeHeaderBuffer + btree * 256, 0);␊ |
922 | ␉␉gBTHeaders[btree] = (BTHeaderRec *)(gBTreeHeaderBuffer + btree * 256 + sizeof(BTNodeDescriptor));␊ |
923 | ␊ |
924 | ␉␉if ((gIsHFSPlus && btree == kBTreeCatalog) && (gBTHeaders[btree]->keyCompareType == kHFSBinaryCompare))␊ |
925 | ␉␉{␊ |
926 | ␉␉␉gCaseSensitive = 1;␊ |
927 | ␉␉}␊ |
928 | ␉}␊ |
929 | ␊ |
930 | ␉curNode = SWAP_BE32(gBTHeaders[btree]->rootNode);␊ |
931 | ␉nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize);␊ |
932 | ␉nodeBuf = (char *)malloc(nodeSize);␊ |
933 | ␉node = (BTNodeDescriptor *)nodeBuf;␊ |
934 | ␊ |
935 | ␉while (1)␊ |
936 | ␉{␊ |
937 | ␉␉// Read the current node.␊ |
938 | ␉ReadExtent(extent, extentSize, extentFile, (long long) curNode * nodeSize, nodeSize, nodeBuf, 1);␊ |
939 | ␊ |
940 | ␉␉// Find the matching key.␊ |
941 | ␉␉lowerBound = 0;␊ |
942 | ␉␉upperBound = SWAP_BE16(node->numRecords) - 1;␊ |
943 | ␊ |
944 | ␉␉while (lowerBound <= upperBound)␊ |
945 | ␉␉{␊ |
946 | ␉␉␉index = (lowerBound + upperBound) / 2;␊ |
947 | ␊ |
948 | ␉␉␉GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData);␊ |
949 | ␊ |
950 | ␉␉␉if (gIsHFSPlus)␊ |
951 | ␉␉␉{␊ |
952 | ␉␉␉␉if (btree == kBTreeCatalog)␊ |
953 | ␉␉␉␉{␊ |
954 | ␉␉␉␉␉result = CompareHFSPlusCatalogKeys(key, testKey);␊ |
955 | ␉␉␉␉}␊ |
956 | ␉␉␉␉else␊ |
957 | ␉␉␉␉{␊ |
958 | ␉␉␉␉␉result = CompareHFSPlusExtentsKeys(key, testKey);␊ |
959 | ␉␉␉␉}␊ |
960 | ␉␉␉}␊ |
961 | ␉␉␉else␊ |
962 | ␉␉␉{␊ |
963 | ␉␉␉␉if (btree == kBTreeCatalog)␊ |
964 | ␉␉␉␉{␊ |
965 | ␉␉␉␉␉result = CompareHFSCatalogKeys(key, testKey);␊ |
966 | ␉␉␉␉}␊ |
967 | ␉␉␉␉else␊ |
968 | ␉␉␉␉{␊ |
969 | ␉␉␉␉␉result = CompareHFSExtentsKeys(key, testKey);␊ |
970 | ␉␉␉␉}␊ |
971 | ␉␉␉}␊ |
972 | ␊ |
973 | ␉␉␉if (result < 0)␊ |
974 | ␉␉␉{␊ |
975 | ␉␉␉␉upperBound = index - 1;␉// search < trial␊ |
976 | ␉␉␉}␊ |
977 | ␉␉␉else if (result > 0)␊ |
978 | ␉␉␉{␊ |
979 | ␉␉␉␉lowerBound = index + 1;␉// search > trial␊ |
980 | ␉␉␉}␊ |
981 | ␉␉␉else␊ |
982 | ␉␉␉{␊ |
983 | ␉␉␉␉break;␉// search = trial␊ |
984 | ␉␉␉}␊ |
985 | ␉␉}␊ |
986 | ␊ |
987 | ␉␉if (result < 0)␊ |
988 | ␉␉{␊ |
989 | ␉␉␉index = upperBound;␊ |
990 | ␉␉␉GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData);␊ |
991 | ␉␉}␊ |
992 | ␊ |
993 | ␉␉// Found the closest key... Recurse on it if this is an index node.␊ |
994 | ␉␉if (node->kind == kBTIndexNode)␊ |
995 | ␉␉{␊ |
996 | ␉␉␉curNode = SWAP_BE32( *((long *)recordData) );␊ |
997 | ␉␉}␊ |
998 | ␉␉else␊ |
999 | ␉␉{␊ |
1000 | ␉␉␉break;␊ |
1001 | ␉␉}␊ |
1002 | ␉}␊ |
1003 | ␊ |
1004 | ␉// Return error if the file was not found.␊ |
1005 | ␉if (result != 0)␊ |
1006 | ␉{␊ |
1007 | ␉␉free(nodeBuf);␊ |
1008 | ␉␉return -1;␊ |
1009 | ␉}␊ |
1010 | ␊ |
1011 | ␉if (btree == kBTreeCatalog)␊ |
1012 | ␉{␊ |
1013 | ␉␉switch (SWAP_BE16(*(short *)recordData))␊ |
1014 | ␉␉{␊ |
1015 | ␉␉␉case kHFSFolderRecord : entrySize = 70;␊ |
1016 | ␉␉␉␉break;␊ |
1017 | ␉␉␉case kHFSFileRecord : entrySize = 102;␊ |
1018 | ␉␉␉␉break;␊ |
1019 | ␉␉␉case kHFSFolderThreadRecord : entrySize = 46;␊ |
1020 | ␉␉␉␉break;␊ |
1021 | ␉␉␉case kHFSFileThreadRecord : entrySize = 46;␊ |
1022 | ␉␉␉␉break;␊ |
1023 | ␉␉␉case kHFSPlusFolderRecord : entrySize = 88;␊ |
1024 | ␉␉␉␉break;␊ |
1025 | ␉␉␉case kHFSPlusFileRecord : entrySize = 248;␊ |
1026 | ␉␉␉␉break;␊ |
1027 | ␉␉␉case kHFSPlusFolderThreadRecord : entrySize = 264;␊ |
1028 | ␉␉␉␉break;␊ |
1029 | ␉␉␉case kHFSPlusFileThreadRecord : entrySize = 264;␊ |
1030 | ␉␉␉␉break;␊ |
1031 | ␉␉}␊ |
1032 | ␉}␊ |
1033 | ␉else␊ |
1034 | ␉{␊ |
1035 | ␉␉if (gIsHFSPlus)␊ |
1036 | ␉␉{␊ |
1037 | ␉␉␉entrySize = sizeof(HFSPlusExtentRecord);␊ |
1038 | ␉␉}␊ |
1039 | ␉␉else␊ |
1040 | ␉␉{␊ |
1041 | ␉␉␉entrySize = sizeof(HFSExtentRecord);␊ |
1042 | ␉␉}␊ |
1043 | ␉}␊ |
1044 | ␊ |
1045 | ␉bcopy(recordData, entry, entrySize);␊ |
1046 | ␊ |
1047 | ␉// Update dirIndex.␊ |
1048 | ␉if (dirIndex != 0)␊ |
1049 | ␉{␊ |
1050 | ␉␉index++;␊ |
1051 | ␉␉if (index == SWAP_BE16(node->numRecords))␊ |
1052 | ␉␉{␊ |
1053 | ␉␉␉index = 0;␊ |
1054 | ␉␉␉curNode = SWAP_BE32(node->fLink);␊ |
1055 | ␉␉}␊ |
1056 | ␉␉*dirIndex = (long long) curNode * nodeSize + index;␊ |
1057 | ␉}␊ |
1058 | ␊ |
1059 | ␉free(nodeBuf);␊ |
1060 | ␊ |
1061 | ␉return 0;␊ |
1062 | }␊ |
1063 | ␊ |
1064 | //==============================================================================␊ |
1065 | ␊ |
1066 | static void GetBTreeRecord(long index, char * nodeBuffer, long nodeSize, char ** key, char ** data)␊ |
1067 | {␊ |
1068 | ␉long keySize;␊ |
1069 | ␉long recordOffset;␊ |
1070 | ␊ |
1071 | ␉recordOffset = SWAP_BE16(*((short *)(nodeBuffer + (nodeSize - 2 * index - 2))));␊ |
1072 | ␉*key = nodeBuffer + recordOffset;␊ |
1073 | ␊ |
1074 | ␉if (gIsHFSPlus)␊ |
1075 | ␉{␊ |
1076 | ␉␉keySize = SWAP_BE16(*(short *)*key);␊ |
1077 | ␉␉*data = *key + 2 + keySize;␊ |
1078 | ␉}␊ |
1079 | ␉else␊ |
1080 | ␉{␊ |
1081 | ␉␉keySize = **key;␊ |
1082 | ␉␉*data = *key + 2 + keySize - (keySize & 1);␊ |
1083 | ␉}␊ |
1084 | }␊ |
1085 | ␊ |
1086 | //==============================================================================␊ |
1087 | ␊ |
1088 | static long ReadExtent(char * extent, uint64_t extentSize, long extentFile, uint64_t offset, uint64_t size, void * buffer, long cache)␊ |
1089 | {␊ |
1090 | ␉uint64_t lastOffset;␊ |
1091 | ␉long long blockNumber, countedBlocks = 0;␊ |
1092 | ␉long long nextExtent = 0, sizeRead = 0, readSize;␊ |
1093 | ␉long long nextExtentBlock, currentExtentBlock = 0;␊ |
1094 | ␉long long readOffset;␊ |
1095 | ␉long long extentDensity, sizeofExtent, currentExtentSize;␊ |
1096 | ␉char *currentExtent, *extentBuffer = 0, *bufferPos = buffer;␊ |
1097 | ␊ |
1098 | ␉if (offset >= extentSize)␊ |
1099 | ␉{␊ |
1100 | ␉␉return 0;␊ |
1101 | ␉}␊ |
1102 | ␊ |
1103 | ␉if (gIsHFSPlus)␊ |
1104 | ␉{␊ |
1105 | ␉␉extentDensity = kHFSPlusExtentDensity;␊ |
1106 | ␉␉sizeofExtent = sizeof(HFSPlusExtentDescriptor);␊ |
1107 | ␉}␊ |
1108 | ␉else␊ |
1109 | ␉{␊ |
1110 | ␉␉extentDensity = kHFSExtentDensity;␊ |
1111 | ␉␉sizeofExtent = sizeof(HFSExtentDescriptor);␊ |
1112 | ␉}␊ |
1113 | ␊ |
1114 | ␉lastOffset = offset + size;␊ |
1115 | ␊ |
1116 | ␉while (offset < lastOffset)␊ |
1117 | ␉{␊ |
1118 | ␉␉blockNumber = offset / gBlockSize;␊ |
1119 | ␊ |
1120 | ␉␉// Find the extent for the offset.␊ |
1121 | ␉␉for (; ; nextExtent++)␊ |
1122 | ␉␉{␊ |
1123 | ␉␉␉if (nextExtent < extentDensity)␊ |
1124 | ␉␉␉{␊ |
1125 | ␉␉␉␉if ((countedBlocks+GetExtentSize(extent, nextExtent)-1)<blockNumber)␊ |
1126 | ␉␉␉␉{␊ |
1127 | ␉␉␉␉␉countedBlocks += GetExtentSize(extent, nextExtent);␊ |
1128 | ␉␉␉␉␉continue;␊ |
1129 | ␉␉␉␉}␊ |
1130 | ␊ |
1131 | ␉␉␉␉currentExtent = extent + nextExtent * sizeofExtent;␊ |
1132 | ␉␉␉␉break;␊ |
1133 | ␉␉␉}␊ |
1134 | ␊ |
1135 | ␉␉␉if (extentBuffer == 0)␊ |
1136 | ␉␉␉{␊ |
1137 | ␉␉␉␉extentBuffer = malloc(sizeofExtent * extentDensity);␊ |
1138 | ␊ |
1139 | ␉␉␉␉if (extentBuffer == 0)␊ |
1140 | ␉␉␉␉{␊ |
1141 | ␉␉␉␉␉return -1;␊ |
1142 | ␉␉␉␉}␊ |
1143 | ␉␉␉}␊ |
1144 | ␊ |
1145 | ␉␉␉nextExtentBlock = nextExtent / extentDensity;␊ |
1146 | ␊ |
1147 | ␉␉␉if (currentExtentBlock != nextExtentBlock)␊ |
1148 | ␉␉␉{␊ |
1149 | ␉␉␉␉ReadExtentsEntry(extentFile, countedBlocks, extentBuffer);␊ |
1150 | ␉␉␉␉currentExtentBlock = nextExtentBlock;␊ |
1151 | ␉␉␉}␊ |
1152 | ␊ |
1153 | ␉␉␉currentExtentSize = GetExtentSize(extentBuffer, nextExtent % extentDensity);␊ |
1154 | ␊ |
1155 | ␉␉␉if ((countedBlocks + currentExtentSize - 1) >= blockNumber)␊ |
1156 | ␉␉␉{␊ |
1157 | ␉␉␉␉currentExtent = extentBuffer + sizeofExtent * (nextExtent % extentDensity);␊ |
1158 | ␉␉␉␉break;␊ |
1159 | ␉␉␉}␊ |
1160 | ␊ |
1161 | ␉␉␉countedBlocks += currentExtentSize;␊ |
1162 | ␉␉}␊ |
1163 | ␊ |
1164 | ␉␉readOffset = ((blockNumber - countedBlocks) * gBlockSize) + (offset % gBlockSize);␊ |
1165 | ␊ |
1166 | ␉␉// MacWen: fix overflow in multiplication by forcing 64bit multiplication␊ |
1167 | ␉␉readSize = (long long)GetExtentSize(currentExtent, 0) * gBlockSize - readOffset;␊ |
1168 | ␊ |
1169 | ␉␉if (readSize > (size - sizeRead))␊ |
1170 | ␉␉{␊ |
1171 | ␉␉␉readSize = size - sizeRead;␊ |
1172 | ␉␉}␊ |
1173 | ␊ |
1174 | ␉␉readOffset += (long long)GetExtentStart(currentExtent, 0) * gBlockSize;␊ |
1175 | ␊ |
1176 | ␉␉CacheRead(gCurrentIH, bufferPos, gAllocationOffset + readOffset, readSize, cache);␊ |
1177 | ␊ |
1178 | ␉␉sizeRead += readSize;␊ |
1179 | ␉␉offset += readSize;␊ |
1180 | ␉␉bufferPos += readSize;␊ |
1181 | ␉}␊ |
1182 | ␊ |
1183 | ␉if (extentBuffer)␊ |
1184 | ␉{␊ |
1185 | ␉␉free(extentBuffer);␊ |
1186 | ␉}␊ |
1187 | ␊ |
1188 | ␉return sizeRead;␊ |
1189 | }␊ |
1190 | ␊ |
1191 | //==============================================================================␊ |
1192 | ␊ |
1193 | static long GetExtentStart(void * extents, long index)␊ |
1194 | {␊ |
1195 | ␉long start;␊ |
1196 | ␊ |
1197 | ␉HFSExtentDescriptor␉␉*hfsExtents␉␉= extents;␊ |
1198 | ␉HFSPlusExtentDescriptor␉*hfsPlusExtents␉= extents;␊ |
1199 | ␊ |
1200 | ␉if (gIsHFSPlus)␊ |
1201 | ␉{␊ |
1202 | ␉␉start = SWAP_BE32(hfsPlusExtents[index].startBlock);␊ |
1203 | ␉}␊ |
1204 | ␉else␊ |
1205 | ␉{␊ |
1206 | ␉␉start = SWAP_BE16(hfsExtents[index].startBlock);␊ |
1207 | ␉}␊ |
1208 | ␊ |
1209 | ␉return start;␊ |
1210 | }␊ |
1211 | ␊ |
1212 | ␊ |
1213 | //==============================================================================␊ |
1214 | ␊ |
1215 | static long GetExtentSize(void * extents, long index)␊ |
1216 | {␊ |
1217 | ␉long size = 0;␊ |
1218 | ␊ |
1219 | ␉HFSExtentDescriptor *hfsExtents = extents;␊ |
1220 | ␉HFSPlusExtentDescriptor *hfsPlusExtents = extents;␊ |
1221 | ␊ |
1222 | ␉if (gIsHFSPlus)␊ |
1223 | ␉{␊ |
1224 | ␉␉size = SWAP_BE32(hfsPlusExtents[index].blockCount);␊ |
1225 | ␉}␊ |
1226 | ␉else␊ |
1227 | ␉{␊ |
1228 | ␉␉size = SWAP_BE16(hfsExtents[index].blockCount);␊ |
1229 | ␉}␊ |
1230 | ␊ |
1231 | ␉return size;␊ |
1232 | }␊ |
1233 | ␊ |
1234 | ␊ |
1235 | //==============================================================================␊ |
1236 | ␊ |
1237 | static long CompareHFSCatalogKeys(void * key, void * testKey)␊ |
1238 | {␊ |
1239 | ␉HFSCatalogKey *searchKey, *trialKey;␊ |
1240 | ␉long result, searchParentID, trialParentID;␊ |
1241 | ␊ |
1242 | ␉searchKey = key;␊ |
1243 | ␉trialKey = testKey;␊ |
1244 | ␊ |
1245 | ␉searchParentID = SWAP_BE32(searchKey->parentID);␊ |
1246 | ␉trialParentID = SWAP_BE32(trialKey->parentID);␊ |
1247 | ␊ |
1248 | ␉// parent dirID is unsigned␊ |
1249 | ␉if (searchParentID > trialParentID)␊ |
1250 | ␉{␊ |
1251 | ␉␉result = 1;␊ |
1252 | ␉}␊ |
1253 | ␉else if (searchParentID < trialParentID)␊ |
1254 | ␉{␊ |
1255 | ␉␉result = -1;␊ |
1256 | ␉}␊ |
1257 | ␉else␊ |
1258 | ␉{␊ |
1259 | ␉␉// parent dirID's are equal, compare names␊ |
1260 | ␉␉result = FastRelString(searchKey->nodeName, trialKey->nodeName);␊ |
1261 | ␉}␊ |
1262 | ␊ |
1263 | ␉return result;␊ |
1264 | }␊ |
1265 | ␊ |
1266 | ␊ |
1267 | //==============================================================================␊ |
1268 | ␊ |
1269 | static long CompareHFSPlusCatalogKeys(void * key, void * testKey)␊ |
1270 | {␊ |
1271 | ␉HFSPlusCatalogKey *searchKey, *trialKey;␊ |
1272 | ␉long result, searchParentID, trialParentID;␊ |
1273 | ␊ |
1274 | ␉searchKey = key;␊ |
1275 | ␉trialKey = testKey;␊ |
1276 | ␊ |
1277 | ␉searchParentID = SWAP_BE32(searchKey->parentID);␊ |
1278 | ␉trialParentID = SWAP_BE32(trialKey->parentID);␊ |
1279 | ␊ |
1280 | ␉// parent dirID is unsigned␊ |
1281 | ␉if (searchParentID > trialParentID)␊ |
1282 | ␉{␊ |
1283 | ␉␉result = 1;␊ |
1284 | ␉}␊ |
1285 | ␉else if (searchParentID < trialParentID) ␊ |
1286 | ␉{␊ |
1287 | ␉␉result = -1;␊ |
1288 | ␉}␊ |
1289 | ␉else␊ |
1290 | ␉{␊ |
1291 | ␉␉// parent dirID's are equal, compare names␊ |
1292 | ␉␉if ((searchKey->nodeName.length == 0) || (trialKey->nodeName.length == 0))␊ |
1293 | ␉␉{␊ |
1294 | ␉␉␉result = searchKey->nodeName.length - trialKey->nodeName.length;␊ |
1295 | ␉␉}␊ |
1296 | ␉␉else if (gCaseSensitive)␊ |
1297 | ␉␉{␊ |
1298 | ␉␉␉result = BinaryUnicodeCompare(&searchKey->nodeName.unicode[0],␊ |
1299 | SWAP_BE16(searchKey->nodeName.length),␊ |
1300 | &trialKey->nodeName.unicode[0],␊ |
1301 | SWAP_BE16(trialKey->nodeName.length));␊ |
1302 | ␉␉}␊ |
1303 | ␉␉else␊ |
1304 | ␉␉{␊ |
1305 | ␉␉␉result = FastUnicodeCompare(&searchKey->nodeName.unicode[0],␊ |
1306 | SWAP_BE16(searchKey->nodeName.length),␊ |
1307 | &trialKey->nodeName.unicode[0],␊ |
1308 | SWAP_BE16(trialKey->nodeName.length), OSBigEndian);␊ |
1309 | ␉␉}␊ |
1310 | ␉}␊ |
1311 | ␊ |
1312 | ␉return result;␊ |
1313 | }␊ |
1314 | ␊ |
1315 | ␊ |
1316 | //==============================================================================␊ |
1317 | ␊ |
1318 | static long CompareHFSExtentsKeys(void * key, void * testKey)␊ |
1319 | {␊ |
1320 | ␉HFSExtentKey *searchKey, *trialKey;␊ |
1321 | ␉long result;␊ |
1322 | ␊ |
1323 | ␉searchKey = key;␊ |
1324 | ␉trialKey = testKey;␊ |
1325 | ␊ |
1326 | ␉// assume searchKey < trialKey␊ |
1327 | ␉result = -1; ␊ |
1328 | ␊ |
1329 | ␉if (searchKey->fileID == trialKey->fileID)␊ |
1330 | ␉{␊ |
1331 | ␉␉// FileNum's are equal; compare fork types␊ |
1332 | ␉␉if (searchKey->forkType == trialKey->forkType)␊ |
1333 | ␉␉{␊ |
1334 | ␉␉␉// Fork types are equal; compare allocation block number␊ |
1335 | ␉␉␉if (searchKey->startBlock == trialKey->startBlock)␊ |
1336 | ␉␉␉{␊ |
1337 | ␉␉␉␉// Everything is equal␊ |
1338 | ␉␉␉␉result = 0;␊ |
1339 | ␉␉␉}␊ |
1340 | ␉␉␉else␊ |
1341 | ␉␉␉{␊ |
1342 | ␉␉␉␉// Allocation block numbers differ; determine sign␊ |
1343 | ␉␉␉␉if (SWAP_BE16(searchKey->startBlock) > SWAP_BE16(trialKey->startBlock))␊ |
1344 | ␉␉␉␉{␊ |
1345 | ␉␉␉␉␉result = 1;␊ |
1346 | ␉␉␉␉}␊ |
1347 | ␉␉␉}␊ |
1348 | ␉}␊ |
1349 | ␉␉else␊ |
1350 | ␉␉{␊ |
1351 | ␉␉␉// Fork types differ; determine sign␊ |
1352 | ␉␉␉if (searchKey->forkType > trialKey->forkType)␊ |
1353 | ␉␉␉{␊ |
1354 | ␉␉␉␉result = 1;␊ |
1355 | ␉␉␉}␊ |
1356 | ␉␉}␊ |
1357 | ␉}␊ |
1358 | ␉else␊ |
1359 | ␉{␊ |
1360 | ␉␉// FileNums differ; determine sign␊ |
1361 | ␉␉if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID))␊ |
1362 | ␉␉{␊ |
1363 | ␉␉␉result = 1;␊ |
1364 | ␉␉}␊ |
1365 | ␉}␊ |
1366 | ␊ |
1367 | ␉return result;␊ |
1368 | }␊ |
1369 | ␊ |
1370 | ␊ |
1371 | //==============================================================================␊ |
1372 | ␊ |
1373 | static long CompareHFSPlusExtentsKeys(void * key, void * testKey)␊ |
1374 | {␊ |
1375 | ␉HFSPlusExtentKey *searchKey, *trialKey;␊ |
1376 | ␊ |
1377 | ␉long result = -1; // assume searchKey < trialKey␊ |
1378 | ␊ |
1379 | ␉searchKey = key;␊ |
1380 | ␉trialKey = testKey;␊ |
1381 | ␊ |
1382 | ␉if (searchKey->fileID == trialKey->fileID)␊ |
1383 | ␉{␊ |
1384 | ␉␉// FileNum's are equal; compare fork types␊ |
1385 | ␉␉if (searchKey->forkType == trialKey->forkType)␊ |
1386 | ␉␉{␊ |
1387 | ␉␉␉// Fork types are equal; compare allocation block number␊ |
1388 | ␉␉␉if (searchKey->startBlock == trialKey->startBlock)␊ |
1389 | ␉␉␉{␊ |
1390 | ␉␉␉␉// Everything is equal␊ |
1391 | ␉␉␉␉result = 0;␊ |
1392 | ␉␉␉}␊ |
1393 | ␉␉␉else␊ |
1394 | ␉␉␉{␊ |
1395 | ␉␉␉␉// Allocation block numbers differ; determine sign␊ |
1396 | ␉␉␉␉if (SWAP_BE32(searchKey->startBlock) > SWAP_BE32(trialKey->startBlock))␊ |
1397 | ␉␉␉␉{␊ |
1398 | ␉␉␉␉␉result = 1;␊ |
1399 | ␉␉␉␉}␊ |
1400 | ␉␉␉}␊ |
1401 | ␉␉}␊ |
1402 | ␉␉else␊ |
1403 | ␉␉{␊ |
1404 | ␉␉␉// Fork types differ; determine sign␊ |
1405 | ␉␉␉if (searchKey->forkType > trialKey->forkType)␊ |
1406 | ␉␉␉{␊ |
1407 | ␉␉␉␉result = 1;␊ |
1408 | ␉␉␉}␊ |
1409 | ␉␉}␊ |
1410 | ␉}␊ |
1411 | ␉else␊ |
1412 | ␉{␊ |
1413 | ␉␉// FileNums differ; determine sign␊ |
1414 | ␉␉if (SWAP_BE32(searchKey->fileID) > SWAP_BE32(trialKey->fileID))␊ |
1415 | ␉␉{␊ |
1416 | ␉␉␉result = 1;␊ |
1417 | ␉␉}␊ |
1418 | ␉}␊ |
1419 | ␊ |
1420 | ␉return result;␊ |
1421 | }␊ |
1422 | ␊ |
1423 | |