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