]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfs_endian.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_endian.h
1 /*
2 * Copyright (c) 2000 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 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.
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 #ifndef __HFS_ENDIAN_H__
23 #define __HFS_ENDIAN_H__
24
25 #include <sys/appleapiopts.h>
26
27 #ifdef KERNEL
28 #ifdef __APPLE_API_PRIVATE
29 /*
30 * hfs_endian.h
31 *
32 * This file prototypes endian swapping routines for the HFS/HFS Plus
33 * volume format.
34 */
35 #include "hfs.h"
36 #include "hfscommon/headers/BTreesInternal.h"
37 #include <libkern/OSByteOrder.h>
38
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)
45
46 #if BYTE_ORDER == BIG_ENDIAN
47
48 /* HFS is always big endian, no swapping needed */
49 #define SWAP_HFS_PLUS_FORK_DATA(__a)
50
51 /************************/
52 /* LITTLE ENDIAN Macros */
53 /************************/
54 #elif BYTE_ORDER == LITTLE_ENDIAN
55
56 #define SWAP_HFS_PLUS_FORK_DATA(__a) hfs_swap_HFSPlusForkData ((__a))
57
58 #else
59 #warning Unknown byte order
60 #error
61 #endif
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 /*
68 * Constants for the "unswap" argument to hfs_swap_BTNode:
69 */
70 enum HFSBTSwapDirection {
71 kSwapBTNodeBigToHost = 0,
72 kSwapBTNodeHostToBig = 1,
73
74 /*
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.
79 *
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.
86 */
87 kSwapBTNodeHeaderRecordOnly = 3
88 };
89
90 int hfs_swap_BTNode (BlockDescriptor *src, vnode_t vp, enum HFSBTSwapDirection direction);
91
92 #ifdef __cplusplus
93 }
94 #endif
95
96 #endif /* __APPLE_API_PRIVATE */
97 #endif /* KERNEL */
98 #endif /* __HFS_FORMAT__ */