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