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 */
17enum {
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 */
29struct DeviceInfo;
30struct VolumeDescriptor;
31struct IOWrapper;
32
33/*
34 * We treat each data structure in the filesystem as
35 * a <start, length> pair.
36 */
37struct Extents {
38	off_t base;
39	off_t length;
40	unsigned int fid;	// Optional, may not be set
41};
42typedef 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 */
50struct ExtentList {
51	size_t count;
52	Extents_t extents[kExtentCount];
53	struct ExtentList *next;
54};
55typedef 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 */
62struct VolumeObjects {
63	struct DeviceInfo *devp;
64	struct VolumeDescriptor *vdp;
65	size_t count;
66	off_t byteCount;
67	ExtentList_t *list;
68};
69typedef struct VolumeObjects VolumeObjects_t;
70
71typedef int (^extent_handler_t)(int fid, off_t start, off_t len);
72
73extern VolumeObjects_t *InitVolumeObject(struct DeviceInfo *devp, struct VolumeDescriptor *vdp);
74extern int AddExtent(VolumeObjects_t *vop, off_t start, off_t length);
75extern int AddExtentForFile(VolumeObjects_t *vop, off_t start, off_t length, unsigned int fid);
76extern void PrintVolumeObject(VolumeObjects_t*);
77extern int CopyObjectsToDest(VolumeObjects_t*, struct IOWrapper *wrapper, off_t skip);
78
79extern void WriteGatheredData(const char *, VolumeObjects_t*);
80
81extern struct DeviceInfo *OpenDevice(const char *, int);
82extern struct VolumeDescriptor *VolumeInfo(struct DeviceInfo *);
83extern int AddHeaders(VolumeObjects_t *, int);
84extern void AddJournal(VolumeObjects_t *);
85extern void AddFileExtents(VolumeObjects_t *);
86extern int FindOtherMetadata(VolumeObjects_t *, extent_handler_t);
87extern int CompareVolumeHeaders(struct VolumeDescriptor*);
88
89void ReleaseDeviceInfo(struct DeviceInfo *);
90void ReleaseVolumeDescriptor(struct VolumeDescriptor*);
91void ReleaseVolumeObjects(VolumeObjects_t *);
92#endif /* _DATA_H */
93