xref: /titanic_52/usr/src/cmd/backup/dump/dump.h (revision c7158ae983f5a04c4a998f468ecefba6d23ba721)
1 /*
2  * Copyright 1996, 1998, 2000, 2002-2003 Sun Microsystems, Inc.
3  * All rights reserved.
4  * Use is subject to license terms.
5  */
6 
7 /*
8  * Copyright (c) 1980 Regents of the University of California.
9  * All rights reserved. The Berkeley software License Agreement
10  * specifies the terms and conditions for redistribution.
11  */
12 
13 #ifndef _DUMP_H
14 #define	_DUMP_H
15 
16 #pragma ident	"%Z%%M%	%I%	%E% SMI"
17 
18 #include <stdio.h>
19 #include <locale.h>
20 #include <sys/types.h>
21 #include <ctype.h>
22 #include <string.h>
23 #include <syslog.h>
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <utmpx.h>
27 #include <signal.h>
28 #include <stdlib.h>
29 #include <time.h>
30 #include <sys/param.h>	/* for MAXBSIZE */
31 #include <sys/stat.h>
32 #include <sys/time.h>
33 #include <sys/wait.h>
34 #include <sys/vnode.h>	/* needed by inode.h */
35 #include <setjmp.h>
36 #include <sys/mman.h>
37 #include <assert.h>
38 #include <dumpusg.h>
39 #include <kstat.h>
40 #include <sys/fssnap_if.h>
41 #include <libgen.h>
42 #include <limits.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 #define	SUPPORTS_MTB_TAPE_FORMAT
49 #include <protocols/dumprestore.h>
50 #include <memutils.h>
51 #include <note.h>
52 
53 #define	NI		16
54 #define	MAXINOPB	(MAXBSIZE / sizeof (struct dinode))
55 #define	MAXNINDIR	(MAXBSIZE / sizeof (daddr32_t))
56 
57 #ifndef roundup
58 #define	roundup(x, y)	((((x)+((y)-1))/(y))*(y))
59 #endif
60 #ifndef MIN
61 #define	MIN(a, b)	(((a) < (b)) ? (a) : (b))
62 #endif
63 #ifndef MAX
64 #define	MAX(a, b)	(((a) > (b)) ? (a) : (b))
65 #endif
66 
67 /*
68  * Define an overflow-free version of howmany so that we don't
69  * run into trouble with large files.
70  */
71 #define	d_howmany(x, y)	((x) / (y) + ((x) % (y) != 0))
72 
73 #define	MWORD(m, i)	(m[(ino_t)(i-1)/NBBY])
74 #define	MBIT(i)		((1<<((ino_t)(i-1)%NBBY))&0xff)
75 #define	BIS(i, w)	(MWORD(w, i) |= MBIT(i))
76 #define	BIC(i, w)	(MWORD(w, i) &= ~MBIT(i))
77 #define	BIT(i, w)	(MWORD(w, i) & MBIT(i))
78 
79 uint_t	msiz;
80 uchar_t	*clrmap;
81 uchar_t	*dirmap;
82 uchar_t	*filmap;
83 uchar_t	*nodmap;
84 uchar_t	*shamap;
85 uchar_t	*activemap;
86 
87 /*
88  *	All calculations done in 0.1" units!
89  */
90 
91 char	*disk;		/* name of the disk file */
92 char	*dname;		/* name to put in /etc/dumpdates */
93 int	disk_dynamic;	/* true if disk refers to dynamic storage */
94 char	*tape;		/* name of the tape file */
95 char	*host;		/* name of the remote tape host (may be "user@host") */
96 char	*dumpdev;	/* hostname:device for current volume */
97 char	*sdumpdev;	/* short form of dumpdev (no user name if remote) */
98 char	*increm;	/* name of file containing incremental information */
99 char	*filesystem;	/* name of the file system */
100 char	*myname;	/* argv[0] without leading path components */
101 char	lastincno;	/* increment number of previous dump */
102 char	incno;		/* increment number */
103 char	*tlabel;	/* what goes in tape header c_label field */
104 int	uflag;		/* update flag */
105 int	fi;		/* disk file descriptor */
106 int	to;		/* tape file descriptor */
107 int	mapfd;		/* block disk device descriptor for mmap */
108 int	pipeout;	/* true => output to standard output */
109 int	tapeout;	/* true => output to a tape drive */
110 ino_t	ino;		/* current inumber; used globally */
111 off_t	pos;		/* starting offset within ino; used globally */
112 int	leftover;	/* number of tape recs left over from prev vol */
113 int	nsubdir;	/* counts subdirs, for deciding to dump a dir */
114 int	newtape;	/* new tape flag */
115 int	nadded;		/* number of added sub directories */
116 int	dadded;		/* directory added flag */
117 int	density;	/* density in 0.1" units */
118 ulong_t	tsize;		/* tape size in 0.1" units */
119 u_offset_t esize;	/* estimated tape size, blocks */
120 u_offset_t o_esize;	/* number of header blocks (overhead) */
121 u_offset_t f_esize;	/* number of TP_BSIZE blocks for files/maps */
122 uint_t	etapes;		/* estimated number of tapes */
123 uint_t	ntrec;		/* 1K records per tape block */
124 int	tenthsperirg;	/* 1/10" per tape inter-record gap */
125 dev_t 	partial_dev;	/* id of BLOCK device used in partial mode */
126 pid_t	dumppid;	/* process-ID of top-level process */
127 
128 int	verify;		/* verify each volume */
129 int	doingverify;	/* true => doing a verify pass */
130 int	active;		/* recopy active files */
131 int	doingactive;	/* true => redumping active files */
132 int	archive;	/* true => saving a archive in archivefile */
133 char	*archivefile;	/* name of archivefile */
134 int	notify;		/* notify operator flag */
135 int	diskette;	/* true if dumping to a diskette */
136 int	cartridge;	/* true if dumping to a cartridge tape */
137 uint_t	tracks;		/* number of tracks on a cartridge tape */
138 int	printsize;	/* just print estimated size and exit */
139 int	offline;	/* take tape offline after rewinding */
140 int	autoload;	/* wait for next tape to autoload; implies offline */
141 int	autoload_tries;	/* number of times to check on autoload */
142 int	autoload_period; /* seconds, tries*period = total wait time */
143 int	doposition;	/* move to specified... */
144 daddr32_t filenum;	/* position of dump on 1st volume */
145 int	dumpstate;	/* dump output state (see below) */
146 int	dumptoarchive;	/* mark records to be archived */
147 
148 int	blockswritten;	/* number of blocks written on current tape */
149 uint_t	tapeno;		/* current tape number */
150 
151 struct fs *sblock;	/* the file system super block */
152 int	shortmeta;	/* current file has small amount of metadata */
153 union u_shadow c_shadow_save[1];
154 
155 time_t	*telapsed;	/* time spent writing previous tapes */
156 time_t	*tstart_writing; /* when we started writing the latest tape */
157 time_t	*tschedule;	/* when next to give a remaining-time estimate */
158 
159 char	*debug_chdir;	/* non-NULL means to mkdir this/pid, and chdir there, */
160 			/* once for each separate child */
161 
162 /*
163  * Defines for the msec part of
164  * inode-based times, since we're
165  * not part of the kernel.
166  */
167 #define	di_atspare	di_ic.ic_atspare
168 #define	di_mtspare	di_ic.ic_mtspare
169 #define	di_ctspare	di_ic.ic_ctspare
170 
171 #define	HOUR	(60L*60L)
172 #define	DAY	(24L*HOUR)
173 #define	YEAR	(365L*DAY)
174 
175 /*
176  *	Dump output states
177  */
178 #define	DS_INIT		0
179 #define	DS_START	1
180 #define	DS_CLRI		2
181 #define	DS_BITS		3
182 #define	DS_DIRS		4
183 #define	DS_FILES	5
184 #define	DS_END		6
185 #define	DS_DONE		7
186 
187 /*
188  *	Exit status codes
189  */
190 #define	X_FINOK		0	/* normal exit */
191 #define	X_REWRITE	2	/* restart writing from the check point */
192 #define	X_ABORT		3	/* abort all of dump; no checkpoint restart */
193 #define	X_VERIFY	4	/* verify the reel just written */
194 #define	X_RESTART	5	/* abort all progress so far; attempt restart */
195 
196 #define	NINCREM	"/etc/dumpdates"	/* new format incremental info */
197 
198 #define	TAPE	"/dev/rmt/0b"		/* default tape device */
199 #define	OPGRENT	"sys"			/* group entry to notify */
200 #define	DIALUP	"ttyd"			/* prefix for dialups */
201 
202 #define	DISKETTE	"/dev/rfd0c"
203 
204 #define	NBUF		64		/* number of output buffers */
205 #define	MAXNTREC	256		/* max tape blocking factor (in Kb) */
206 
207 /*
208  *	The contents of the file NINCREM are maintained both on
209  *	a linked list and then (eventually) arrayified.
210  */
211 struct	idates {
212 	char	id_name[MAXNAMLEN+3];
213 	char	id_incno;
214 	time32_t id_ddate;
215 };
216 
217 size_t	nidates;		/* number of records (might be zero) */
218 struct	idates	**idatev;	/* the arrayfied version */
219 #define	ITITERATE(i, ip)	\
220 	for (i = 0; i < nidates && (ip = idatev[i]) != NULL; i++)
221 
222 /*
223  * Function declarations
224  */
225 #ifdef __STDC__
226 /*
227  * dumpfstab.c
228  */
229 extern void mnttabread(void);
230 extern struct mntent *mnttabsearch(char *, int);
231 extern void setmnttab(void);
232 extern struct mntent *getmnttab(void);
233 /*
234  * dumpitime.c
235  */
236 extern char *prdate(time_t);
237 extern void inititimes(void);
238 extern void getitime(void);
239 extern void putitime(void);
240 extern void est(struct dinode *);
241 extern time32_t is_fssnap_dump(char *);
242 extern void bmapest(uchar_t *);
243 /*
244  * dumplabel.c
245  */
246 extern void getlabel(void);
247 /*
248  * dumpmain.c
249  */
250 extern void child_chdir(void);
251 extern char *unrawname(char *);
252 extern void sigAbort(int);
253 extern char *rawname(char *);
254 extern char *lf_rawname(char *);
255 extern time32_t timeclock(time32_t);
256 #ifdef signal
257 extern void (*nsignal(int, void (*)(int)))(int);
258 #endif
259 extern int safe_file_open(const char *file, int mode, int perms);
260 extern int safe_device_open(const char *file, int mode, int perms);
261 extern FILE *safe_fopen(const char *filename, const char *smode, int perms);
262 /*
263  * dumponline.c
264  */
265 extern void allocino(void);
266 extern void freeino(void);
267 extern void saveino(ino_t, struct dinode *);
268 extern void resetino(ino_t);
269 extern long getigen(ino_t);
270 extern int lf_ismounted(char *, char *);
271 extern int isoperator(uid_t, gid_t);
272 extern int lockfs(char *, char *);
273 extern int openi(ino_t, long, char *);
274 extern caddr_t mapfile(int, off_t, off_t, int);
275 extern void unmapfile(void);
276 extern void stattoi(struct stat *, struct dinode *);
277 extern void dumpfile(int, caddr_t, off_t, off_t, off_t, int, int);
278 extern void activepass(void);
279 /*
280  * dumpoptr.c
281  */
282 extern int query(char *);
283 extern int query_once(char *, int);
284 extern void interrupt(int);
285 extern void broadcast(char *);
286 extern void timeest(int, int);
287 /*PRINTFLIKE1*/
288 extern void msg(const char *, ...);
289 /*PRINTFLIKE1*/
290 extern void msgtail(const char *, ...);
291 extern void lastdump(int);
292 extern char *getresponse(char *, char *);
293 /*
294  * dumptape.c
295  */
296 extern void alloctape(void);
297 extern void reset(void);
298 extern void spclrec(void);
299 extern void taprec(uchar_t *, int, int);
300 extern void dmpblk(daddr32_t, size_t, off_t);
301 extern void toslave(void (*)(ino_t), ino_t);
302 extern void doinode(ino_t);
303 extern void dospcl(ino_t);
304 extern void flushcmds(void);
305 extern void flusht(void);
306 extern void nextdevice(void);
307 extern int isrewind(int);
308 extern void trewind(void);
309 extern void close_rewind(void);
310 extern void changevol(void);
311 extern void otape(int);
312 extern void dumpabort(void);
313 extern void dumpailing(void);
314 extern void Exit(int);
315 extern void positiontape(char *);
316 /*
317  * dumptraverse.c
318  */
319 extern void pass(void (*)(struct dinode *), uchar_t *);
320 extern void mark(struct dinode *);
321 extern void active_mark(struct dinode *);
322 extern void markshad(struct dinode *);
323 extern void estshad(struct dinode *);
324 extern void freeshad();
325 extern void add(struct dinode *);
326 extern void dirdump(struct dinode *);
327 extern void dump(struct dinode *);
328 extern void lf_dump(struct dinode *);
329 extern void dumpblocks(ino_t);
330 extern void bitmap(uchar_t *, int);
331 extern struct dinode *getino(ino_t);
332 extern void bread(diskaddr_t, uchar_t *, size_t);
333 extern int hasshortmeta(struct dinode **ip);
334 /*
335  * lftw.c
336  */
337 extern int lftw(const char *,
338 	int (*)(const char *, const struct stat *, int), int);
339 extern int lf_lftw(const char *,
340 	int (*)(const char *, const struct stat64 *, int), int);
341 /*
342  * partial.c
343  */
344 extern void partial_check(void);
345 extern void lf_partial_check(void);
346 extern int partial_mark(int, char **);
347 /*
348  * unctime.c
349  */
350 extern time_t unctime(char *);
351 #else	/* !STDC */
352 /*
353  * dumpfstab.c
354  */
355 extern void mnttabread();
356 extern struct mntent *mnttabsearch();
357 extern void setmnttab();
358 extern struct mntent *getmnttab();
359 /*
360  * dumpitime.c
361  */
362 extern char *prdate();
363 extern void inititimes();
364 extern void getitime();
365 extern void putitime();
366 extern void est();
367 extern time32_t is_fssnap_dump();
368 extern void bmapest();
369 /*
370  * dumplabel.c
371  */
372 extern void getlabel();
373 /*
374  * dumpmain.c
375  */
376 extern void child_chdir();
377 extern char *unrawname();
378 extern void sigAbort();
379 extern char *rawname();
380 extern char *lf_rawname();
381 extern time_t timeclock();
382 #ifdef signal
383 extern void nsignal();
384 #endif
385 extern int safe_file_open();
386 extern int safe_device_open();
387 extern FILE *safe_fopen();
388 /*
389  * dumponline.c
390  */
391 extern void allocino();
392 extern void freeino();
393 extern void saveino();
394 extern void resetino();
395 extern long getigen();
396 extern int lf_ismounted();
397 extern int isoperator();
398 extern ulong_t lockfs();
399 extern int openi();
400 extern caddr_t mapfile();
401 extern void unmapfile();
402 extern void stattoi();
403 extern void dumpfile();
404 extern void activepass();
405 /*
406  * dumpoptr.c
407  */
408 extern int query();
409 extern int query_once();
410 extern void interrupt();
411 extern void broadcast();
412 extern void timeest();
413 extern void msg();
414 extern void msgtail();
415 extern void lastdump();
416 extern char *getresponse();
417 /*
418  * dumptape.c
419  */
420 extern void alloctape();
421 extern void reset();
422 extern void spclrec();
423 extern void taprec();
424 extern void dmpblk();
425 extern void toslave();
426 extern void doinode();
427 extern void dospcl();
428 extern void flushcmds();
429 extern void flusht();
430 extern void nextdevice();
431 extern int isrewind();
432 extern void trewind();
433 extern void close_rewind();
434 extern void changevol();
435 extern void otape();
436 extern void dumpabort();
437 extern void dumpailing();
438 extern void Exit();
439 extern void positiontape();
440 /*
441  * dumptraverse.c
442  */
443 extern void pass();
444 extern void mark();
445 extern void active_mark();
446 extern void markshad();
447 extern void estshad();
448 extern void freeshad();
449 extern void add();
450 extern void dirdump();
451 extern void dump();
452 extern void lf_dump();
453 extern void dumpblocks();
454 extern void bitmap();
455 extern struct dinode *getino();
456 extern void bread();
457 extern int hasshortmeta();
458 /*
459  * lftw.c
460  */
461 extern int lftw();
462 extern int lf_lftw();
463 /*
464  * partial.c
465  */
466 extern void partial_check();
467 extern void lf_partial_check();
468 extern int partial_mark();
469 /*
470  * unctime.c
471  */
472 extern time_t unctime();
473 #endif /* __STDC__ */
474 
475 /* Insufficiently-featureful system header files... */
476 NOTE(ALIGNMENT(mmap, 8))
477 
478 
479 #ifdef	__cplusplus
480 }
481 #endif
482 
483 #endif /* _DUMP_H */
484