xref: /freebsd/sbin/dump/dump.h (revision 5ebc7e6281887681c3a348a5a4c902e262ccd656)
1 /*-
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  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  *	@(#)dump.h	8.1 (Berkeley) 6/5/93
34  */
35 
36 #define MAXINOPB	(MAXBSIZE / sizeof(struct dinode))
37 #define MAXNINDIR	(MAXBSIZE / sizeof(daddr_t))
38 
39 /*
40  * Dump maps used to describe what is to be dumped.
41  */
42 int	mapsize;	/* size of the state maps */
43 char	*usedinomap;	/* map of allocated inodes */
44 char	*dumpdirmap;	/* map of directories to be dumped */
45 char	*dumpinomap;	/* map of files to be dumped */
46 /*
47  * Map manipulation macros.
48  */
49 #define	SETINO(ino, map) \
50 	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
51 #define	CLRINO(ino, map) \
52 	map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
53 #define	TSTINO(ino, map) \
54 	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
55 
56 /*
57  *	All calculations done in 0.1" units!
58  */
59 char	*disk;		/* name of the disk file */
60 char	*tape;		/* name of the tape file */
61 char	*dumpdates;	/* name of the file containing dump date information*/
62 char	*temp;		/* name of the file for doing rewrite of dumpdates */
63 char	lastlevel;	/* dump level of previous dump */
64 char	level;		/* dump level of this dump */
65 int	uflag;		/* update flag */
66 int	diskfd;		/* disk file descriptor */
67 int	tapefd;		/* tape file descriptor */
68 int	pipeout;	/* true => output to standard output */
69 ino_t	curino;		/* current inumber; used globally */
70 int	newtape;	/* new tape flag */
71 int	density;	/* density in 0.1" units */
72 long	tapesize;	/* estimated tape size, blocks */
73 long	tsize;		/* tape size in 0.1" units */
74 long	asize;		/* number of 0.1" units written on current tape */
75 int	etapes;		/* estimated number of tapes */
76 int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
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 struct	fs *sblock;	/* the file system super block */
83 char	sblock_buf[MAXBSIZE];
84 long	dev_bsize;	/* block size of underlying disk device */
85 int	dev_bshift;	/* log2(dev_bsize) */
86 int	tp_bshift;	/* log2(TP_BSIZE) */
87 
88 #ifndef __P
89 #include <sys/cdefs.h>
90 #endif
91 
92 /* operator interface functions */
93 void	broadcast __P((char *message));
94 void	lastdump __P((int arg));	/* int should be char */
95 void	msg __P((const char *fmt, ...));
96 void	msgtail __P((const char *fmt, ...));
97 int	query __P((char *question));
98 void	quit __P((const char *fmt, ...));
99 void	set_operators __P((void));
100 void	timeest __P((void));
101 time_t	unctime __P((char *str));
102 
103 /* mapping rouintes */
104 struct	dinode;
105 long	blockest __P((struct dinode *dp));
106 int	mapfiles __P((ino_t maxino, long *tapesize));
107 int	mapdirs __P((ino_t maxino, long *tapesize));
108 
109 /* file dumping routines */
110 void	blksout __P((daddr_t *blkp, int frags, ino_t ino));
111 void	bread __P((daddr_t blkno, char *buf, int size));
112 void	dumpino __P((struct dinode *dp, ino_t ino));
113 void	dumpmap __P((char *map, int type, ino_t ino));
114 void	writeheader __P((ino_t ino));
115 
116 /* tape writing routines */
117 int	alloctape __P((void));
118 void	close_rewind __P((void));
119 void	dumpblock __P((daddr_t blkno, int size));
120 void	startnewtape __P((int top));
121 void	trewind __P((void));
122 void	writerec __P((char *dp, int isspcl));
123 
124 __dead void Exit __P((int status));
125 void	dumpabort __P((int signo));
126 void	getfstab __P((void));
127 
128 char	*rawname __P((char *cp));
129 struct	dinode *getino __P((ino_t inum));
130 
131 /* rdump routines */
132 #ifdef RDUMP
133 void	rmtclose __P((void));
134 int	rmthost __P((char *host));
135 int	rmtopen __P((char *tape, int mode));
136 int	rmtwrite __P((char *buf, int count));
137 #endif /* RDUMP */
138 
139 void	interrupt __P((int signo));	/* in case operator bangs on console */
140 
141 /*
142  *	Exit status codes
143  */
144 #define	X_FINOK		0	/* normal exit */
145 #define	X_REWRITE	2	/* restart writing from the check point */
146 #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
147 
148 #define	OPGRENT	"operator"		/* group entry to notify */
149 #define DIALUP	"ttyd"			/* prefix for dialups */
150 
151 struct	fstab *fstabsearch __P((char *key));	/* search fs_file and fs_spec */
152 
153 #ifndef NAME_MAX
154 #define NAME_MAX 255
155 #endif
156 
157 /*
158  *	The contents of the file _PATH_DUMPDATES is maintained both on
159  *	a linked list, and then (eventually) arrayified.
160  */
161 struct dumpdates {
162 	char	dd_name[NAME_MAX+3];
163 	char	dd_level;
164 	time_t	dd_ddate;
165 };
166 struct dumptime {
167 	struct	dumpdates dt_value;
168 	struct	dumptime *dt_next;
169 };
170 struct	dumptime *dthead;	/* head of the list version */
171 int	nddates;		/* number of records (might be zero) */
172 int	ddates_in;		/* we have read the increment file */
173 struct	dumpdates **ddatev;	/* the arrayfied version */
174 void	initdumptimes __P((void));
175 void	getdumptime __P((void));
176 void	putdumptime __P((void));
177 #define	ITITERATE(i, ddp) \
178 	for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
179 
180 void	sig __P((int signo));
181 
182 /*
183  * Compatibility with old systems.
184  */
185 #ifdef COMPAT
186 #include <sys/file.h>
187 extern char *index(), *rindex(), *strdup();
188 extern char *ctime();
189 extern int read(), write();
190 extern int errno;
191 #endif
192 
193 #ifndef	_PATH_UTMP
194 #define	_PATH_UTMP	"/etc/utmp"
195 #endif
196 #ifndef	_PATH_FSTAB
197 #define	_PATH_FSTAB	"/etc/fstab"
198 #endif
199 
200 #ifdef sunos
201 extern char *calloc();
202 extern char *malloc();
203 extern long atol();
204 extern char *strcpy();
205 extern char *strncpy();
206 extern char *strcat();
207 extern time_t time();
208 extern void endgrent();
209 extern __dead void exit();
210 extern off_t lseek();
211 extern const char *strerror();
212 #endif
213