xref: /dragonfly/sbin/dump/dump.h (revision 9bb2a92d)
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.2 (Berkeley) 4/28/95
34  *
35  * $FreeBSD: src/sbin/dump/dump.h,v 1.7.6.4 2003/01/25 18:54:59 dillon Exp $
36  * $DragonFly: src/sbin/dump/dump.h,v 1.5 2004/02/04 17:39:59 joerg Exp $
37  */
38 
39 #define MAXINOPB	(MAXBSIZE / sizeof(struct dinode))
40 #define MAXNINDIR	(MAXBSIZE / sizeof(daddr_t))
41 
42 /*
43  * Dump maps used to describe what is to be dumped.
44  */
45 int	mapsize;	/* size of the state maps */
46 char	*usedinomap;	/* map of allocated inodes */
47 char	*dumpdirmap;	/* map of directories to be dumped */
48 char	*dumpinomap;	/* map of files to be dumped */
49 /*
50  * Map manipulation macros.
51  */
52 #define	SETINO(ino, map) \
53 	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
54 #define	CLRINO(ino, map) \
55 	map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
56 #define	TSTINO(ino, map) \
57 	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
58 
59 /*
60  *	All calculations done in 0.1" units!
61  */
62 char	*disk;		/* name of the disk file */
63 char	*tape;		/* name of the tape file */
64 char	*dumpdates;	/* name of the file containing dump date information*/
65 char	*temp;		/* name of the file for doing rewrite of dumpdates */
66 char	lastlevel;	/* dump level of previous dump */
67 char	level;		/* dump level of this dump */
68 int	uflag;		/* update flag */
69 int	diskfd;		/* disk file descriptor */
70 int	tapefd;		/* tape file descriptor */
71 int	pipeout;	/* true => output to standard output */
72 ino_t	curino;		/* current inumber; used globally */
73 int	newtape;	/* new tape flag */
74 int	density;	/* density in 0.1" units */
75 long	tapesize;	/* estimated tape size, blocks */
76 long	tsize;		/* tape size in 0.1" units */
77 long	asize;		/* number of 0.1" units written on current tape */
78 int	etapes;		/* estimated number of tapes */
79 int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
80 int	unlimited;	/* if set, write to end of medium */
81 int	cachesize;	/* size of block cache */
82 
83 int	notify;		/* notify operator flag */
84 int	blockswritten;	/* number of blocks written on current tape */
85 int	tapeno;		/* current tape number */
86 time_t	tstart_writing;	/* when started writing the first tape block */
87 time_t	tend_writing;	/* after writing the last tape block */
88 int	passno;		/* current dump pass number */
89 struct	fs *sblock;	/* the file system super block */
90 char	sblock_buf[MAXBSIZE];
91 long	dev_bsize;	/* block size of underlying disk device */
92 int	dev_bshift;	/* log2(dev_bsize) */
93 int	tp_bshift;	/* log2(TP_BSIZE) */
94 
95 /* operator interface functions */
96 void	broadcast(char *message);
97 void	infosch(int);
98 void	lastdump(int arg);	/* int should be char */
99 void	msg(const char *fmt, ...) __printflike(1, 2);
100 void	msgtail(const char *fmt, ...) __printflike(1, 2);
101 int	query(char *question);
102 void	quit(const char *fmt, ...) __printflike(1, 2);
103 void	timeest(void);
104 time_t	unctime(char *str);
105 
106 /* mapping rouintes */
107 struct	dinode;
108 long	blockest(struct dinode *dp);
109 int	mapfiles(ino_t maxino, long *tapesize);
110 int	mapdirs(ino_t maxino, long *tapesize);
111 
112 /* file dumping routines */
113 void	blksout(daddr_t *blkp, int frags, ino_t ino);
114 void	bread(daddr_t blkno, char *buf, int size);
115 ssize_t cread(int fd, void *buf, size_t nbytes, off_t offset);
116 void	dumpino(struct dinode *dp, ino_t ino);
117 void	dumpmap(char *map, int type, ino_t ino);
118 void	writeheader(ino_t ino);
119 
120 /* tape writing routines */
121 int	alloctape(void);
122 void	close_rewind(void);
123 void	dumpblock(daddr_t blkno, int size);
124 void	startnewtape(int top);
125 void	trewind(void);
126 void	writerec(char *dp, int isspcl);
127 
128 void	Exit(int status) __dead2;
129 void	dumpabort(int signo);
130 void	getfstab(void);
131 
132 char	*rawname(char *cp);
133 struct	dinode *getino(ino_t inum);
134 
135 /* rdump routines */
136 #ifdef RDUMP
137 void	rmtclose(void);
138 int	rmthost(char *host);
139 int	rmtopen(char *tape, int mode);
140 int	rmtwrite(char *buf, int count);
141 #endif /* RDUMP */
142 
143 void	interrupt(int signo);	/* in case operator bangs on console */
144 
145 /*
146  *	Exit status codes
147  */
148 #define	X_FINOK		0	/* normal exit */
149 #define	X_STARTUP	1	/* startup error */
150 #define	X_REWRITE	2	/* restart writing from the check point */
151 #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
152 
153 #define	OPGRENT	"operator"		/* group entry to notify */
154 
155 struct	fstab *fstabsearch(char *key);	/* search fs_file and fs_spec */
156 
157 #ifndef NAME_MAX
158 #define NAME_MAX 255
159 #endif
160 
161 /*
162  *	The contents of the file _PATH_DUMPDATES is maintained both on
163  *	a linked list, and then (eventually) arrayified.
164  */
165 struct dumpdates {
166 	char	dd_name[NAME_MAX+3];
167 	char	dd_level;
168 	time_t	dd_ddate;
169 };
170 int	nddates;		/* number of records (might be zero) */
171 int	ddates_in;		/* we have read the increment file */
172 struct	dumpdates **ddatev;	/* the arrayfied version */
173 void	initdumptimes(void);
174 void	getdumptime(void);
175 void	putdumptime(void);
176 #define	ITITERATE(i, ddp) \
177 	for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
178 
179 void	sig(int signo);
180 
181 /*
182  * Compatibility with old systems.
183  */
184 #ifdef COMPAT
185 #include <sys/file.h>
186 #define	strchr(a,b)	index(a,b)
187 #define	strrchr(a,b)	rindex(a,b)
188 extern char *strdup(), *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 void exit();
210 extern off_t lseek();
211 extern const char *strerror();
212 #endif
213