]> code.delx.au - refind/blob - filesystems/fsw_hfs.h
Clarified description of "default_selection" in configfile.html.
[refind] / filesystems / fsw_hfs.h
1 /* $Id: fsw_hfs.h 29125 2010-05-06 09:43:05Z vboxsync $ */
2 /** @file
3 * fsw_hfs.h - HFS file system driver header.
4 */
5
6 /*
7 * Copyright (C) 2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18 #ifndef _FSW_HFS_H_
19 #define _FSW_HFS_H_
20
21 #define VOLSTRUCTNAME fsw_hfs_volume
22 #define DNODESTRUCTNAME fsw_hfs_dnode
23
24 #include "fsw_core.h"
25
26
27 //! Block size for HFS volumes.
28 #define HFS_BLOCKSIZE 512
29
30 //! Block number where the HFS superblock resides.
31 #define HFS_SUPERBLOCK_BLOCKNO 2
32
33 /* Make world look Applish enough for the system header describing HFS layout */
34 #define __APPLE_API_PRIVATE
35 #define __APPLE_API_UNSTABLE
36
37 #define u_int8_t fsw_u8
38 #define u_int16_t fsw_u16
39 #define u_int32_t fsw_u32
40 #define u_int64_t fsw_u64
41 #define int8_t fsw_s8
42 #define int16_t fsw_s16
43 #define int32_t fsw_s32
44 #define int64_t fsw_s64
45
46 #include "hfs_format.h"
47
48 #undef u_int8_t
49 #undef u_int16_t
50 #undef u_int32_t
51 #undef u_int64_t
52 #undef int8_t
53 #undef int16_t
54 #undef int32_t
55 #undef int64_t
56
57 #pragma pack(1)
58 #ifdef _MSC_VER
59 /* vasily: disable warning for non-standard anonymous struct/union
60 * declarations
61 */
62 # pragma warning (disable:4201)
63 # define inline __inline
64 #endif
65
66 struct hfs_dirrec {
67 fsw_u8 _dummy;
68 };
69
70 struct fsw_hfs_key
71 {
72 union
73 {
74 struct HFSPlusExtentKey ext_key;
75 struct HFSPlusCatalogKey cat_key;
76 fsw_u16 key_len; /* Length is at the beginning of all keys */
77 };
78 };
79
80 #pragma pack()
81
82 typedef enum {
83 /* Regular HFS */
84 FSW_HFS_PLAIN = 0,
85 /* HFS+ */
86 FSW_HFS_PLUS,
87 /* HFS+ embedded to HFS */
88 FSW_HFS_PLUS_EMB
89 } fsw_hfs_kind;
90
91 /**
92 * HFS: Dnode structure with HFS-specific data.
93 */
94
95 struct fsw_hfs_dnode
96 {
97 struct fsw_dnode g; //!< Generic dnode structure
98 HFSPlusExtentRecord extents;
99 fsw_u32 ctime;
100 fsw_u32 mtime;
101 fsw_u64 used_bytes;
102 };
103
104 /**
105 * HFS: In-memory B-tree structure.
106 */
107 struct fsw_hfs_btree
108 {
109 fsw_u32 root_node;
110 fsw_u32 node_size;
111 struct fsw_hfs_dnode* file;
112 };
113
114
115 /**
116 * HFS: In-memory volume structure with HFS-specific data.
117 */
118
119 struct fsw_hfs_volume
120 {
121 struct fsw_volume g; //!< Generic volume structure
122
123 struct HFSPlusVolumeHeader *primary_voldesc; //!< Volume Descriptor
124 struct fsw_hfs_btree catalog_tree; // Catalog tree
125 struct fsw_hfs_btree extents_tree; // Extents overflow tree
126 struct fsw_hfs_dnode root_file;
127 int case_sensitive;
128 fsw_u32 block_size_shift;
129 fsw_hfs_kind hfs_kind;
130 fsw_u32 emb_block_off;
131 };
132
133 /* Endianess swappers */
134 static inline fsw_u16
135 swab16(fsw_u16 x)
136 {
137 return (x<<8 | ((x & 0xff00)>>8));
138 }
139
140 static inline fsw_u32
141 swab32(fsw_u32 x)
142 {
143 return x<<24 | x>>24 |
144 (x & (fsw_u32)0x0000ff00UL)<<8 |
145 (x & (fsw_u32)0x00ff0000UL)>>8;
146 }
147
148
149 static inline fsw_u64
150 swab64(fsw_u64 x)
151 {
152 return x<<56 | x>>56 |
153 (x & (fsw_u64)0x000000000000ff00ULL)<<40 |
154 (x & (fsw_u64)0x0000000000ff0000ULL)<<24 |
155 (x & (fsw_u64)0x00000000ff000000ULL)<< 8 |
156 (x & (fsw_u64)0x000000ff00000000ULL)>> 8 |
157 (x & (fsw_u64)0x0000ff0000000000ULL)>>24 |
158 (x & (fsw_u64)0x00ff000000000000ULL)>>40;
159 }
160
161 static inline fsw_u16
162 be16_to_cpu(fsw_u16 x)
163 {
164 return swab16(x);
165 }
166
167 static inline fsw_u16
168 cpu_to_be16(fsw_u16 x)
169 {
170 return swab16(x);
171 }
172
173
174 static inline fsw_u32
175 cpu_to_be32(fsw_u32 x)
176 {
177 return swab32(x);
178 }
179
180 static inline fsw_u32
181 be32_to_cpu(fsw_u32 x)
182 {
183 return swab32(x);
184 }
185
186 static inline fsw_u64
187 be64_to_cpu(fsw_u64 x)
188 {
189 return swab64(x);
190 }
191
192 #endif