2 * libhfs - library for reading and writing Macintosh HFS volumes
3 * Copyright (C) 2000 Klaus Halfmann (khalfmann@libra.de)
4 * Original work by 1996-1998 Robert Leslie (rob@mars.org)
6 * This file defines constants,structs etc needed for this library.
7 * Everything found here is usually not related to Apple defintions.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 * $Id: libhfsp.h,v 1.17 2000/10/20 06:16:52 hasi Exp $
31 /* Last error is eventually found here */
32 extern const char *hfsp_error;
34 # define HFSP_ERROR(code, str) \
35 do { hfsp_error = (str), errno = (code); goto fail; } while (0)
38 # define ASSERT(cond) do { if (! (cond)) abort(); } while (0)
40 # define ASSERT(cond) /* nothing */
43 # define SIZE(type, n) ((size_t) (sizeof(type) * (n)))
44 # define ALLOC(type, n) ((type *) malloc(SIZE(type, n)))
45 # define ALLOCX(type, n) ((n) ? ALLOC(type, n) : (type *) 0)
46 # define FREE(ptr) ((ptr) ? (void) free((void *) ptr) : (void) 0)
48 # define REALLOC(ptr, type, n) \
49 ((type *) ((ptr) ? realloc(ptr, SIZE(type, n)) : malloc(SIZE(type, n))))
50 # define REALLOCX(ptr, type, n) \
51 ((n) ? REALLOC(ptr, type, n) : (FREE(ptr), (type *) 0))
53 # define BMTST(bm, num) \
54 (((const byte *) (bm))[(num) >> 3] & (0x80 >> ((num) & 0x07)))
55 # define BMSET(bm, num) \
56 (((byte *) (bm))[(num) >> 3] |= (0x80 >> ((num) & 0x07)))
57 # define BMCLR(bm, num) \
58 (((byte *) (bm))[(num) >> 3] &= ~(0x80 >> ((num) & 0x07)))
60 # define STRINGIZE(x) #x
61 # define STR(x) STRINGIZE(x)
63 /* used by internal routines to specify the open modes */
64 # define HFSP_MODE_RDONLY 0
65 # define HFSP_MODE_RDWR 1
66 # define HFSP_MODE_ANY 2
68 /* Signatures registered with Apple to identify this driver */
69 /* Identifies the userland implementation */
70 # define HPLS_SIGNATURE 0x482B4C58 // 'H+LX'
71 /* Identifies the kernel module by Brad Boyer (flar@pants.nu) */
72 # define HPLS_SIGRES1 0x482B4C78 // 'H+Lx'
73 /* not jet in use ... */
74 # define HPLS_SIGRES2 0x482B6C78 // 'H+lx'
75 /* Signature used by Apple */
76 # define HPAPPLE_SIGNATURE 0x382e3130 // '8.10'
78 /* Version used for this implementation of HFS+. This is not related
79 * to the VERSION file found at the top-level of this package,
80 * but designates the version of the low level code */
81 #define HPLS_VERSION 1 /* must fit in a short */
84 /* Othe Signatures may follow for informational purpos */
86 /* prototype for key comparing functions. */
87 typedef int (*hfsp_key_compare) (void* key1, void* key2);
89 /* prototype for key reading (necessary for byte swapping) */
90 typedef void* (*hfsp_key_read) (void* p, void* key);
92 struct volume; /* foreward declaration for btree needed */
94 /* Structures for a node cache. The cache is an array
95 * with linear search. (So making it to big may make
96 * things slower). It is searched in a round robin
103 // as lower this number as higher the priority.
104 // decremetned on any sucessfull usage
105 // incremented else, intial value height*DEPTHFACTOR
106 UInt16 index; // of node in fork
107 // 0 means empty, since first node is node header
108 // contents of node in original byte order
109 UInt16 flags; // like DIRTY etc.
114 UInt32 index; // duplicate of above
115 btree_node_desc desc; // header of node
116 char node[0]; // actual node_size
117 // contents of node in original byte order
122 int size; // number of nodes in the cache
123 int currindex; // round robin index
124 int nodebufsize; // size of complete node_buf, including node
126 char *buffers; // actually *node_buf
131 struct volume* vol; /* pointer to volume this tree is part of */
132 hfsp_fork_raw* fork; /* pointer to fork this tree is part of */
133 UInt32 cnid; /* (pseudo) file id for the fork */
134 hfsp_key_compare kcomp;
135 /* function used for key compare in _this_ btree */
137 /* fucntion used to read a key int _this_ btree */
141 /* Number of volume blocks per node (usually 1-4) */
143 /* Warning all functions of btrees and records may modify
144 the following values ! */
145 // UInt16 node_index; /* index of node in fork */
146 // btree_node_desc node; /* current node under examination */
147 // char* buf; /* buf with size of a node */
150 /* Function on btrees are defined in btree.h */
152 /* A Wrapper around the raw hfs+ volume header for additional information
153 * needed by this library.
156 typedef struct volume
158 int os_fd; /* OS dependend reference to device */
159 UInt16 blksize_bits; /* blocksize of device = 1 << blksize_bits */
161 UInt32 blksize; /* always 1 << blksize_bits */
163 /* Offset from physical to logical blocks,
164 eventually intodruced by HFS wrapper */
165 UInt32 maxblocks; /* maximum number of blocks in device */
166 // UInt32 currblock; /* value of current block, to cache blocks */
167 hfsp_vh vol; /* raw volume data */
168 // void* blockbuf; /* (single) buffer for fetching one block */
169 /* Buffer has double size of blksize to allow cross block reading */
171 btree* extents; /* is NULL by default and intialized when needed */
172 btree catalog; /* This is always neeeded */
175 /* Functions on volumes are defined in volume.h */
177 typedef struct { // may not be used as found here
178 btree* tree; // tree where this record is contained in.
179 UInt16 node_index; /* index of record in btree */
180 UInt16 keyind; /* index of current key in btree */
181 hfsp_cat_key key; /* current key */
182 UInt32 child; /* child node belonging to this key */
186 btree* tree; // tree where this record is contained in.
187 UInt16 node_index; /* index of record in btree */
188 UInt16 keyind; /* index of current key in btree */
189 hfsp_extent_key key; /* current key */
190 hfsp_extent_rec extent; /* The payload carried around */
194 btree* tree; // tree where this record is contained in.
195 UInt16 node_index; /* index of record in btree */
196 UInt16 keyind; /* index of current key in btree */
197 hfsp_cat_key key; /* current key */
198 hfsp_cat_entry record; /* current record */
201 /* Functions on records are defined in record.h */