]>
git.saurik.com Git - hfs.git/blob - newfs_hfs/hfs_endian.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * This file implements endian swapping routines for the HFS/HFS Plus
31 #include <sys/types.h>
34 #include <libkern/OSByteOrder.h>
35 #include <hfs/hfs_format.h>
37 #include "hfs_endian.h"
41 /* Private swapping routines */
42 int hfs_swap_HFSPlusBTInternalNode (BlockDescriptor
*src
, HFSCatalogNodeID fileID
, int unswap
);
43 int hfs_swap_HFSBTInternalNode (BlockDescriptor
*src
, HFSCatalogNodeID fileID
, int unswap
);
46 static void hfs_swap_HFSPlusForkData (HFSPlusForkData
*src
);
49 * hfs_swap_HFSMasterDirectoryBlock
51 * Specially modified to swap parts of the finder info
54 hfs_swap_HFSMasterDirectoryBlock (
58 HFSMasterDirectoryBlock
*src
= (HFSMasterDirectoryBlock
*)buf
;
60 src
->drSigWord
= SWAP_BE16 (src
->drSigWord
);
61 src
->drCrDate
= SWAP_BE32 (src
->drCrDate
);
62 src
->drLsMod
= SWAP_BE32 (src
->drLsMod
);
63 src
->drAtrb
= SWAP_BE16 (src
->drAtrb
);
64 src
->drNmFls
= SWAP_BE16 (src
->drNmFls
);
65 src
->drVBMSt
= SWAP_BE16 (src
->drVBMSt
);
66 src
->drAllocPtr
= SWAP_BE16 (src
->drAllocPtr
);
67 src
->drNmAlBlks
= SWAP_BE16 (src
->drNmAlBlks
);
68 src
->drAlBlkSiz
= SWAP_BE32 (src
->drAlBlkSiz
);
69 src
->drClpSiz
= SWAP_BE32 (src
->drClpSiz
);
70 src
->drAlBlSt
= SWAP_BE16 (src
->drAlBlSt
);
71 src
->drNxtCNID
= SWAP_BE32 (src
->drNxtCNID
);
72 src
->drFreeBks
= SWAP_BE16 (src
->drFreeBks
);
76 src
->drVolBkUp
= SWAP_BE32 (src
->drVolBkUp
);
77 src
->drVSeqNum
= SWAP_BE16 (src
->drVSeqNum
);
78 src
->drWrCnt
= SWAP_BE32 (src
->drWrCnt
);
79 src
->drXTClpSiz
= SWAP_BE32 (src
->drXTClpSiz
);
80 src
->drCTClpSiz
= SWAP_BE32 (src
->drCTClpSiz
);
81 src
->drNmRtDirs
= SWAP_BE16 (src
->drNmRtDirs
);
82 src
->drFilCnt
= SWAP_BE32 (src
->drFilCnt
);
83 src
->drDirCnt
= SWAP_BE32 (src
->drDirCnt
);
85 /* Swap just the 'blessed folder' in drFndrInfo */
86 src
->drFndrInfo
[0] = SWAP_BE32 (src
->drFndrInfo
[0]);
88 src
->drEmbedSigWord
= SWAP_BE16 (src
->drEmbedSigWord
);
89 src
->drEmbedExtent
.startBlock
= SWAP_BE16 (src
->drEmbedExtent
.startBlock
);
90 src
->drEmbedExtent
.blockCount
= SWAP_BE16 (src
->drEmbedExtent
.blockCount
);
92 src
->drXTFlSize
= SWAP_BE32 (src
->drXTFlSize
);
93 src
->drXTExtRec
[0].startBlock
= SWAP_BE16 (src
->drXTExtRec
[0].startBlock
);
94 src
->drXTExtRec
[0].blockCount
= SWAP_BE16 (src
->drXTExtRec
[0].blockCount
);
95 src
->drXTExtRec
[1].startBlock
= SWAP_BE16 (src
->drXTExtRec
[1].startBlock
);
96 src
->drXTExtRec
[1].blockCount
= SWAP_BE16 (src
->drXTExtRec
[1].blockCount
);
97 src
->drXTExtRec
[2].startBlock
= SWAP_BE16 (src
->drXTExtRec
[2].startBlock
);
98 src
->drXTExtRec
[2].blockCount
= SWAP_BE16 (src
->drXTExtRec
[2].blockCount
);
100 src
->drCTFlSize
= SWAP_BE32 (src
->drCTFlSize
);
101 src
->drCTExtRec
[0].startBlock
= SWAP_BE16 (src
->drCTExtRec
[0].startBlock
);
102 src
->drCTExtRec
[0].blockCount
= SWAP_BE16 (src
->drCTExtRec
[0].blockCount
);
103 src
->drCTExtRec
[1].startBlock
= SWAP_BE16 (src
->drCTExtRec
[1].startBlock
);
104 src
->drCTExtRec
[1].blockCount
= SWAP_BE16 (src
->drCTExtRec
[1].blockCount
);
105 src
->drCTExtRec
[2].startBlock
= SWAP_BE16 (src
->drCTExtRec
[2].startBlock
);
106 src
->drCTExtRec
[2].blockCount
= SWAP_BE16 (src
->drCTExtRec
[2].blockCount
);
110 * hfs_swap_HFSPlusVolumeHeader
113 hfs_swap_HFSPlusVolumeHeader (
117 HFSPlusVolumeHeader
*src
= (HFSPlusVolumeHeader
*)buf
;
119 src
->signature
= SWAP_BE16 (src
->signature
);
120 src
->version
= SWAP_BE16 (src
->version
);
121 src
->attributes
= SWAP_BE32 (src
->attributes
);
122 src
->lastMountedVersion
= SWAP_BE32 (src
->lastMountedVersion
);
124 src
->journalInfoBlock
= SWAP_BE32 (src
->journalInfoBlock
);
126 src
->createDate
= SWAP_BE32 (src
->createDate
);
127 src
->modifyDate
= SWAP_BE32 (src
->modifyDate
);
128 src
->backupDate
= SWAP_BE32 (src
->backupDate
);
129 src
->checkedDate
= SWAP_BE32 (src
->checkedDate
);
130 src
->fileCount
= SWAP_BE32 (src
->fileCount
);
131 src
->folderCount
= SWAP_BE32 (src
->folderCount
);
132 src
->blockSize
= SWAP_BE32 (src
->blockSize
);
133 src
->totalBlocks
= SWAP_BE32 (src
->totalBlocks
);
134 src
->freeBlocks
= SWAP_BE32 (src
->freeBlocks
);
135 src
->nextAllocation
= SWAP_BE32 (src
->nextAllocation
);
136 src
->rsrcClumpSize
= SWAP_BE32 (src
->rsrcClumpSize
);
137 src
->dataClumpSize
= SWAP_BE32 (src
->dataClumpSize
);
138 src
->nextCatalogID
= SWAP_BE32 (src
->nextCatalogID
);
139 src
->writeCount
= SWAP_BE32 (src
->writeCount
);
140 src
->encodingsBitmap
= SWAP_BE64 (src
->encodingsBitmap
);
142 /* Don't swap finderInfo */
144 hfs_swap_HFSPlusForkData (&src
->allocationFile
);
145 hfs_swap_HFSPlusForkData (&src
->extentsFile
);
146 hfs_swap_HFSPlusForkData (&src
->catalogFile
);
147 hfs_swap_HFSPlusForkData (&src
->attributesFile
);
148 hfs_swap_HFSPlusForkData (&src
->startupFile
);
152 * hfs_swap_HFSPlusForkData
154 * There's still a few spots where we still need to swap the fork data.
157 hfs_swap_HFSPlusForkData (
163 src
->logicalSize
= SWAP_BE64 (src
->logicalSize
);
165 src
->clumpSize
= SWAP_BE32 (src
->clumpSize
);
166 src
->totalBlocks
= SWAP_BE32 (src
->totalBlocks
);
168 for (i
= 0; i
< kHFSPlusExtentDensity
; i
++) {
169 src
->extents
[i
].startBlock
= SWAP_BE32 (src
->extents
[i
].startBlock
);
170 src
->extents
[i
].blockCount
= SWAP_BE32 (src
->extents
[i
].blockCount
);