]> git.saurik.com Git - apple/hfs.git/blob - CopyHFSMeta/Data.h
hfs-522.0.9.tar.gz
[apple/hfs.git] / CopyHFSMeta / Data.h
1 #ifndef _DATA_H
2 # define _DATA_H
3
4 # include <errno.h>
5 /*
6 * Exit status values. We use some errno values because
7 * they are convenient.
8 * kGoodExit: we finished copying, and no problems.
9 * kNoSpaceExit: Not enough space for the skeleton copy.
10 * kCopyIOExit: An I/O error occurred. This may not be fatal,
11 * as it may just mean the source device went away. We
12 * can continue later, perhaps.
13 * kIntrExit: The copying was interrupted. As above, this may
14 * not be fatal.
15 * kBadExit: Any other problem.
16 */
17 enum {
18 kGoodExit = 0,
19 kNoSpaceExit = ENOSPC,
20 kCopyIOExit = EIO,
21 kIntrExit = EINTR,
22 kBadExit = 1,
23 };
24
25 /*
26 * Data-manipulating functions and structures, used to
27 * create the skeleton copy.
28 */
29 struct DeviceInfo;
30 struct VolumeDescriptor;
31 struct IOWrapper;
32
33 /*
34 * We treat each data structure in the filesystem as
35 * a <start, length> pair.
36 */
37 struct Extents {
38 off_t base;
39 off_t length;
40 unsigned int fid; // Optional, may not be set
41 };
42 typedef struct Extents Extents_t;
43
44 #define kExtentCount 100
45
46 /*
47 * The in-core representation consists of a linked
48 * list of an array of extents, up to 100 in each element.
49 */
50 struct ExtentList {
51 size_t count;
52 Extents_t extents[kExtentCount];
53 struct ExtentList *next;
54 };
55 typedef struct ExtentList ExtentList_t;
56 /*
57 * The in-core description of the volume: an input source,
58 * a description of the volume, the linked list of extents,
59 * the total number of bytes, and the number of linked list
60 * elements.
61 */
62 struct VolumeObjects {
63 struct DeviceInfo *devp;
64 struct VolumeDescriptor *vdp;
65 size_t count;
66 off_t byteCount;
67 ExtentList_t *list;
68 };
69 typedef struct VolumeObjects VolumeObjects_t;
70
71 typedef int (^extent_handler_t)(int fid, off_t start, off_t len);
72
73 extern VolumeObjects_t *InitVolumeObject(struct DeviceInfo *devp, struct VolumeDescriptor *vdp);
74 extern int AddExtent(VolumeObjects_t *vop, off_t start, off_t length);
75 extern int AddExtentForFile(VolumeObjects_t *vop, off_t start, off_t length, unsigned int fid);
76 extern void PrintVolumeObject(VolumeObjects_t*);
77 extern int CopyObjectsToDest(VolumeObjects_t*, struct IOWrapper *wrapper, off_t skip);
78
79 extern void WriteGatheredData(const char *, VolumeObjects_t*);
80
81 extern struct DeviceInfo *OpenDevice(const char *, int);
82 extern struct VolumeDescriptor *VolumeInfo(struct DeviceInfo *);
83 extern int AddHeaders(VolumeObjects_t *, int);
84 extern void AddJournal(VolumeObjects_t *);
85 extern void AddFileExtents(VolumeObjects_t *);
86 extern int FindOtherMetadata(VolumeObjects_t *, extent_handler_t);
87 extern int CompareVolumeHeaders(struct VolumeDescriptor*);
88
89 void ReleaseDeviceInfo(struct DeviceInfo *);
90 void ReleaseVolumeDescriptor(struct VolumeDescriptor*);
91 void ReleaseVolumeObjects(VolumeObjects_t *);
92 #endif /* _DATA_H */