]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/hfs_endian.c
xnu-792.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_endian.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
e5568f75
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (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.
1c79356b 11 *
e5568f75
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
A
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.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23/*
24 * hfs_endian.c
25 *
26 * This file implements endian swapping routines for the HFS/HFS Plus
27 * volume format.
28 */
29
30#include <architecture/byte_order.h>
31
32#include "hfs_endian.h"
33#include "hfs_dbg.h"
34
35#undef ENDIAN_DEBUG
36
37/* Private swapping routines */
38int hfs_swap_HFSPlusBTInternalNode (BlockDescriptor *src, HFSCatalogNodeID fileID, int unswap);
39int hfs_swap_HFSBTInternalNode (BlockDescriptor *src, HFSCatalogNodeID fileID, int unswap);
40
41/*
42 * hfs_swap_HFSPlusForkData
43 *
44 * There's still a few spots where we still need to swap the fork data.
45 */
46void
47hfs_swap_HFSPlusForkData (
48 HFSPlusForkData *src
49)
50{
51 int i;
52
1c79356b
A
53 src->logicalSize = SWAP_BE64 (src->logicalSize);
54
55 src->clumpSize = SWAP_BE32 (src->clumpSize);
56 src->totalBlocks = SWAP_BE32 (src->totalBlocks);
57
58 for (i = 0; i < kHFSPlusExtentDensity; i++) {
59 src->extents[i].startBlock = SWAP_BE32 (src->extents[i].startBlock);
60 src->extents[i].blockCount = SWAP_BE32 (src->extents[i].blockCount);
61 }
62}
63
64/*
65 * hfs_swap_BTNode
66 *
67 * NOTE: This operation is not naturally symmetric.
68 * We have to determine which way we're swapping things.
69 */
70int
71hfs_swap_BTNode (
72 BlockDescriptor *src,
73 int isHFSPlus,
74 HFSCatalogNodeID fileID,
75 int unswap
76)
77{
78 BTNodeDescriptor *srcDesc = src->buffer;
79 UInt16 *srcOffs = NULL;
80
81 UInt32 i;
82 int error = 0;
83
1c79356b
A
84
85#ifdef ENDIAN_DEBUG
86 if (unswap == 0) {
87 printf ("BE -> LE Swap\n");
88 } else if (unswap == 1) {
89 printf ("LE -> BE Swap\n");
90 } else if (unswap == 3) {
91 printf ("Not swapping descriptors\n");
92 } else {
93 panic ("%s This is impossible", "hfs_swap_BTNode:");
94 }
95#endif
96
97 /* If we are doing a swap */
98 if (unswap == 0) {
99 /* Swap the node descriptor */
100 srcDesc->fLink = SWAP_BE32 (srcDesc->fLink);
101 srcDesc->bLink = SWAP_BE32 (srcDesc->bLink);
102
103 /* Don't swap srcDesc->kind */
104 /* Don't swap srcDesc->height */
105 /* Don't swap srcDesc->reserved */
106
107 srcDesc->numRecords = SWAP_BE16 (srcDesc->numRecords);
108
109 /* Swap the node offsets (including the free space one!) */
110 srcOffs = (UInt16 *)((char *)src->buffer + (src->blockSize - ((srcDesc->numRecords + 1) * sizeof (UInt16))));
111
112 /* Sanity check */
113 if ((char *)srcOffs > ((char *)src->buffer + src->blockSize)) {
114 panic ("%s Too many records in the B-Tree node", "hfs_swap_BTNode:");
115 }
116
117 for (i = 0; i < srcDesc->numRecords + 1; i++) {
118 srcOffs[i] = SWAP_BE16 (srcOffs[i]);
119
120 /* Sanity check */
121 if (srcOffs[i] >= src->blockSize) {
122 panic ("%s B-Tree node offset out of range", "hfs_swap_BTNode:");
123 }
124 }
125 }
126
127 /* Swap the records (ordered by frequency of access) */
128 /* Swap a B-Tree internal node */
129 if ((srcDesc->kind == kBTIndexNode) ||
130 (srcDesc-> kind == kBTLeafNode)) {
131
132 if (isHFSPlus) {
133 error = hfs_swap_HFSPlusBTInternalNode (src, fileID, unswap);
134 } else {
135 error = hfs_swap_HFSBTInternalNode (src, fileID, unswap);
136 }
137
138 /* Swap a B-Tree map node */
139 } else if (srcDesc-> kind == kBTMapNode) {
140 /* Don't swap the bitmaps, they'll be done in the bitmap routines */
141
142 /* Swap a B-Tree header node */
143 } else if (srcDesc-> kind == kBTHeaderNode) {
144 /* The header's offset is hard-wired because we cannot trust the offset pointers */
145 BTHeaderRec *srcHead = (BTHeaderRec *)((char *)src->buffer + 14);
146
147 srcHead->treeDepth = SWAP_BE16 (srcHead->treeDepth);
148
149 srcHead->rootNode = SWAP_BE32 (srcHead->rootNode);
150 srcHead->leafRecords = SWAP_BE32 (srcHead->leafRecords);
151 srcHead->firstLeafNode = SWAP_BE32 (srcHead->firstLeafNode);
152 srcHead->lastLeafNode = SWAP_BE32 (srcHead->lastLeafNode);
153
154 srcHead->nodeSize = SWAP_BE16 (srcHead->nodeSize);
155 srcHead->maxKeyLength = SWAP_BE16 (srcHead->maxKeyLength);
156
157 srcHead->totalNodes = SWAP_BE32 (srcHead->totalNodes);
158 srcHead->freeNodes = SWAP_BE32 (srcHead->freeNodes);
159
160 srcHead->clumpSize = SWAP_BE32 (srcHead->clumpSize);
161 srcHead->attributes = SWAP_BE32 (srcHead->attributes);
162
163 /* Don't swap srcHead->reserved1 */
164 /* Don't swap srcHead->btreeType */
165 /* Don't swap srcHead->reserved2 */
166 /* Don't swap srcHead->reserved3 */
167 /* Don't swap bitmap */
168 }
169
170 /* If we are doing an unswap */
171 if (unswap == 1) {
172 /* Swap the node descriptor */
173 srcDesc->fLink = SWAP_BE32 (srcDesc->fLink);
174 srcDesc->bLink = SWAP_BE32 (srcDesc->bLink);
175
176 /* Don't swap srcDesc->kind */
177 /* Don't swap srcDesc->height */
178 /* Don't swap srcDesc->reserved */
179
180 /* Swap the node offsets (including the free space one!) */
181 srcOffs = (UInt16 *)((char *)src->buffer + (src->blockSize - ((srcDesc->numRecords + 1) * sizeof (UInt16))));
182
183 /* Sanity check */
184 if ((char *)srcOffs > ((char *)src->buffer + src->blockSize)) {
185 panic ("%s Too many records in the B-Tree node", "hfs_swap_BTNode:");
186 }
187
188 for (i = 0; i < srcDesc->numRecords + 1; i++) {
189 /* Sanity check */
190 if (srcOffs[i] >= src->blockSize) {
191 panic ("%s B-Tree node offset out of range", "hfs_swap_BTNode:");
192 }
193
194 srcOffs[i] = SWAP_BE16 (srcOffs[i]);
195 }
196
197 srcDesc->numRecords = SWAP_BE16 (srcDesc->numRecords);
198 }
199
200 return (error);
201}
202
203int
204hfs_swap_HFSPlusBTInternalNode (
205 BlockDescriptor *src,
206 HFSCatalogNodeID fileID,
207 int unswap
208)
209{
210 BTNodeDescriptor *srcDesc = src->buffer;
211 UInt16 *srcOffs = (UInt16 *)((char *)src->buffer + (src->blockSize - (srcDesc->numRecords * sizeof (UInt16))));
212
213 UInt32 i;
214 UInt32 j;
215
1c79356b
A
216 if (fileID == kHFSExtentsFileID) {
217 HFSPlusExtentKey *srcKey;
218 HFSPlusExtentDescriptor *srcRec;
219
220 for (i = 0; i < srcDesc->numRecords; i++) {
221 srcKey = (HFSPlusExtentKey *)((char *)src->buffer + srcOffs[i]);
222
223 if (!unswap) srcKey->keyLength = SWAP_BE16 (srcKey->keyLength);
224 srcRec = (HFSPlusExtentDescriptor *)((char *)srcKey + srcKey->keyLength + 2);
225 if (unswap) srcKey->keyLength = SWAP_BE16 (srcKey->keyLength);
226
227 /* Don't swap srcKey->forkType */
228 /* Don't swap srcKey->pad */
229
230 srcKey->fileID = SWAP_BE32 (srcKey->fileID);
231 srcKey->startBlock = SWAP_BE32 (srcKey->startBlock);
232
233 /* Stop if this is just an index node */
234 if (srcDesc->kind == kBTIndexNode) {
235 *((UInt32 *)srcRec) = SWAP_BE32 (*((UInt32 *)srcRec));
236 continue;
237 }
238
239 /* Swap the extent data */
240
241 /* Swap each extent */
242 for (j = 0; j < kHFSPlusExtentDensity; j++) {
243 srcRec[j].startBlock = SWAP_BE32 (srcRec[j].startBlock);
244 srcRec[j].blockCount = SWAP_BE32 (srcRec[j].blockCount);
245 }
246 }
247
248 } else if (fileID == kHFSCatalogFileID) {
249 HFSPlusCatalogKey *srcKey;
250 SInt16 *srcPtr;
251
252 for (i = 0; i < srcDesc->numRecords; i++) {
253 srcKey = (HFSPlusCatalogKey *)((char *)src->buffer + srcOffs[i]);
254
255 if (!unswap) srcKey->keyLength = SWAP_BE16 (srcKey->keyLength);
256 srcPtr = (SInt16 *)((char *)srcKey + srcKey->keyLength + 2);
257 if (unswap) srcKey->keyLength = SWAP_BE16 (srcKey->keyLength);
258
259 srcKey->parentID = SWAP_BE32 (srcKey->parentID);
260
261 if (!unswap) srcKey->nodeName.length = SWAP_BE16 (srcKey->nodeName.length);
262 for (j = 0; j < srcKey->nodeName.length; j++) {
263 srcKey->nodeName.unicode[j] = SWAP_BE16 (srcKey->nodeName.unicode[j]);
264 }
265 if (unswap) srcKey->nodeName.length = SWAP_BE16 (srcKey->nodeName.length);
266
267 /* Stop if this is just an index node */
268 if (srcDesc->kind == kBTIndexNode) {
269 *((UInt32 *)srcPtr) = SWAP_BE32 (*((UInt32 *)srcPtr));
270 continue;
271 }
272
273 /* Swap the recordType field, if unswapping, leave to later */
274 if (!unswap) srcPtr[0] = SWAP_BE16 (srcPtr[0]);
275
276 if (srcPtr[0] == kHFSPlusFolderRecord) {
277 HFSPlusCatalogFolder *srcRec = (HFSPlusCatalogFolder *)srcPtr;
278
279 srcRec->flags = SWAP_BE16 (srcRec->flags);
280 srcRec->valence = SWAP_BE32 (srcRec->valence);
281 srcRec->folderID = SWAP_BE32 (srcRec->folderID);
282 srcRec->createDate = SWAP_BE32 (srcRec->createDate);
283 srcRec->contentModDate = SWAP_BE32 (srcRec->contentModDate);
284 srcRec->attributeModDate = SWAP_BE32 (srcRec->attributeModDate);
285 srcRec->accessDate = SWAP_BE32 (srcRec->accessDate);
286 srcRec->backupDate = SWAP_BE32 (srcRec->backupDate);
287
288 srcRec->bsdInfo.ownerID = SWAP_BE32 (srcRec->bsdInfo.ownerID);
289 srcRec->bsdInfo.groupID = SWAP_BE32 (srcRec->bsdInfo.groupID);
290
291 /* Don't swap srcRec->bsdInfo.adminFlags */
292 /* Don't swap srcRec->bsdInfo.ownerFlags */
293
294 srcRec->bsdInfo.fileMode = SWAP_BE16 (srcRec->bsdInfo.fileMode);
295 srcRec->bsdInfo.special.iNodeNum = SWAP_BE32 (srcRec->bsdInfo.special.iNodeNum);
296
297 srcRec->textEncoding = SWAP_BE32 (srcRec->textEncoding);
298
299 /* Don't swap srcRec->userInfo */
300 /* Don't swap srcRec->finderInfo */
301 /* Don't swap srcRec->reserved */
302
303 } else if (srcPtr[0] == kHFSPlusFileRecord) {
304 HFSPlusCatalogFile *srcRec = (HFSPlusCatalogFile *)srcPtr;
305
306 srcRec->flags = SWAP_BE16 (srcRec->flags);
307
308 srcRec->fileID = SWAP_BE32 (srcRec->fileID);
309
310 srcRec->createDate = SWAP_BE32 (srcRec->createDate);
311 srcRec->contentModDate = SWAP_BE32 (srcRec->contentModDate);
312 srcRec->attributeModDate = SWAP_BE32 (srcRec->attributeModDate);
313 srcRec->accessDate = SWAP_BE32 (srcRec->accessDate);
314 srcRec->backupDate = SWAP_BE32 (srcRec->backupDate);
315
316 srcRec->bsdInfo.ownerID = SWAP_BE32 (srcRec->bsdInfo.ownerID);
317 srcRec->bsdInfo.groupID = SWAP_BE32 (srcRec->bsdInfo.groupID);
318
319 /* Don't swap srcRec->bsdInfo.adminFlags */
320 /* Don't swap srcRec->bsdInfo.ownerFlags */
321
322 srcRec->bsdInfo.fileMode = SWAP_BE16 (srcRec->bsdInfo.fileMode);
323 srcRec->bsdInfo.special.iNodeNum = SWAP_BE32 (srcRec->bsdInfo.special.iNodeNum);
324
325 srcRec->textEncoding = SWAP_BE32 (srcRec->textEncoding);
326
327 /* Don't swap srcRec->reserved1 */
328 /* Don't swap srcRec->userInfo */
329 /* Don't swap srcRec->finderInfo */
330 /* Don't swap srcRec->reserved2 */
331
332 hfs_swap_HFSPlusForkData (&srcRec->dataFork);
333 hfs_swap_HFSPlusForkData (&srcRec->resourceFork);
334
335 } else if ((srcPtr[0] == kHFSPlusFolderThreadRecord) ||
336 (srcPtr[0] == kHFSPlusFileThreadRecord)) {
337
338 HFSPlusCatalogThread *srcRec = (HFSPlusCatalogThread *)srcPtr;
339
340 /* Don't swap srcRec->reserved */
341
342 srcRec->parentID = SWAP_BE32 (srcRec->parentID);
343
344 if (!unswap) srcRec->nodeName.length = SWAP_BE16 (srcRec->nodeName.length);
345 for (j = 0; j < srcRec->nodeName.length; j++) {
346 srcRec->nodeName.unicode[j] = SWAP_BE16 (srcRec->nodeName.unicode[j]);
347 }
348 if (unswap) srcRec->nodeName.length = SWAP_BE16 (srcRec->nodeName.length);
349
350 } else {
351 panic ("%s unrecognized catalog record type", "hfs_swap_BTNode:");
352 }
353
354 /* If unswapping, we can safely unswap type field now */
355 if (unswap) srcPtr[0] = SWAP_BE16 (srcPtr[0]);
356 }
357
91447636
A
358 } else if (fileID == kHFSAttributesFileID) {
359 HFSPlusAttrKey *srcKey;
360 HFSPlusAttrRecord *srcRec;
361
362 for (i = 0; i < srcDesc->numRecords; i++) {
363 srcKey = (HFSPlusAttrKey *)((char *)src->buffer + srcOffs[i]);
364
365 if (!unswap) srcKey->keyLength = SWAP_BE16(srcKey->keyLength);
366 srcRec = (HFSPlusAttrRecord *)((char *)srcKey + srcKey->keyLength + 2);
367 if (unswap) srcKey->keyLength = SWAP_BE16(srcKey->keyLength);
368
369 srcKey->fileID = SWAP_BE32(srcKey->fileID);
370 srcKey->startBlock = SWAP_BE32(srcKey->startBlock);
371
372 if (!unswap) srcKey->attrNameLen = SWAP_BE16(srcKey->attrNameLen);
373 for (j = 0; j < srcKey->attrNameLen; j++)
374 srcKey->attrName[j] = SWAP_BE16(srcKey->attrName[j]);
375 if (unswap) srcKey->attrNameLen = SWAP_BE16(srcKey->attrNameLen);
376
377 /* If this is an index node, just swap the child node number */
378 if (srcDesc->kind == kBTIndexNode) {
379 *((UInt32 *)srcRec) = SWAP_BE32 (*((UInt32 *)srcRec));
380 continue;
381 }
382
383 /* Swap the data record */
384 if (!unswap) srcRec->recordType = SWAP_BE32(srcRec->recordType);
385 switch (srcRec->recordType) {
386 case kHFSPlusAttrInlineData:
387 /* We're not swapping the reserved fields */
388 srcRec->attrData.attrSize = SWAP_BE32(srcRec->attrData.attrSize);
389 /* Not swapping the attrData */
390 break;
391 case kHFSPlusAttrForkData:
392 /* We're not swapping the reserved field */
393 hfs_swap_HFSPlusForkData(&srcRec->forkData.theFork);
394 break;
395 case kHFSPlusAttrExtents:
396 /* We're not swapping the reserved field */
397 for (j = 0; j < kHFSPlusExtentDensity; j++) {
398 srcRec->overflowExtents.extents[j].startBlock =
399 SWAP_BE32(srcRec->overflowExtents.extents[j].startBlock);
400 srcRec->overflowExtents.extents[j].blockCount =
401 SWAP_BE32(srcRec->overflowExtents.extents[j].blockCount);
402 }
403 break;
404 }
405 if (unswap) srcRec->recordType = SWAP_BE32(srcRec->recordType);
406 }
55e303ae
A
407 } else if (fileID > kHFSFirstUserCatalogNodeID) {
408 HotFileKey *srcKey;
409 UInt32 *srcRec;
410
411 for (i = 0; i < srcDesc->numRecords; i++) {
412 srcKey = (HotFileKey *)((char *)src->buffer + srcOffs[i]);
413
414 if (!unswap)
415 srcKey->keyLength = SWAP_BE16 (srcKey->keyLength);
416 srcRec = (u_int32_t *)((char *)srcKey + srcKey->keyLength + 2);
417 if (unswap)
418 srcKey->keyLength = SWAP_BE16 (srcKey->keyLength);
419
420 /* Don't swap srcKey->forkType */
421 /* Don't swap srcKey->pad */
422
423 srcKey->temperature = SWAP_BE32 (srcKey->temperature);
424 srcKey->fileID = SWAP_BE32 (srcKey->fileID);
425
426 *((UInt32 *)srcRec) = SWAP_BE32 (*((UInt32 *)srcRec));
427 }
1c79356b
A
428 } else {
429 panic ("%s unrecognized B-Tree type", "hfs_swap_BTNode:");
430 }
431
55e303ae 432
1c79356b
A
433 return (0);
434}
435
436int
437hfs_swap_HFSBTInternalNode (
438 BlockDescriptor *src,
439 HFSCatalogNodeID fileID,
440 int unswap
441)
442{
443 BTNodeDescriptor *srcDesc = src->buffer;
444 UInt16 *srcOffs = (UInt16 *)((char *)src->buffer + (src->blockSize - (srcDesc->numRecords * sizeof (UInt16))));
445
446 UInt32 i;
447 UInt32 j;
448
1c79356b
A
449 if (fileID == kHFSExtentsFileID) {
450 HFSExtentKey *srcKey;
451 HFSExtentDescriptor *srcRec;
452
453 for (i = 0; i < srcDesc->numRecords; i++) {
454 srcKey = (HFSExtentKey *)((char *)src->buffer + srcOffs[i]);
455
456 /* Don't swap srcKey->keyLength */
457 /* Don't swap srcKey->forkType */
458
459 srcKey->fileID = SWAP_BE32 (srcKey->fileID);
460 srcKey->startBlock = SWAP_BE16 (srcKey->startBlock);
461
462 /* Point to record data (round up to even byte boundary) */
463 srcRec = (HFSExtentDescriptor *)((char *)srcKey + ((srcKey->keyLength + 2) & ~1));
464
465 /* Stop if this is just an index node */
466 if (srcDesc->kind == kBTIndexNode) {
467 *((UInt32 *)srcRec) = SWAP_BE32 (*((UInt32 *)srcRec));
468 continue;
469 }
470
471 /* Swap each extent */
472 for (j = 0; j < kHFSExtentDensity; j++) {
473 srcRec[j].startBlock = SWAP_BE16 (srcRec[j].startBlock);
474 srcRec[j].blockCount = SWAP_BE16 (srcRec[j].blockCount);
475 }
476 }
477
478 } else if (fileID == kHFSCatalogFileID) {
479 HFSCatalogKey *srcKey;
480 SInt16 *srcPtr;
481
482 for (i = 0; i < srcDesc->numRecords; i++) {
483 srcKey = (HFSCatalogKey *)((char *)src->buffer + srcOffs[i]);
484
485 /* Don't swap srcKey->keyLength */
486 /* Don't swap srcKey->reserved */
487
488 srcKey->parentID = SWAP_BE32 (srcKey->parentID);
489
490 /* Don't swap srcKey->nodeName */
491
492 /* Point to record data (round up to even byte boundary) */
493 srcPtr = (SInt16 *)((char *)srcKey + ((srcKey->keyLength + 2) & ~1));
494
495 /* Stop if this is just an index node */
496 if (srcDesc->kind == kBTIndexNode) {
497 *((UInt32 *)srcPtr) = SWAP_BE32 (*((UInt32 *)srcPtr));
498 continue;
499 }
500
501 /* Swap the recordType field, if unswapping, leave to later */
502 if (!unswap) srcPtr[0] = SWAP_BE16 (srcPtr[0]);
503
504 if (srcPtr[0] == kHFSFolderRecord) {
505 HFSCatalogFolder *srcRec = (HFSCatalogFolder *)srcPtr;
506
507 srcRec->flags = SWAP_BE16 (srcRec->flags);
508 srcRec->valence = SWAP_BE16 (srcRec->valence);
509
510 srcRec->folderID = SWAP_BE32 (srcRec->folderID);
511 srcRec->createDate = SWAP_BE32 (srcRec->createDate);
512 srcRec->modifyDate = SWAP_BE32 (srcRec->modifyDate);
513 srcRec->backupDate = SWAP_BE32 (srcRec->backupDate);
514
515 /* Don't swap srcRec->userInfo */
516 /* Don't swap srcRec->finderInfo */
517 /* Don't swap resserved array */
518
519 } else if (srcPtr[0] == kHFSFileRecord) {
520 HFSCatalogFile *srcRec = (HFSCatalogFile *)srcPtr;
521
522 srcRec->flags = srcRec->flags;
523 srcRec->fileType = srcRec->fileType;
524
525 /* Don't swap srcRec->userInfo */
526
527 srcRec->fileID = SWAP_BE32 (srcRec->fileID);
528
529 srcRec->dataStartBlock = SWAP_BE16 (srcRec->dataStartBlock);
530 srcRec->dataLogicalSize = SWAP_BE32 (srcRec->dataLogicalSize);
531 srcRec->dataPhysicalSize = SWAP_BE32 (srcRec->dataPhysicalSize);
532
533 srcRec->rsrcStartBlock = SWAP_BE16 (srcRec->rsrcStartBlock);
534 srcRec->rsrcLogicalSize = SWAP_BE32 (srcRec->rsrcLogicalSize);
535 srcRec->rsrcPhysicalSize = SWAP_BE32 (srcRec->rsrcPhysicalSize);
536
537 srcRec->createDate = SWAP_BE32 (srcRec->createDate);
538 srcRec->modifyDate = SWAP_BE32 (srcRec->modifyDate);
539 srcRec->backupDate = SWAP_BE32 (srcRec->backupDate);
540
541 /* Don't swap srcRec->finderInfo */
542
543 srcRec->clumpSize = SWAP_BE16 (srcRec->clumpSize);
544
545 /* Swap the two sets of extents as an array of six (three each) UInt16 */
546 for (j = 0; j < kHFSExtentDensity * 2; j++) {
547 srcRec->dataExtents[j].startBlock = SWAP_BE16 (srcRec->dataExtents[j].startBlock);
548 srcRec->dataExtents[j].blockCount = SWAP_BE16 (srcRec->dataExtents[j].blockCount);
549 }
550
551 /* Don't swap srcRec->reserved */
552
553 } else if ((srcPtr[0] == kHFSFolderThreadRecord) ||
554 (srcPtr[0] == kHFSFileThreadRecord)) {
555
556 HFSCatalogThread *srcRec = (HFSCatalogThread *)srcPtr;
557
558 /* Don't swap srcRec->reserved array */
559
560 srcRec->parentID = SWAP_BE32 (srcRec->parentID);
561
562 /* Don't swap srcRec->nodeName */
563
564 } else {
565 panic ("%s unrecognized catalog record type", "hfs_swap_BTNode:");
566 }
567
568 /* If unswapping, we can safely swap type now */
569 if (unswap) srcPtr[0] = SWAP_BE16 (srcPtr[0]);
570 }
571
572 } else {
573 panic ("%s unrecognized B-Tree type", "hfs_swap_BTNode:");
574 }
575
576 return (0);
577}