2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef __HFS_ENDIAN_H__
23 #define __HFS_ENDIAN_H__
25 #include <sys/appleapiopts.h>
28 #ifdef __APPLE_API_PRIVATE
32 * This file prototypes endian swapping routines for the HFS/HFS Plus
36 #include "hfscommon/headers/BTreesInternal.h"
37 #include <libkern/OSByteOrder.h>
39 /*********************/
40 /* BIG ENDIAN Macros */
41 /*********************/
42 #define SWAP_BE16(__a) OSSwapBigToHostInt16 (__a)
43 #define SWAP_BE32(__a) OSSwapBigToHostInt32 (__a)
44 #define SWAP_BE64(__a) OSSwapBigToHostInt64 (__a)
46 #if BYTE_ORDER == BIG_ENDIAN
48 /* HFS is always big endian, no swapping needed */
49 #define SWAP_HFS_PLUS_FORK_DATA(__a)
51 /************************/
52 /* LITTLE ENDIAN Macros */
53 /************************/
54 #elif BYTE_ORDER == LITTLE_ENDIAN
56 #define SWAP_HFS_PLUS_FORK_DATA(__a) hfs_swap_HFSPlusForkData ((__a))
59 #warning Unknown byte order
68 * Constants for the "unswap" argument to hfs_swap_BTNode:
70 enum HFSBTSwapDirection
{
71 kSwapBTNodeBigToHost
= 0,
72 kSwapBTNodeHostToBig
= 1,
75 * kSwapBTNodeHeaderRecordOnly is used to swap just the header record
76 * of a header node from big endian (on disk) to host endian (in memory).
77 * It does not swap the node descriptor (forward/backward links, record
78 * count, etc.). It assumes the header record is at offset 0x000E.
80 * Since HFS Plus doesn't have fixed B-tree node sizes, we have to read
81 * the header record to determine the actual node size for that tree
82 * before we can set up the B-tree control block. We read it initially
83 * as 512 bytes, then re-read it once we know the correct node size. Since
84 * we may not have read the entire header node the first time, we can't
85 * swap the record offsets, other records, or do most sanity checks.
87 kSwapBTNodeHeaderRecordOnly
= 3
90 int hfs_swap_BTNode (BlockDescriptor
*src
, vnode_t vp
, enum HFSBTSwapDirection direction
);
96 #endif /* __APPLE_API_PRIVATE */
98 #endif /* __HFS_FORMAT__ */