xref: /netbsd-src/sbin/dump/dump.h (revision 5f7096188587a2c7c95fa3c69b78e1ec9c7923d0)
1 /*-
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	from: @(#)dump.h	5.16 (Berkeley) 5/29/91
34  *	$Id: dump.h,v 1.4 1993/08/01 18:27:52 mycroft Exp $
35  */
36 
37 #define MAXINOPB	(MAXBSIZE / sizeof(struct dinode))
38 #define MAXNINDIR	(MAXBSIZE / sizeof(daddr_t))
39 
40 /*
41  * Dump maps used to describe what is to be dumped.
42  */
43 int	mapsize;	/* size of the state maps */
44 char	*usedinomap;	/* map of allocated inodes */
45 char	*dumpdirmap;	/* map of directories to be dumped */
46 char	*dumpinomap;	/* map of files to be dumped */
47 /*
48  * Map manipulation macros.
49  */
50 #define	SETINO(ino, map) \
51 	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
52 #define	CLRINO(ino, map) \
53 	map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
54 #define	TSTINO(ino, map) \
55 	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
56 
57 /*
58  *	All calculations done in 0.1" units!
59  */
60 char	*disk;		/* name of the disk file */
61 char	*tape;		/* name of the tape file */
62 char	*dumpdates;	/* name of the file containing dump date information*/
63 char	*temp;		/* name of the file for doing rewrite of dumpdates */
64 char	lastlevel;	/* dump level of previous dump */
65 char	level;		/* dump level of this dump */
66 int	uflag;		/* update flag */
67 int	diskfd;		/* disk file descriptor */
68 int	tapefd;		/* tape file descriptor */
69 int	pipeout;	/* true => output to standard output */
70 ino_t	curino;		/* current inumber; used globally */
71 int	newtape;	/* new tape flag */
72 int	density;	/* density in 0.1" units */
73 long	tapesize;	/* estimated tape size, blocks */
74 long	tsize;		/* tape size in 0.1" units */
75 long	asize;		/* number of 0.1" units written on current tape */
76 int	etapes;		/* estimated number of tapes */
77 
78 int	notify;		/* notify operator flag */
79 int	blockswritten;	/* number of blocks written on current tape */
80 int	tapeno;		/* current tape number */
81 time_t	tstart_writing;	/* when started writing the first tape block */
82 char	*processname;
83 struct	fs *sblock;	/* the file system super block */
84 char	buf[MAXBSIZE];
85 long	dev_bsize;	/* block size of underlying disk device */
86 int	dev_bshift;	/* log2(dev_bsize) */
87 int	tp_bshift;	/* log2(TP_BSIZE) */
88 
89 /* operator interface functions */
90 void	broadcast();
91 void	lastdump();
92 void	msg();
93 void	msgtail();
94 int	query();
95 void	set_operators();
96 void	timeest();
97 
98 /* mapping rouintes */
99 long	blockest();
100 int	mapfiles();
101 int	mapdirs();
102 
103 /* file dumping routines */
104 void	dirdump();
105 void	blksout();
106 void	dumpmap();
107 void	writeheader();
108 void	bread();
109 
110 /* tape writing routines */
111 int	alloctape();
112 void	writerec();
113 void	dumpblock();
114 void	flushtape();
115 void	trewind();
116 void	close_rewind();
117 void	startnewtape();
118 
119 void	dumpabort();
120 void	Exit();
121 void	getfstab();
122 void	quit();
123 
124 char	*rawname();
125 struct dinode *getino();
126 
127 void	interrupt();		/* in case operator bangs on console */
128 
129 /*
130  *	Exit status codes
131  */
132 #define	X_FINOK		0	/* normal exit */
133 #define	X_REWRITE	2	/* restart writing from the check point */
134 #define	X_ABORT		3	/* abort all of dump; don't attempt checkpointing*/
135 
136 #define	OPGRENT	"operator"		/* group entry to notify */
137 #define DIALUP	"ttyd"			/* prefix for dialups */
138 
139 struct	fstab	*fstabsearch();	/* search in fs_file and fs_spec */
140 
141 /*
142  *	The contents of the file _PATH_DUMPDATES is maintained both on
143  *	a linked list, and then (eventually) arrayified.
144  */
145 struct dumpdates {
146 	char	dd_name[MAXNAMLEN+3];
147 	char	dd_level;
148 	time_t	dd_ddate;
149 };
150 struct dumptime {
151 	struct	dumpdates dt_value;
152 	struct	dumptime *dt_next;
153 };
154 struct	dumptime *dthead;	/* head of the list version */
155 int	nddates;		/* number of records (might be zero) */
156 int	ddates_in;		/* we have read the increment file */
157 struct	dumpdates **ddatev;	/* the arrayfied version */
158 void	initdumptimes();
159 void	getdumptime();
160 void	putdumptime();
161 #define	ITITERATE(i, ddp) \
162 	for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
163 
164 /*
165  *	We catch these interrupts
166  */
167 void	sighup();
168 void	sigquit();
169 void	sigill();
170 void	sigtrap();
171 void	sigfpe();
172 void	sigkill();
173 void	sigbus();
174 void	sigsegv();
175 void	sigsys();
176 void	sigalrm();
177 void	sigterm();
178 
179 /*
180  * Compatibility with old systems.
181  */
182 #ifndef __STDC__
183 #include <sys/file.h>
184 #define _PATH_FSTAB	"/etc/fstab"
185 extern char *index(), *strdup();
186 extern char *ctime();
187 extern int errno;
188 #endif
189