xref: /openbsd/sbin/dump/dump.h (revision 9be7043f)
1 /*	$OpenBSD: dump.h,v 1.25 2021/01/21 00:16:36 mortimer Exp $	*/
2 /*	$NetBSD: dump.h,v 1.11 1997/06/05 11:13:20 lukem Exp $	*/
3 
4 /*-
5  * Copyright (c) 1980, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)dump.h	8.1 (Berkeley) 6/5/93
33  */
34 
35 /*
36  * Dump maps used to describe what is to be dumped.
37  */
38 extern int	mapsize;	/* size of the state maps */
39 extern char	*usedinomap;	/* map of allocated inodes */
40 extern char	*dumpdirmap;	/* map of directories to be dumped */
41 extern char	*dumpinomap;	/* map of files to be dumped */
42 /*
43  * Map manipulation macros.
44  */
45 #define	SETINO(ino, map) \
46 	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
47 #define	CLRINO(ino, map) \
48 	map[(u_int)((ino) - 1) / NBBY] &=  ~(1 << ((u_int)((ino) - 1) % NBBY))
49 #define	TSTINO(ino, map) \
50 	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
51 
52 /*
53  *	All calculations done in 0.1" units!
54  */
55 extern char	*disk;		/* name of the disk file */
56 extern char	*tape;		/* name of the tape file */
57 extern char	*dumpdates;	/* name of the file containing dump date information*/
58 extern char	*duid;		/* duid of the disk being dumped */
59 extern char	lastlevel;	/* dump level of previous dump */
60 extern char	level;		/* dump level of this dump */
61 extern int	uflag;		/* update flag */
62 extern int	diskfd;		/* disk file descriptor */
63 extern int	pipeout;	/* true => output to standard output */
64 extern ino_t	curino;		/* current inumber; used globally */
65 extern int	newtape;	/* new tape flag */
66 extern int	density;	/* density in 0.1" units */
67 extern int64_t	tapesize;	/* estimated tape size, blocks */
68 extern int64_t	tsize;		/* tape size in 0.1" units */
69 extern int	unlimited;	/* if set, write to end of medium */
70 extern int	etapes;		/* estimated number of tapes */
71 extern int	nonodump;	/* if set, do not honor UF_NODUMP user flags */
72 extern int	notify;		/* notify operator flag */
73 extern int64_t	blockswritten;	/* number of blocks written on current tape */
74 extern int	tapeno;		/* current tape number */
75 extern int 	ntrec;		/* blocking factor on tape */
76 extern int64_t	blocksperfile;  /* number of blocks per output file */
77 extern int	cartridge;	/* assume non-cartridge tape */
78 extern char 	*host;		/* remote host (if any) */
79 extern time_t	tstart_writing;	/* when started writing the first tape block */
80 extern long	xferrate;	/* averaged transfer rate of all volumes */
81 extern struct	fs *sblock;	/* the file system super block */
82 extern char	sblock_buf[MAXBSIZE];
83 extern int	tp_bshift;	/* log2(TP_BSIZE) */
84 
85 /* operator interface functions */
86 void	broadcast(char *message);
87 time_t	do_stats(void);
88 void	lastdump(int arg);	/* int should be char */
89 void	msg(const char *fmt, ...)
90 	    __attribute__((__format__ (printf, 1, 2)));
91 void	msgtail(const char *fmt, ...)
92 	    __attribute__((__format__ (printf, 1, 2)));
93 int	query(char *question);
94 __dead void quit(const char *fmt, ...)
95 	    __attribute__((__format__ (printf, 1, 2)));
96 void	statussig(int);
97 void	timeest(void);
98 
99 /* mapping routines */
100 union	dinode;
101 int64_t	blockest(union dinode *dp);
102 void	mapfileino(ino_t, int64_t *, int *);
103 int	mapfiles(ino_t maxino, int64_t *tapesize, char *disk,
104 	    char * const *dirv);
105 int	mapdirs(ino_t maxino, int64_t *tapesize);
106 
107 /* file dumping routines */
108 void	ufs1_blksout(int32_t *blkp, int frags, ino_t ino);
109 void	ufs2_blksout(daddr_t *blkp, int frags, ino_t ino);
110 void	bread(daddr_t blkno, char *buf, int size);
111 void	dumpino(union dinode *dp, ino_t ino);
112 void	dumpmap(char *map, int type, ino_t ino);
113 void	writeheader(ino_t ino);
114 
115 /* tape writing routines */
116 int	alloctape(void);
117 void	close_rewind(void);
118 void	dumpblock(daddr_t blkno, int size);
119 void	startnewtape(int top);
120 void	trewind(void);
121 void	writerec(char *dp, int isspcl);
122 
123 __dead void Exit(int status);
124 __dead void dumpabort(int signo);
125 void	getfstab(void);
126 
127 char	*rawname(char *cp);
128 char	*getduid(char *path);
129 union	dinode *getino(ino_t inum, int *mode);
130 
131 /* rdump routines */
132 #ifdef RDUMP
133 void	rmtclose(void);
134 int	rmthost(char *host);
135 int	rmtopen(char *tape, int mode);
136 int	rmtwrite(char *buf, int count);
137 #endif /* RDUMP */
138 
139 void	interrupt(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_STARTUP	1	/* startup error */
146 #define	X_REWRITE	2	/* restart writing from the check point */
147 #define	X_ABORT		3	/* abort dump; don't attempt checkpointing */
148 
149 #define	OPGRENT	"operator"		/* group entry to notify */
150 
151 struct	fstab *fstabsearch(char *key);	/* search fs_file and fs_spec */
152 
153 /*
154  *	The contents of the file _PATH_DUMPDATES is maintained both on
155  *	a linked list, and then (eventually) arrayified.
156  */
157 struct dumpdates {
158 	char	dd_name[NAME_MAX+3];
159 	char	dd_level;
160 	time_t	dd_ddate;
161 };
162 struct dumptime {
163 	struct	dumpdates dt_value;
164 	struct	dumptime *dt_next;
165 };
166 extern struct	dumptime *dthead;	/* head of the list version */
167 extern int	ddates_in;		/* we have read the increment file */
168 extern int	nddates;		/* number of records (might be zero) */
169 extern struct	dumpdates **ddatev;	/* the arrayfied version */
170 void	initdumptimes(void);
171 void	getdumptime(void);
172 void	putdumptime(void);
173 #define	ITITERATE(i, ddp) \
174 	for (i = 0; i < nddates && (ddp = ddatev[i]); i++)
175 
176 void	sig(int signo);
177 
178