1#ifndef _HFS_META_H
2# define _HFS_META_H
3
4# include <libkern/OSByteOrder.h>
5# include <hfs/hfs_format.h>
6
7# include "Data.h"
8
9/*
10 * The in-core description of the volume.  We care about
11 * the primary and alternate header locations, the alternate
12 * and primary journal offset locations, the size of the device,
13 * the two headers, and the two journal info blocks.
14 */
15struct VolumeDescriptor {
16	off_t priOffset;	// Offset of primary volume header
17	off_t altOffset;	// Offset of alternate volume header
18	off_t priJInfoOffset;	// Offset of journal info block from primary header
19	off_t altJInfoOffset;	// and for the alt.  May be the same as the above.
20	off_t deviceSize;	// The size of the entire device
21	JournalInfoBlock	priJournal;	// Primary journal block
22	JournalInfoBlock	altJournal;	// Alternate journal, if different
23	HFSPlusVolumeHeader priHeader;	// The primary header
24	HFSPlusVolumeHeader altHeader;	// And the alternate
25};
26typedef struct VolumeDescriptor VolumeDescriptor_t;
27
28/*
29 * The input device description.
30 */
31struct DeviceInfo {
32	char *devname;
33	int fd;
34	off_t size;
35	int blockSize;
36	off_t blockCount;
37};
38typedef struct DeviceInfo DeviceInfo_t;
39
40# define S16(x)	OSSwapBigToHostInt16(x)
41# define S32(x)	OSSwapBigToHostInt32(x)
42# define S64(x)	OSSwapBigToHostInt64(x)
43
44ssize_t GetBlock(DeviceInfo_t*, off_t, uint8_t*);
45int ScanExtents(VolumeObjects_t *, int);
46
47/*
48 * The IOWrapper structure is used to do input and output on
49 * the target -- which may be a device node, or a sparse bundle.
50 * writer() is used to copy a particular amount of data from the source device;
51 * reader() is used to get some data from the destination device (e.g., the header);
52 * getprog() is used to find what the stored progress was (if any);
53 * setprog() is used to write out the progress status so far.
54 * cleanup() is called when the copy is done.
55 */
56struct IOWrapper {
57	ssize_t (*writer)(struct IOWrapper *ctx,DeviceInfo_t *devp, off_t start, off_t len, void (^bp)(off_t));
58	ssize_t (*reader)(struct IOWrapper *ctx, off_t start, void *buffer, off_t len);
59	off_t (*getprog)(struct IOWrapper *ctx);
60	void (*setprog)(struct IOWrapper *ctx, off_t prog);
61	int (*cleanup)(struct IOWrapper *ctx);
62	void *context;
63};
64typedef struct IOWrapper IOWrapper_t;
65
66extern ssize_t UnalignedRead(DeviceInfo_t *, void *, size_t, off_t);
67
68extern int debug, verbose, printProgress;
69
70#endif /* _HFS_META_H */
71