File: inventory.h

package info (click to toggle)
xfsdump 3.1.9%2B0
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 3,932 kB
  • sloc: ansic: 45,863; sh: 3,227; makefile: 545
file content (319 lines) | stat: -rw-r--r-- 9,892 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#ifndef INVENTORY_H
#define INVENTORY_H

#include "types.h"

/* abstract interface to the inventory sub system of xfsdump
 *
 * the inventory contains a description of every xfsdump ever
 * done, unless explicitly deleted. It provides simple and specific
 * storage and query facilities.
 *
 * This was not an attempt to write a generic database. The inventory does have
 * knowledge of the functionalities, some abstractions, and even typical queries
 * of dump() and restore() and uses this knowledge in formulating its storage
 * structure on disk. All these things, of course, are completely abstract with
 * respect to the clients of the inventory.
 *
 */

#define INV_DIRPATH		inv_dirpath()
#define INV_TOKEN_NULL 		NULL
#define INV_FSTAB		inv_fstab()
#define INV_INVINDEX_PREFIX     ".InvIndex"
#define INV_STOBJ_PREFIX        ".StObj"

/* length of labels, mntpts, etc */
#define INV_STRLEN              GLOBAL_HDR_STRING_SZ

typedef uint32_t		inv_version_t;

/* This is the general inventory version.
 */
#define INV_VERSION		(inv_version_t) 1

/* This is the version of the on-tape (packed) inventory.
 * version 2 has an extra inv_version_t in it to make everything
 * 64 bit aligned.
 */
#define PACKED_INV_VERSION_1	(inv_version_t) 1
#define PACKED_INV_VERSION_2	(inv_version_t) 2
#define PACKED_INV_VERSION	PACKED_INV_VERSION_2

/* Print [-I] suboption -depth */
#define PR_DEFAULT	0
#define PR_FSONLY 	1
#define PR_SESSONLY 	2
#define PR_STRMSONLY 	3
#define PR_ALL		4
#define PR_MAXDEPTH	5
#define PR_MAXLEVEL	255

/*----------------------------------------------------------------------*/
/* Inventory                                                            */
/*                                                                      */
/* Users are first supposed to call inventory_open() specifying what    */
/* type of handle s/he would like to supply. This can be BY_MOUNTPT,    */
/* BY_DEVPATH, or BY_UUID. The inventory maintains its own table of file*/
/* systems and their uuids, mountpts, and device paths.                 */
/* The current implementation requires that a uuid be present for all   */
/* its fs table entries. However, once the entry is there, caller can   */
/* query by any of the other handles.                                   */
/*                                                                      */
/* For a read-session, ie. just querying, like in restore(), the token  */
/* from inv_open() must always be passed.                               */
/*                                                                      */
/* This inventory has a hierarchical token scheme.                      */
/* For write-sessions, the caller should obtain a session_token         */
/* by calling inv_writesession_open() with the original token.  	*/
/* In order to start writing media files, the caller must    		*/
/* then obtain a stream-token via inv_stream_open() using that    	*/
/* session-token.                                                       */
/*                                                                      */
/* Once, done, stream_close(), writesession_close() and inv_close()     */
/* must be called in that order. To obtain all the data written during  */
/* the course of a single write-session, the user can call inv_get_     */
/* sessioninfo() while still holding the session-token. For inventory   */
/* reconstruction, inv_put_sessioninfo() may be used, and there is no   */
/* requirement to hold a token for that.                                */
/*                                                                      */
/* inv_delete_mediaobj() is, of course, for deletion of all the media   */
/* files contained in a media object.                                   */
/*                                                                      */
/*----------------------------------------------------------------------*/

/* Caller can open the inventory by any of these handles */
typedef enum {
	INV_BY_UUID,
	INV_BY_MOUNTPT,
	INV_BY_DEVPATH
} inv_predicate_t;


typedef enum {
	INV_SEARCH_ONLY,
	INV_SEARCH_N_MOD
} inv_oflag_t;


typedef struct inv_mediafile {
	uuid_t		 m_moid;	/* media object id */
	uint		 m_mfile_index; /* index within the media object */
	xfs_ino_t	 m_startino;	/* file that we started out with */
	off64_t		 m_startino_off;
	xfs_ino_t	 m_endino;	/* the dump file we ended this .. */
	off64_t		 m_endino_off;	/* .. media file with. */
	off64_t		 m_size;	/* size of mediafile in bytes */
	bool_t           m_isgood;      /* distinguishes good mfiles */
	bool_t		 m_isinvdump;	/* is this the mfile that has the dump
					   of the rest of the session? */
	char		 m_label[INV_STRLEN];	/* media file label */
} inv_mediafile_t;


typedef struct inv_stream {
	bool_t		st_interrupted;	/* was this stream interrupted ? */

	/* duplicate info from mediafiles for speed */
	xfs_ino_t	st_startino;	/* the starting pt */
	off64_t		st_startino_off;
	xfs_ino_t	st_endino;  	/* where we actually ended up. this
					   means we've written upto but not
					   including this breakpoint. */
	off64_t		st_endino_off;
	char            st_cmdarg[INV_STRLEN]; /* the driver path user entered */
	uint		st_nmediafiles; /* number of mediafiles */
	inv_mediafile_t *st_mediafiles; /* array of all media files */
} inv_stream_t;


