xref: /dragonfly/sbin/dump/dump.h (revision 5e83d98b)
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. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	@(#)dump.h	8.2 (Berkeley) 4/28/95
30  *
31  * $FreeBSD: src/sbin/dump/dump.h,v 1.7.6.4 2003/01/25 18:54:59 dillon Exp $
32  */
33 
34 #include <sys/param.h>
35 
36 #define MAXINOPB	(MAXBSIZE / sizeof(struct ufs1_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)	setbit(map, (u_int)((ino) - 1))
50 #define	CLRINO(ino, map)	clrbit(map, (u_int)((ino) - 1))
51 #define	TSTINO(ino, map)	isset(map, (u_int)((ino) - 1))
52 
53 /*
54  *	All calculations done in 0.1" units!
55  */
56 char	*disk;		/* name of the disk file */
57 const char	*tape;		/* name of the tape file */
58 extern const char *dumpdates;	/* name of the file containing dump date information*/
59 extern const char *temp;		/* name of the file for doing rewrite of dumpdates */
60 char	lastlevel;	/* dump level of previous dump */
61 char	level;		/* dump level of this dump */
62 int	uflag;		/* update flag */
63 int	diskfd;		/* disk file descriptor */
64 int	tapefd;		/* tape file descriptor */
65 int	pipeout;	/* true => output to standard output */
66 ufs1_ino_t curino;	/* current inumber; used globally */
67 int	newtape;	/* new tape flag */
68 long	tapesize;	/* estimated tape size, blocks */
69 long	tsize;		/* tape size in 0.1" units */
70 long	asize;		/* number of 0.1" units written on current tape */
71 int	etapes;		/* estimated number of tapes */
72 int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
73 int	unlimited;	/* if set, write to end of medium */
74 
75 extern int	cachesize;	/* size of block cache */
76 extern int	density;	/* density in 0.1" units */
77 extern int	dokerberos;
78 #ifdef NTREC_LONG
79 extern long	ntrec;		/* used by sbin/restore */
80 #else
81 extern int	ntrec;		/* blocking factor on tape */
82 #endif
83 extern int	cartridge;
84 extern const char *host;
85 extern long	blocksperfile;	/* number of blocks per output file */
86 extern int	notify;		/* notify operator flag */
87 extern int	blockswritten;	/* number of blocks written on current tape */
88 extern long	dev_bsize;	/* block size of underlying disk device */
89 
90 time_t	tstart_writing;	/* when started writing the first tape block */
91 time_t	tend_writing;	/* after writing the last tape block */
92 int	passno;		/* current dump pass number */
93 struct	fs *sblock;	/* the file system super block */
94 char	sblock_buf[MAXBSIZE];
95 int	dev_bshift;	/* log2(dev_bsize) */
96 int	tp_bshift;	/* log2(TP_BSIZE) */
97 
98 /* operator interface functions */
99 void	broadcast(const char *);
100 void	infosch(int);
101 void	lastdump(int);		/* int should be char */
102 void	msg(const char *, ...) __printflike(1, 2);
103 void	msgtail(const char *, ...) __printflike(1, 2);
104 int	query(const char *);
105 void	quit(const char *, ...) __dead2 __printflike(1, 2);
106 void	timeest(void);
107 time_t	unctime(const char *);
108 
109 /* mapping rouintes */
110 struct	ufs1_dinode;
111 long	blockest(struct ufs1_dinode *);
112 int	mapfiles(ufs1_ino_t maxino, long *);
113 int	mapdirs(ufs1_ino_t maxino, long *);
114 
115 /* file dumping routines */
116 void	blksout(daddr_t *, int, ufs1_ino_t);
117 void	bread(daddr_t, char *, int);
118 ssize_t cread(int, void *, size_t, off_t);
119 void	dumpino(struct ufs1_dinode *, ufs1_ino_t);
120 void	dumpmap(const char *, int, ufs1_ino_t);
121 void	writeheader(ufs1_ino_t);
122 
123 /* tape writing routines */
124 int	alloctape(void);
125 void	close_rewind(void);
126 void	dumpblock(daddr_t, int);
127 void	startnewtape(int);
128 void	trewind(void);
129 void	writerec(const void *, int);
130 
131 void	Exit(int) __dead2;
132 void	dumpabort(int) __dead2;
133 void	dump_getfstab(void);
134 
135 char	*rawname(char *);
136 struct	ufs1_dinode *getino(ufs1_ino_t);
137 
138 /* rdump routines */
139 #if defined(RDUMP) || defined(RRESTORE)
140 void	rmtclose(void);
141 int	rmthost(const char *);
142 int	rmtopen(const char *, int);
143 int	rmtwrite(const void *, int);
144 #endif /* RDUMP || RRESTORE */
145 
146 /* rrestore routines */
147 #ifdef RRESTORE
148 int	rmtread(char *, int);
149 int	rmtseek(int, int);
150 int	rmtioctl(int, int);
151 #endif /* RRESTORE */
152 
153 void	interrupt(int);		/* in case operator bangs on console */
154 
155 /*
156  *	Exit status codes
157  */
158 #define	X_FINOK		0	/* normal exit */
159 #define	X_STARTUP	1	/* startup error */
160 #define	X_REWRITE	2	/* restart writing from the check point */
161 #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
162 
163 #define	OPGRENT	"operator"		/* group entry to notify */
164 
165 struct	fstab *fstabsearch(const char *);	/* search fs_file and fs_spec */
166 
167 #ifndef NAME_MAX
168 #define NAME_MAX 255
169 #endif
170 
171 /*
172  *	The contents of the file _PATH_DUMPDATES is maintained both on
173  *	a linked list, and then (eventually) arrayified.
174  */
175 struct dumpdates {
176 	char	dd_name[NAME_MAX+3];
177 	char	dd_level;
178 	time_t	dd_ddate;
179 };
180 extern int	nddates;		/* number of records (might be zero) */
181 extern struct	dumpdates **ddatev;	/* the arrayfied version */
182 void	initdumptimes(void);
183 void	getdumptime(void);
184 void	putdumptime(void);
185 #define	ITITERATE(i, ddp) 	\
186 	if (ddatev != NULL)	\
187 		for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
188 
189 void	sig(int);
190