xref: /netbsd-src/sys/fs/hfs/libhfs.h (revision daf6c4152fcddc27c445489775ed1f66ab4ea9a9)
1 /*	$NetBSD: libhfs.h,v 1.4 2008/09/03 22:56:51 gmcgarry Exp $	*/
2 
3 /*-
4  * Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Yevgeny Binder, Dieter Baron, and Pelle Johansson.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _FS_HFS_LIBHFS_H_
33 #define _FS_HFS_LIBHFS_H_
34 
35 #include <sys/endian.h>
36 #include <sys/param.h>
37 #include <sys/mount.h>	/* needs to go after sys/param.h or compile fails */
38 #include <sys/types.h>
39 #if defined(_KERNEL)
40 #include <sys/kernel.h>
41 #include <sys/systm.h>
42 #include <machine/stdarg.h>
43 #include <sys/fcntl.h>
44 #endif /* defined(_KERNEL) */
45 
46 #if !defined(_KERNEL) && !defined(STANDALONE)
47 #include <fcntl.h>
48 #include <iconv.h>
49 #include <stdarg.h>
50 #include <stdint.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <unistd.h>
54 #endif /* !defined(_KERNEL) && !defined(STANDALONE) */
55 
56 #ifndef va_list
57 #define va_list _BSD_VA_LIST_
58 #endif /* !va_list */
59 
60 #define max(A,B) ((A) > (B) ? (A):(B))
61 #define min(A,B) ((A) < (B) ? (A):(B))
62 
63 
64 /* Macros to handle errors in this library. Not recommended outside libhfs.c */
65 #ifdef __PCC__
66 #define HFS_LIBERR(format, ...) \
67 	do{ hfslib_error(format, __FILE__, __LINE__); \
68 		goto error; } while(/*CONSTCOND*/ 0)
69 #else
70 #define HFS_LIBERR(format, ...) \
71 	do{ hfslib_error(format, __FILE__, __LINE__, ##__VA_ARGS__); \
72 		goto error; } while(/*CONSTCOND*/ 0)
73 #endif
74 
75 #if 0
76 #pragma mark Constants (on-disk)
77 #endif
78 
79 
80 enum
81 {
82 	HFS_SIG_HFSP	= 0x482B,	/* 'H+' */
83 	HFS_SIG_HFSX	= 0x4858,	/* 'HX' */
84 	HFS_SIG_HFS	= 0x4244	/* 'BD' */
85 }; /* volume signatures */
86 
87 typedef enum
88 {
89 							/* bits 0-6 are reserved */
90 	HFS_VOL_HWLOCK			= 7,
91 	HFS_VOL_UNMOUNTED		= 8,
92 	HFS_VOL_BADBLOCKS		= 9,
93 	HFS_VOL_NOCACHE		= 10,
94 	HFS_VOL_DIRTY			= 11,
95 	HFS_VOL_CNIDS_RECYCLED	= 12,
96 	HFS_VOL_JOURNALED		= 13,
97 							/* bit 14 is reserved */
98 	HFS_VOL_SWLOCK			= 15
99 							/* bits 16-31 are reserved */
100 } hfs_volume_attribute_bit; /* volume header attribute bits */
101 
102 typedef enum
103 {
104 	HFS_LEAFNODE	= -1,
105 	HFS_INDEXNODE	= 0,
106 	HFS_HEADERNODE	= 1,
107 	HFS_MAPNODE	= 2
108 } hfs_node_kind; /* btree node kinds */
109 
110 enum
111 {
112 	HFS_BAD_CLOSE_MASK			= 0x00000001,
113 	HFS_BIG_KEYS_MASK			= 0x00000002,
114 	HFS_VAR_INDEX_KEYS_MASK	= 0x00000004
115 }; /* btree header attribute masks */
116 
117 typedef enum
118 {
119 	HFS_CNID_ROOT_PARENT	= 1,
120 	HFS_CNID_ROOT_FOLDER	= 2,
121 	HFS_CNID_EXTENTS		= 3,
122 	HFS_CNID_CATALOG		= 4,
123 	HFS_CNID_BADBLOCKS		= 5,
124 	HFS_CNID_ALLOCATION	= 6,
125 	HFS_CNID_STARTUP		= 7,
126 	HFS_CNID_ATTRIBUTES	= 8,
127 								/* CNIDs 9-13 are reserved */
128 	HFS_CNID_REPAIR		= 14,
129 	HFS_CNID_TEMP			= 15,
130 	HFS_CNID_USER			= 16
131 } hfs_special_cnid; /* special CNID values */
132 
133 typedef enum
134 {
135 	HFS_REC_FLDR			= 0x0001,
136 	HFS_REC_FILE			= 0x0002,
137 	HFS_REC_FLDR_THREAD	= 0x0003,
138 	HFS_REC_FILE_THREAD	= 0x0004
139 } hfs_catalog_rec_kind; /* catalog record types */
140 
141 enum
142 {
143     HFS_JOURNAL_ON_DISK_MASK		= 0x00000001, /* journal on same volume */
144     HFS_JOURNAL_ON_OTHER_MASK		= 0x00000002, /* journal elsewhere */
145     HFS_JOURNAL_NEEDS_INIT_MASK	= 0x00000004
146 }; /* journal flag masks */
147 
148 enum
149 {
150 	HFS_JOURNAL_HEADER_MAGIC	= 0x4a4e4c78,
151 	HFS_JOURNAL_ENDIAN_MAGIC	= 0x12345678
152 }; /* journal magic numbers */
153 
154 enum
155 {
156 	HFS_DATAFORK	= 0x00,
157 	HFS_RSRCFORK	= 0xFF
158 }; /* common fork types */
159 
160 enum
161 {
162 	HFS_KEY_CASEFOLD	= 0xCF,
163 	HFS_KEY_BINARY		= 0XBC
164 }; /* catalog key comparison method types */
165 
166 enum
167 {
168 	HFS_MIN_CAT_KEY_LEN	= 6,
169 	HFS_MAX_CAT_KEY_LEN	= 516,
170 	HFS_MAX_EXT_KEY_LEN	= 10
171 };
172 
173 enum {
174     HFS_HARD_LINK_FILE_TYPE = 0x686C6E6B,  /* 'hlnk' */
175     HFS_HFSLUS_CREATOR     = 0x6866732B   /* 'hfs+' */
176 };
177 
178 
179 #if 0
180 #pragma mark -
181 #pragma mark Constants (custom)
182 #endif
183 
184 
185 /* number of bytes between start of volume and volume header */
186 #define HFS_VOLUME_HEAD_RESERVE_SIZE	1024
187 
188 typedef enum
189 {
190 	HFS_CATALOG_FILE = 1,
191 	HFS_EXTENTS_FILE = 2,
192 	HFS_ATTRIBUTES_FILE = 3
193 } hfs_btree_file_type; /* btree file kinds */
194 
195 
196 #if 0
197 #pragma mark -
198 #pragma mark On-Disk Types (Mac OS specific)
199 #endif
200 
201 typedef uint32_t	hfs_macos_type_code; /* four 1-byte char field */
202 
203 typedef struct
204 {
205   int16_t	v;
206   int16_t	h;
207 } hfs_macos_point_t;
208 
209 typedef struct
210 {
211   int16_t	t;	/* top */
212   int16_t	l;	/* left */
213   int16_t	b;	/* bottom */
214   int16_t	r;	/* right */
215 } hfs_macos_rect_t;
216 
217 typedef struct
218 {
219   hfs_macos_type_code	file_type;
220   hfs_macos_type_code	file_creator;
221   uint16_t				finder_flags;
222   hfs_macos_point_t	location;
223   uint16_t				reserved;
224 } hfs_macos_file_info_t;
225 
226 typedef struct
227 {
228   int16_t	reserved[4];
229   uint16_t	extended_finder_flags;
230   int16_t	reserved2;
231   int32_t	put_away_folder_cnid;
232 } hfs_macos_extended_file_info_t;
233 
234 typedef struct
235 {
236   hfs_macos_rect_t		window_bounds;
237   uint16_t				finder_flags;
238   hfs_macos_point_t	location;
239   uint16_t				reserved;
240 } hfs_macos_folder_info_t;
241 
242 typedef struct
243 {
244   hfs_macos_point_t	scroll_position;
245   int32_t				reserved;
246   uint16_t				extended_finder_flags;
247   int16_t				reserved2;
248   int32_t				put_away_folder_cnid;
249 } hfs_macos_extended_folder_info_t;
250 
251 
252 #if 0
253 #pragma mark -
254 #pragma mark On-Disk Types
255 #endif
256 
257 typedef uint16_t unichar_t;
258 
259 typedef uint32_t hfs_cnid_t;
260 
261 
262 typedef struct
263 {
264 	uint16_t	length;
265 	unichar_t	unicode[255];
266 } hfs_unistr255_t;
267 
268 typedef struct
269 {
270 	uint32_t	start_block;
271 	uint32_t	block_count;
272 } hfs_extent_descriptor_t;
273 
274 typedef hfs_extent_descriptor_t hfs_extent_record_t[8];
275 
276 typedef struct hfs_fork_t
277 {
278 	uint64_t				logical_size;
279 	uint32_t				clump_size;
280 	uint32_t				total_blocks;
281 	hfs_extent_record_t	extents;
282 } hfs_fork_t;
283 
284 typedef struct
285 {
286 	uint16_t	signature;
287 	uint16_t	version;
288 	uint32_t	attributes;
289 	uint32_t	last_mounting_version;
290 	uint32_t	journal_info_block;
291 
292 	uint32_t	date_created;
293 	uint32_t	date_modified;
294 	uint32_t	date_backedup;
295 	uint32_t	date_checked;
296 
297 	uint32_t	file_count;
298 	uint32_t	folder_count;
299 
300 	uint32_t	block_size;
301 	uint32_t	total_blocks;
302 	uint32_t	free_blocks;
303 
304 	uint32_t	next_alloc_block;
305 	uint32_t	rsrc_clump_size;
306 	uint32_t	data_clump_size;
307 	hfs_cnid_t	next_cnid;
308 
309 	uint32_t	write_count;
310 	uint64_t	encodings;
311 
312 	uint32_t	finder_info[8];
313 
314 	hfs_fork_t	allocation_file;
315 	hfs_fork_t	extents_file;
316 	hfs_fork_t	catalog_file;
317 	hfs_fork_t	attributes_file;
318 	hfs_fork_t	startup_file;
319 } hfs_volume_header_t;
320 
321 typedef struct
322 {
323 	uint32_t	flink;
324 	uint32_t	blink;
325 	int8_t		kind;
326 	uint8_t		height;
327 	uint16_t	num_recs;
328 	uint16_t	reserved;
329 } hfs_node_descriptor_t;
330 
331 typedef struct
332 {
333 	uint16_t	tree_depth;
334 	uint32_t	root_node;
335 	uint32_t	leaf_recs;
336 	uint32_t	first_leaf;
337 	uint32_t	last_leaf;
338 	uint16_t	node_size;
339 	uint16_t	max_key_len;
340 	uint32_t	total_nodes;
341 	uint32_t	free_nodes;
342 	uint16_t	reserved;
343 	uint32_t	clump_size;		/* misaligned */
344 	uint8_t		btree_type;
345 	uint8_t		keycomp_type;
346 	uint32_t	attributes;		/* long aligned again */
347 	uint32_t	reserved2[16];
348 } hfs_header_record_t;
349 
350 typedef struct
351 {
352 	uint16_t			key_len;
353 	hfs_cnid_t			parent_cnid;
354 	hfs_unistr255_t	name;
355 } hfs_catalog_key_t;
356 
357 typedef struct
358 {
359 	uint16_t	key_length;
360 	uint8_t		fork_type;
361 	uint8_t		padding;
362 	hfs_cnid_t	file_cnid;
363 	uint32_t	start_block;
364 } hfs_extent_key_t;
365 
366 typedef struct
367 {
368 	uint32_t	owner_id;
369 	uint32_t	group_id;
370 	uint8_t		admin_flags;
371 	uint8_t		owner_flags;
372 	uint16_t	file_mode;
373 	union
374 	{
375 		uint32_t	inode_num;
376 		uint32_t	link_count;
377 		uint32_t	raw_device;
378 	} special;
379 } hfs_bsd_data_t;
380 
381 typedef struct
382 {
383 	int16_t			rec_type;
384 	uint16_t		flags;
385 	uint32_t		valence;
386 	hfs_cnid_t		cnid;
387 	uint32_t		date_created;
388 	uint32_t		date_content_mod;
389 	uint32_t		date_attrib_mod;
390 	uint32_t		date_accessed;
391 	uint32_t		date_backedup;
392 	hfs_bsd_data_t						bsd;
393 	hfs_macos_folder_info_t			user_info;
394 	hfs_macos_extended_folder_info_t	finder_info;
395 	uint32_t		text_encoding;
396 	uint32_t		reserved;
397 } hfs_folder_record_t;
398 
399 typedef struct
400 {
401 	int16_t			rec_type;
402 	uint16_t		flags;
403 	uint32_t		reserved;
404 	hfs_cnid_t		cnid;
405 	uint32_t		date_created;
406 	uint32_t		date_content_mod;
407 	uint32_t		date_attrib_mod;
408 	uint32_t		date_accessed;
409 	uint32_t		date_backedup;
410 	hfs_bsd_data_t						bsd;
411 	hfs_macos_file_info_t				user_info;
412 	hfs_macos_extended_file_info_t		finder_info;
413 	uint32_t		text_encoding;
414 	uint32_t		reserved2;
415 	hfs_fork_t		data_fork;
416 	hfs_fork_t		rsrc_fork;
417 } hfs_file_record_t;
418 
419 typedef struct
420 {
421 	int16_t				rec_type;
422 	int16_t				reserved;
423 	hfs_cnid_t			parent_cnid;
424 	hfs_unistr255_t	name;
425 } hfs_thread_record_t;
426 
427 typedef struct
428 {
429 	uint32_t	flags;
430 	uint32_t	device_signature[8];
431 	uint64_t	offset;
432 	uint64_t	size;
433 	uint64_t	reserved[32];
434 } hfs_journal_info_t;
435 
436 typedef struct
437 {
438 	uint32_t	magic;
439 	uint32_t	endian;
440 	uint64_t	start;
441 	uint64_t	end;
442 	uint64_t	size;
443 	uint32_t	blocklist_header_size;
444 	uint32_t	checksum;
445 	uint32_t	journal_header_size;
446 } hfs_journal_header_t;
447 
448 /* plain HFS structures needed for hfs wrapper support */
449 
450 typedef struct
451 {
452         uint16_t        start_block;
453         uint16_t        block_count;
454 } hfs_hfs_extent_descriptor_t;
455 
456 typedef hfs_hfs_extent_descriptor_t hfs_hfs_extent_record_t[3];
457 
458 typedef struct
459 {
460         uint16_t        signature;
461         uint32_t        date_created;
462         uint32_t        date_modified;
463         uint16_t        attributes;
464         uint16_t        root_file_count;
465         uint16_t        volume_bitmap;
466         uint16_t        next_alloc_block;
467         uint16_t        total_blocks;
468         uint32_t        block_size;
469         uint32_t        clump_size;
470         uint16_t        first_block;
471         hfs_cnid_t      next_cnid;
472         uint16_t        free_blocks;
473         unsigned char   volume_name[28];
474         uint32_t        date_backedup;
475         uint16_t        backup_seqnum;
476         uint32_t        write_count;
477         uint32_t        extents_clump_size;
478         uint32_t        catalog_clump_size;
479         uint16_t        root_folder_count;
480         uint32_t        file_count;
481         uint32_t        folder_count;
482         uint32_t        finder_info[8];
483         uint16_t        embedded_signature;
484         hfs_hfs_extent_descriptor_t embedded_extent;
485         uint32_t        extents_size;
486         hfs_hfs_extent_record_t extents_extents;
487         uint32_t        catalog_size;
488         hfs_hfs_extent_record_t catalog_extents;
489 } hfs_hfs_master_directory_block_t;
490 
491 #if 0
492 #pragma mark -
493 #pragma mark Custom Types
494 #endif
495 
496 typedef struct
497 {
498 	hfs_volume_header_t	vh;		/* volume header */
499 	hfs_header_record_t	chr;	/* catalog file header node record*/
500 	hfs_header_record_t	ehr;	/* extent overflow file header node record*/
501 	uint8_t	catkeysizefieldsize;	/* size of catalog file key_len field in
502 									 * bytes (1 or 2); always 2 for HFS+ */
503 	uint8_t	extkeysizefieldsize;	/* size of extent file key_len field in
504 									 * bytes (1 or 2); always 2 for HFS+ */
505 	hfs_unistr255_t		name;	/* volume name */
506 
507 	/* pointer to catalog file key comparison function */
508 	int (*keycmp) (const void*, const void*);
509 
510 	int						journaled;	/* 1 if volume is journaled, else 0 */
511 	hfs_journal_info_t		jib;	/* journal info block */
512 	hfs_journal_header_t	jh;		/* journal header */
513 
514 	uint64_t offset;	/* offset, in bytes, of HFS+ volume */
515 	int		readonly;	/* 0 if mounted r/w, 1 if mounted r/o */
516 	void*	cbdata;		/* application-specific data; allocated, defined and
517 						 * used (if desired) by the program, usually within
518 						 * callback routines */
519 } hfs_volume;
520 
521 typedef union
522 {
523 	/* for leaf nodes */
524 	int16_t					type; /* type of record: folder, file, or thread */
525 	hfs_folder_record_t	folder;
526 	hfs_file_record_t		file;
527 	hfs_thread_record_t	thread;
528 
529 	/* for pointer nodes */
530 	/* (using this large union for just one tiny field is not memory-efficient,
531 	 *	 so change this if it becomes problematic) */
532 	uint32_t	child;	/* node number of this node's child node */
533 } hfs_catalog_keyed_record_t;
534 
535 /*
536  * These arguments are passed among libhfs without any inspection. This struct
537  * is accepted by all public functions of libhfs, and passed to each callback.
538  * An application dereferences each pointer to its own specific struct of
539  * arguments. Callbacks must be prepared to deal with NULL values for any of
540  * these fields (by providing default values to be used in lieu of that
541  * argument). However, a NULL pointer to this struct is an error.
542  *
543  * It was decided to make one unified argument structure, rather than many
544  * separate, operand-specific structures, because, when this structure is passed
545  * to a public function (e.g., hfslib_open_volume()), the function may make
546  * several calls (and subcalls) to various facilities, e.g., read(), malloc(),
547  * and free(), all of which require their own particular arguments. The
548  * facilities to be used are quite impractical to foreshadow, so the application
549  * takes care of all possible calls at once. This also reinforces the idea that
550  * a public call is an umbrella to a set of system calls, and all of these calls
551  * must be passed arguments which do not change within the context of this
552  * umbrella. (E.g., if a public function makes two calls to read(), one call
553  * should not be passed a uid of root and the other passed a uid of daemon.)
554  */
555 typedef struct
556 {
557 	/* The 'error' function does not take an argument. All others do. */
558 
559 	void*	allocmem;
560 	void*	reallocmem;
561 	void*	freemem;
562 	void*	openvol;
563 	void*	closevol;
564 	void*	read;
565 } hfs_callback_args;
566 
567 typedef struct
568 {
569 	/* error(in_format, in_file, in_line, in_args) */
570 	void (*error) (const char*, const char*, int, va_list);
571 
572 	/* allocmem(in_size, cbargs) */
573 	void* (*allocmem) (size_t, hfs_callback_args*);
574 
575 	/* reallocmem(in_ptr, in_size, cbargs) */
576 	void* (*reallocmem) (void*, size_t, hfs_callback_args*);
577 
578 	/* freemem(in_ptr, cbargs) */
579 	void (*freemem) (void*, hfs_callback_args*);
580 
581 	/* openvol(in_volume, in_devicepath, cbargs)
582 	 * returns 0 on success */
583 	int (*openvol) (hfs_volume*, const char*, hfs_callback_args*);
584 
585 	/* closevol(in_volume, cbargs) */
586 	void (*closevol) (hfs_volume*, hfs_callback_args*);
587 
588 	/* read(in_volume, out_buffer, in_length, in_offset, cbargs)
589 	 * returns 0 on success */
590 	int (*read) (hfs_volume*, void*, uint64_t, uint64_t,
591 		hfs_callback_args*);
592 
593 } hfs_callbacks;
594 
595 hfs_callbacks	hfs_gcb;	/* global callbacks */
596 
597 /*
598  * global case folding table
599  * (lazily initialized; see comments at bottom of hfs_open_volume())
600  */
601 unichar_t* hfs_gcft;
602 
603 #if 0
604 #pragma mark -
605 #pragma mark Functions
606 #endif
607 
608 void hfslib_init(hfs_callbacks*);
609 void hfslib_done(void);
610 void hfslib_init_cbargs(hfs_callback_args*);
611 
612 int hfslib_open_volume(const char*, int, hfs_volume*,
613 	hfs_callback_args*);
614 void hfslib_close_volume(hfs_volume*, hfs_callback_args*);
615 
616 int hfslib_path_to_cnid(hfs_volume*, hfs_cnid_t, char**, uint16_t*,
617 	hfs_callback_args*);
618 hfs_cnid_t hfslib_find_parent_thread(hfs_volume*, hfs_cnid_t,
619 	hfs_thread_record_t*, hfs_callback_args*);
620 int hfslib_find_catalog_record_with_cnid(hfs_volume*, hfs_cnid_t,
621 	hfs_catalog_keyed_record_t*, hfs_catalog_key_t*, hfs_callback_args*);
622 int hfslib_find_catalog_record_with_key(hfs_volume*, hfs_catalog_key_t*,
623 	hfs_catalog_keyed_record_t*, hfs_callback_args*);
624 int hfslib_find_extent_record_with_key(hfs_volume*, hfs_extent_key_t*,
625 	hfs_extent_record_t*, hfs_callback_args*);
626 int hfslib_get_directory_contents(hfs_volume*, hfs_cnid_t,
627 	hfs_catalog_keyed_record_t**, hfs_unistr255_t**, uint32_t*,
628 	hfs_callback_args*);
629 int hfslib_is_journal_clean(hfs_volume*);
630 int hfslib_is_private_file(hfs_catalog_key_t*);
631 
632 int hfslib_get_hardlink(hfs_volume *, uint32_t,
633 			 hfs_catalog_keyed_record_t *, hfs_callback_args *);
634 
635 size_t hfslib_read_volume_header(void*, hfs_volume_header_t*);
636 size_t hfslib_read_master_directory_block(void*,
637 	hfs_hfs_master_directory_block_t*);
638 size_t hfslib_reada_node(void*, hfs_node_descriptor_t*, void***, uint16_t**,
639 	hfs_btree_file_type, hfs_volume*, hfs_callback_args*);
640 size_t hfslib_reada_node_offsets(void*, uint16_t*);
641 size_t hfslib_read_header_node(void**, uint16_t*, uint16_t,
642 	hfs_header_record_t*, void*, void*);
643 size_t hfslib_read_catalog_keyed_record(void*, hfs_catalog_keyed_record_t*,
644 	int16_t*, hfs_catalog_key_t*, hfs_volume*);
645 size_t hfslib_read_extent_record(void*, hfs_extent_record_t*, hfs_node_kind,
646 	hfs_extent_key_t*, hfs_volume*);
647 void hfslib_free_recs(void***, uint16_t**, uint16_t*, hfs_callback_args*);
648 
649 size_t hfslib_read_fork_descriptor(void*, hfs_fork_t*);
650 size_t hfslib_read_extent_descriptors(void*, hfs_extent_record_t*);
651 size_t hfslib_read_unistr255(void*, hfs_unistr255_t*);
652 size_t hfslib_read_bsd_data(void*, hfs_bsd_data_t*);
653 size_t hfslib_read_file_userinfo(void*, hfs_macos_file_info_t*);
654 size_t hfslib_read_file_finderinfo(void*, hfs_macos_extended_file_info_t*);
655 size_t hfslib_read_folder_userinfo(void*, hfs_macos_folder_info_t*);
656 size_t hfslib_read_folder_finderinfo(void*, hfs_macos_extended_folder_info_t*);
657 size_t hfslib_read_journal_info(void*, hfs_journal_info_t*);
658 size_t hfslib_read_journal_header(void*, hfs_journal_header_t*);
659 
660 uint16_t hfslib_make_catalog_key(hfs_cnid_t, uint16_t, unichar_t*,
661 	hfs_catalog_key_t*);
662 uint16_t hfslib_make_extent_key(hfs_cnid_t, uint8_t, uint32_t,
663 	hfs_extent_key_t*);
664 uint16_t hfslib_get_file_extents(hfs_volume*, hfs_cnid_t, uint8_t,
665 	hfs_extent_descriptor_t**, hfs_callback_args*);
666 int hfslib_readd_with_extents(hfs_volume*, void*, uint64_t*, uint64_t,
667 	uint64_t, hfs_extent_descriptor_t*, uint16_t, hfs_callback_args*);
668 
669 int hfslib_compare_catalog_keys_cf(const void*, const void*);
670 int hfslib_compare_catalog_keys_bc(const void*, const void*);
671 int hfslib_compare_extent_keys(const void*, const void*);
672 
673 
674 /* callback wrappers */
675 void hfslib_error(const char*, const char*, int, ...) __attribute__ ((format (printf, 1, 4)));
676 void* hfslib_malloc(size_t, hfs_callback_args*);
677 void* hfslib_realloc(void*, size_t, hfs_callback_args*);
678 void hfslib_free(void*, hfs_callback_args*);
679 int hfslib_openvoldevice(hfs_volume*, const char*, hfs_callback_args*);
680 void hfslib_closevoldevice(hfs_volume*, hfs_callback_args*);
681 int hfslib_readd(hfs_volume*, void*, uint64_t, uint64_t, hfs_callback_args*);
682 
683 #endif /* !_FS_HFS_LIBHFS_H_ */
684