xref: /netbsd-src/sbin/dump/dump.h (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /*	$NetBSD: dump.h,v 1.27 2001/05/28 01:09:55 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 1980, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)dump.h	8.2 (Berkeley) 4/28/95
36  */
37 
38 #include <machine/bswap.h>
39 
40 #define MAXINOPB	(MAXBSIZE / sizeof(struct dinode))
41 #define MAXNINDIR	(MAXBSIZE / sizeof(daddr_t))
42 
43 /*
44  * Filestore-independent UFS data, so code can be more easily shared
45  * between ffs, lfs, and maybe ext2fs and others as well.
46  */
47 struct ufsi {
48 	int64_t ufs_dsize;	/* filesystem size, in sectors */
49 	int32_t ufs_bsize;	/* block size */
50 	int32_t ufs_bshift;	/* log2(ufs_bsize) */
51 	int32_t ufs_fsize;	/* fragment size */
52 	int32_t ufs_frag;       /* block size / frag size */
53 	int32_t ufs_fsatoda;	/* disk address conversion constant */
54 	int32_t	ufs_nindir;	/* disk addresses per indirect block */
55 	int32_t ufs_inopb;      /* inodes per block */
56 	int32_t ufs_maxsymlinklen; /* max symlink length */
57 	int32_t ufs_bmask;      /* block mask */
58 	int32_t ufs_fmask;      /* frag mask */
59 	int64_t ufs_qbmask;     /* ~ufs_bmask */
60 	int64_t ufs_qfmask;     /* ~ufs_fmask */
61 };
62 #define fsatoda(u,a) ((a) << (u)->ufs_fsatoda)
63 #define ufs_fragroundup(u,size) /* calculates roundup(size, ufs_fsize) */ \
64         (((size) + (u)->ufs_qfmask) & (u)->ufs_fmask)
65 #define ufs_blkoff(u,loc)   /* calculates (loc % u->ufs_bsize) */ \
66         ((loc) & (u)->ufs_qbmask)
67 #define ufs_dblksize(u,d,b) \
68 	((((b) >= NDADDR || (d)->di_size >= ((b)+1) << (u)->ufs_bshift \
69 		? (u)->ufs_bsize \
70 		: (ufs_fragroundup((u), ufs_blkoff(u, (d)->di_size))))))
71 struct ufsi *ufsib;
72 
73 /*
74  * Dump maps used to describe what is to be dumped.
75  */
76 int	mapsize;	/* size of the state maps */
77 char	*usedinomap;	/* map of allocated inodes */
78 char	*dumpdirmap;	/* map of directories to be dumped */
79 char	*dumpinomap;	/* map of files to be dumped */
80 /*
81  * Map manipulation macros.
82  */
83 #define	SETINO(ino, map) \
84 	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
85 #define	CLRINO(ino, map) \
86 	map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
87 #define	TSTINO(ino, map) \
88 	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
89 
90 /*
91  *	All calculations done in 0.1" units!
92  */
93 char	*disk;		/* name of the disk file */
94 char	*tape;		/* name of the tape file */
95 char	*dumpdates;	/* name of the file containing dump date information*/
96 char	*temp;		/* name of the file for doing rewrite of dumpdates */
97 char	lastlevel;	/* dump level of previous dump */
98 char	level;		/* dump level of this dump */
99 int	uflag;		/* update flag */
100 int	eflag;		/* eject flag */
101 int	diskfd;		/* disk file descriptor */
102 int	tapefd;		/* tape file descriptor */
103 int	pipeout;	/* true => output to standard output */
104 ino_t	curino;		/* current inumber; used globally */
105 int	newtape;	/* new tape flag */
106 long	tapesize;	/* estimated tape size, blocks */
107 long	tsize;		/* tape size in 0.1" units */
108 long	asize;		/* number of 0.1" units written on current tape */
109 int	etapes;		/* estimated number of tapes */
110 int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
111 
112 extern int	density;	/* density in 0.1" units */
113 extern int	notify;		/* notify operator flag */
114 extern int	blockswritten;	/* number of blocks written on current tape */
115 extern int	tapeno;		/* current tape number */
116 
117 time_t	tstart_writing;	/* when started writing the first tape block */
118 int	xferrate;	/* averaged transfer rate of all volumes */
119 char	sblock_buf[MAXBSIZE]; /* buffer to hold the superblock */
120 extern long	dev_bsize;	/* block size of underlying disk device */
121 int	dev_bshift;	/* log2(dev_bsize) */
122 int	tp_bshift;	/* log2(TP_BSIZE) */
123 int needswap;	/* file system in swapped byte order */
124 /* some inline functs to help the byte-swapping mess */
125 static __inline u_int16_t iswap16(u_int16_t);
126 static __inline u_int32_t iswap32(u_int32_t);
127 static __inline u_int64_t iswap64(u_int64_t);
128 
129 static __inline u_int16_t iswap16(u_int16_t x)
130 {
131 	if (needswap)
132 		return bswap16(x);
133 	else
134 		return x;
135 }
136 
137 static __inline u_int32_t iswap32(u_int32_t x)
138 {
139 	if (needswap)
140 		return bswap32(x);
141 	else
142 		return x;
143 }
144 
145 static __inline u_int64_t iswap64(u_int64_t x)
146 {
147 	if (needswap)
148 		return bswap64(x);
149 	else
150 		return x;
151 }
152 
153 /* filestore-specific hooks */
154 int	fs_read_sblock(char *);
155 struct ufsi *fs_parametrize(void);
156 ino_t	fs_maxino(void);
157 
158 /* operator interface functions */
159 void	broadcast(char *);
160 void	lastdump(char);
161 void	msg(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
162 void	msgtail(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
163 int	query(char *);
164 void	quit(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
165 void	set_operators(void);
166 time_t	do_stats(void);
167 void	statussig(int);
168 void	timeest(void);
169 time_t	unctime(char *);
170 
171 /* mapping routines */
172 struct	dinode;
173 long	blockest(struct dinode *);
174 void	mapfileino(ino_t, long *, int *);
175 int	mapfiles(ino_t, long *, char *, char * const *);
176 int	mapdirs(ino_t, long *);
177 
178 /* file dumping routines */
179 void	blksout(daddr_t *, int, ino_t);
180 void	dumpino(struct dinode *, ino_t);
181 void	dumpmap(char *, int, ino_t);
182 void	writeheader(ino_t);
183 
184 /* data block caching */
185 void	bread(daddr_t, char *, int);
186 void	rawread(daddr_t, char *, int);
187 void	initcache(int, int);
188 void	printcachestats(void);
189 
190 /* tape writing routines */
191 int	alloctape(void);
192 void	close_rewind(void);
193 void	dumpblock(daddr_t, int);
194 void	startnewtape(int);
195 void	trewind(int);
196 void	writerec(char *, int);
197 
198 void	Exit(int);
199 void	dumpabort(int);
200 void	getfstab(void);
201 
202 char	*rawname(char *);
203 struct	dinode *getino(ino_t);
204 
205 void	*xcalloc(size_t, size_t);
206 void	*xmalloc(size_t);
207 char	*xstrdup(const char *);
208 
209 /* rdump routines */
210 #if defined(RDUMP) || defined(RRESTORE)
211 void	rmtclose(void);
212 int	rmthost(char *);
213 int	rmtopen(char *, int);
214 int	rmtwrite(char *, int);
215 #endif /* RDUMP || RRESTORE */
216 
217 void	interrupt(int);	/* in case operator bangs on console */
218 
219 /*
220  *	Exit status codes
221  */
222 #define	X_FINOK		0	/* normal exit */
223 #define	X_REWRITE	2	/* restart writing from the check point */
224 #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
225 
226 #define	OPGRENT	"operator"		/* group entry to notify */
227 #define DIALUP	"ttyd"			/* prefix for dialups */
228 
229 struct	fstab *fstabsearch(const char *);	/* search fs_file and fs_spec */
230 struct	statfs *mntinfosearch(const char *key);
231 
232 #ifndef NAME_MAX
233 #define NAME_MAX 255
234 #endif
235 
236 /*
237  *	The contents of the file _PATH_DUMPDATES is maintained both on
238  *	a linked list, and then (eventually) arrayified.
239  */
240 struct dumpdates {
241 	char	dd_name[NAME_MAX+3];
242 	char	dd_level;
243 	time_t	dd_ddate;
244 };
245 struct dumptime {
246 	struct	dumpdates dt_value;
247 	struct	dumptime *dt_next;
248 };
249 
250 extern struct	dumptime *dthead;	/* head of the list version */
251 extern int	nddates;		/* number of records (might be zero) */
252 extern int	ddates_in;		/* we have read the increment file */
253 extern struct	dumpdates **ddatev;	/* the arrayfied version */
254 
255 void	initdumptimes(void);
256 void	getdumptime(void);
257 void	putdumptime(void);
258 #define	ITITERATE(i, ddp) \
259 	for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
260 
261 void	sig(int signo);
262 
263 /*
264  * Compatibility with old systems.
265  */
266 #ifdef COMPAT
267 #include <sys/file.h>
268 #define	strchr(a,b)	index(a,b)
269 #define	strrchr(a,b)	rindex(a,b)
270 extern char *strdup(), *ctime();
271 extern int read(), write();
272 extern int errno;
273 #endif
274 
275 #ifndef	_PATH_UTMP
276 #define	_PATH_UTMP	"/etc/utmp"
277 #endif
278 #ifndef	_PATH_FSTAB
279 #define	_PATH_FSTAB	"/etc/fstab"
280 #endif
281