]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/hfs/hfs_endian.h
xnu-792.6.76.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_endian.h
... / ...
CommitLineData
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 <architecture/byte_order.h>
38
39/*********************/
40/* BIG ENDIAN Macros */
41/*********************/
42#if BYTE_ORDER == BIG_ENDIAN
43
44 /* HFS is always big endian, make swaps into no-ops */
45 #define SWAP_BE16(__a) (__a)
46 #define SWAP_BE32(__a) (__a)
47 #define SWAP_BE64(__a) (__a)
48
49 /* HFS is always big endian, no swapping needed */
50 #define SWAP_HFS_PLUS_FORK_DATA(__a)
51
52/************************/
53/* LITTLE ENDIAN Macros */
54/************************/
55#elif BYTE_ORDER == LITTLE_ENDIAN
56
57 /* HFS is always big endian, make swaps actually swap */
58 #define SWAP_BE16(__a) NXSwapBigShortToHost (__a)
59 #define SWAP_BE32(__a) NXSwapBigLongToHost (__a)
60 #define SWAP_BE64(__a) NXSwapBigLongLongToHost (__a)
61
62 #define SWAP_HFS_PLUS_FORK_DATA(__a) hfs_swap_HFSPlusForkData ((__a))
63
64#else
65#warning Unknown byte order
66#error
67#endif
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73/*
74 * Constants for the "unswap" argument to hfs_swap_BTNode:
75 */
76enum HFSBTSwapDirection {
77 kSwapBTNodeBigToHost = 0,
78 kSwapBTNodeHostToBig = 1,
79
80 /*
81 * kSwapBTNodeHeaderRecordOnly is used to swap just the header record
82 * of a header node from big endian (on disk) to host endian (in memory).
83 * It does not swap the node descriptor (forward/backward links, record
84 * count, etc.). It assumes the header record is at offset 0x000E.
85 *
86 * Since HFS Plus doesn't have fixed B-tree node sizes, we have to read
87 * the header record to determine the actual node size for that tree
88 * before we can set up the B-tree control block. We read it initially
89 * as 512 bytes, then re-read it once we know the correct node size. Since
90 * we may not have read the entire header node the first time, we can't
91 * swap the record offsets, other records, or do most sanity checks.
92 */
93 kSwapBTNodeHeaderRecordOnly = 3
94};
95
96int hfs_swap_BTNode (BlockDescriptor *src, vnode_t vp, enum HFSBTSwapDirection direction);
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* __APPLE_API_PRIVATE */
103#endif /* KERNEL */
104#endif /* __HFS_FORMAT__ */