/*
 * inventory_session_t
 * all the information that is kept on a single dump session of a single
 * file system in the inventory.
 *
 */

typedef struct inv_session {
	uuid_t		 s_fsid;	/* file system */
	uuid_t 		 s_sesid;	/* this session's id:16 bytes*/
	time32_t	 s_time;   	/* time of the dump */
	bool_t		 s_ispartial;	/* was this a partial (dump) ? */
	bool_t           s_isresumed;   /* was this a resumed (dump) ? */
	u_char		 s_level;  	/* dump level */
	char		 s_label[INV_STRLEN];  /* session label */
	char		 s_mountpt[INV_STRLEN];/* path to the mount point */
	char		 s_devpath[INV_STRLEN];/* path to the device */
	uint		 s_nstreams;	/* num of media streams recorded */
	inv_stream_t	*s_streams;	/* array of streams */
        uint            s_refnum;      /* storage location dependent ref.
					   used in displaying the session and
					   nowhere else */

} inv_session_t;



struct invt_desc_entry;
struct invt_sesdesc_entry;
struct invt_strdesc_entry;

/* The three kinds of access tokens for the inventory */
typedef struct invt_desc_entry		*inv_idbtoken_t;
typedef struct invt_sesdesc_entry	*inv_sestoken_t;
typedef struct invt_strdesc_entry	*inv_stmtoken_t;




/* inventory_open - initializes access to the inventory
 */
extern inv_idbtoken_t
inv_open(
	 inv_predicate_t bywhat, /* BY_UUID, BY_MOUNTPT, BY_DEVPATH */
	 inv_oflag_t      forwhat,/* SEARCH_ONLY, SEARCH_N_MOD */
	 void 		 *pred);/* uuid_t *, char * mntpt, or char *dev */


extern bool_t
inv_close(
	inv_idbtoken_t	tok);


extern inv_sestoken_t
inv_writesession_open(
	inv_idbtoken_t 	tok, 	/* token obtained by inventory_init() */
	uuid_t		*fsid,
	uuid_t		*sesid,
	char		*label,
	bool_t		ispartial,
        bool_t          isresumed,
	u_char		level,
	uint		nstreams,
	time32_t	time,
	char		*mntpt,
	char		*devpath);

extern bool_t
inv_writesession_close(
	inv_sestoken_t  tok);

extern inv_stmtoken_t
inv_stream_open(
	inv_sestoken_t 	tok,
	char		*cmdarg);

extern bool_t
inv_stream_close(
	inv_stmtoken_t	tok,
	bool_t 		wasinterrupted);

extern bool_t
inv_put_mediafile(
	inv_stmtoken_t 	tok,
	uuid_t 		*moid,
	char 		*label,
	uint		mfileindex,
	xfs_ino_t	startino,
	off64_t		startino_offset,
	xfs_ino_t	endino,
	off64_t		endino_offset,
	off64_t		size,	  /* size of the mediafile in bytes */
	bool_t          isgood,   /* to distinguish unimportant media
				     files from others */
	bool_t		isinv_dump);

/* lasttime_level_lessthan - finds the time of the last dump of the
 * specified file system at a level less than the specified level.
 * if never dumped below the current level, *time is set to NULL.
 *
 */
extern bool_t
inv_lasttime_level_lessthan(
	uuid_t			*fsidp,
	inv_idbtoken_t 		tok,
	u_char			level,
	time32_t		**time); /* out */

extern bool_t
inv_lastsession_level_lessthan(
	uuid_t			*fsidp,
	inv_idbtoken_t 		tok,
	u_char  		level,
	inv_session_t		**ses); /* out */

extern bool_t
inv_lastsession_level_equalto(
	uuid_t			*fsidp,
	inv_idbtoken_t 		tok,
	u_char  		level,
	inv_session_t		**ses); /* out */

/* Given a uuid of a session, return the session structure.*/
extern bool_t
inv_get_session_byuuid(
	uuid_t		*fsidp,
	uuid_t		*sesid,
	inv_session_t	**ses);

extern bool_t
inv_get_session_bylabel(
	uuid_t		*fsidp,
	char		*session_label,
	inv_session_t	**ses);


/* on return, *ses is NULL */
extern void
inv_free_session(
	inv_session_t **ses);


/* For dumping the inventory once a dump is done. */
extern bool_t
inv_get_sessioninfo(
	inv_sestoken_t		tok,
	void		      **bufpp,		/* out */
	size_t		       *bufszp);	/* out */


extern bool_t
inv_delete_mediaobj(uuid_t *moid);

extern bool_t
inv_DEBUG_print(int argc, char **argv);

extern int
inv_setup_base(void);

extern char *
inv_dirpath(void);

extern char *
inv_fstab(void);

extern char *
inv_lockfile(void);

extern char *
inv_basepath(void);


#endif /* INVENTORY_H */