dump.h revision 1.16 1 /* $NetBSD: dump.h,v 1.16 1999/03/23 14:22:59 bouyer 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 * Dump maps used to describe what is to be dumped.
45 */
46 int mapsize; /* size of the state maps */
47 char *usedinomap; /* map of allocated inodes */
48 char *dumpdirmap; /* map of directories to be dumped */
49 char *dumpinomap; /* map of files to be dumped */
50 /*
51 * Map manipulation macros.
52 */
53 #define SETINO(ino, map) \
54 map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
55 #define CLRINO(ino, map) \
56 map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY))
57 #define TSTINO(ino, map) \
58 (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
59
60 /*
61 * All calculations done in 0.1" units!
62 */
63 char *disk; /* name of the disk file */
64 char *tape; /* name of the tape file */
65 char *dumpdates; /* name of the file containing dump date information*/
66 char *temp; /* name of the file for doing rewrite of dumpdates */
67 char lastlevel; /* dump level of previous dump */
68 char level; /* dump level of this dump */
69 int uflag; /* update flag */
70 int diskfd; /* disk file descriptor */
71 int tapefd; /* tape file descriptor */
72 int pipeout; /* true => output to standard output */
73 ino_t curino; /* current inumber; used globally */
74 int newtape; /* new tape flag */
75 int density; /* density in 0.1" units */
76 long tapesize; /* estimated tape size, blocks */
77 long tsize; /* tape size in 0.1" units */
78 long asize; /* number of 0.1" units written on current tape */
79 int etapes; /* estimated number of tapes */
80 int nonodump; /* if set, do not honor UF_NODUMP user flags */
81
82 int notify; /* notify operator flag */
83 int blockswritten; /* number of blocks written on current tape */
84 int tapeno; /* current tape number */
85 time_t tstart_writing; /* when started writing the first tape block */
86 int xferrate; /* averaged transfer rate of all volumes */
87 struct fs *sblock; /* the file system super block */
88 char sblock_buf[MAXBSIZE];
89 long dev_bsize; /* block size of underlying disk device */
90 int dev_bshift; /* log2(dev_bsize) */
91 int tp_bshift; /* log2(TP_BSIZE) */
92 int needswap; /* file system in swapped byte order */
93 /* some inline functs to help the byte-swapping mess */
94 static __inline u_int16_t iswap16 __P((u_int16_t));
95 static __inline u_int32_t iswap32 __P((u_int32_t));
96 static __inline u_int64_t iswap64 __P((u_int64_t));
97
98 static __inline u_int16_t iswap16(x)
99 u_int16_t x;
100 {
101 if (needswap)
102 return bswap16(x);
103 else return x;
104 }
105
106 static __inline u_int32_t iswap32(x)
107 u_int32_t x;
108 {
109 if (needswap)
110 return bswap32(x);
111 else return x;
112 }
113
114 static __inline u_int64_t iswap64(x)
115 u_int64_t x;
116 {
117 if (needswap)
118 return bswap64(x);
119 else return x;
120 }
121
122 #ifndef __P
123 #include <sys/cdefs.h>
124 #endif
125
126 /* operator interface functions */
127 void broadcast __P((char *message));
128 void lastdump __P((int arg)); /* int should be char */
129 void msg __P((const char *fmt, ...));
130 void msgtail __P((const char *fmt, ...));
131 int query __P((char *question));
132 void quit __P((const char *fmt, ...));
133 void set_operators __P((void));
134 time_t do_stats __P((void));
135 void statussig __P((int));
136 void timeest __P((void));
137 time_t unctime __P((char *str));
138
139 /* mapping routines */
140 struct dinode;
141 long blockest __P((struct dinode *dp));
142 void mapfileino __P((ino_t, long *, int *));
143 int mapfiles __P((ino_t maxino, long *tapesize, char *disk,
144 char * const *dirv));
145 int mapdirs __P((ino_t maxino, long *tapesize));
146
147 /* file dumping routines */
148 void blksout __P((daddr_t *blkp, int frags, ino_t ino));
149 void dumpino __P((struct dinode *dp, ino_t ino));
150 void dumpmap __P((char *map, int type, ino_t ino));
151 void writeheader __P((ino_t ino));
152
153 /* data block caching */
154 void bread __P((daddr_t blkno, char *buf, int size));
155 void rawread __P((daddr_t, char *, int));
156 void initcache __P((int, int));
157 void printcachestats __P((void));
158
159 /* tape writing routines */
160 int alloctape __P((void));
161 void close_rewind __P((void));
162 void dumpblock __P((daddr_t blkno, int size));
163 void startnewtape __P((int top));
164 void trewind __P((void));
165 void writerec __P((char *dp, int isspcl));
166
167 void Exit __P((int status));
168 void dumpabort __P((int signo));
169 void getfstab __P((void));
170
171 char *rawname __P((char *cp));
172 struct dinode *getino __P((ino_t inum));
173
174 /* rdump routines */
175 #ifdef RDUMP
176 void rmtclose __P((void));
177 int rmthost __P((char *host));
178 int rmtopen __P((char *tape, int mode));
179 int rmtwrite __P((char *buf, int count));
180 #endif /* RDUMP */
181
182 void interrupt __P((int signo)); /* in case operator bangs on console */
183
184 /*
185 * Exit status codes
186 */
187 #define X_FINOK 0 /* normal exit */
188 #define X_REWRITE 2 /* restart writing from the check point */
189 #define X_ABORT 3 /* abort dump; don't attempt checkpointing */
190
191 #define OPGRENT "operator" /* group entry to notify */
192 #define DIALUP "ttyd" /* prefix for dialups */
193
194 struct fstab *fstabsearch __P((char *key)); /* search fs_file and fs_spec */
195
196 #ifndef NAME_MAX
197 #define NAME_MAX 255
198 #endif
199
200 /*
201 * The contents of the file _PATH_DUMPDATES is maintained both on
202 * a linked list, and then (eventually) arrayified.
203 */
204 struct dumpdates {
205 char dd_name[NAME_MAX+3];
206 char dd_level;
207 time_t dd_ddate;
208 };
209 struct dumptime {
210 struct dumpdates dt_value;
211 struct dumptime *dt_next;
212 };
213 struct dumptime *dthead; /* head of the list version */
214 int nddates; /* number of records (might be zero) */
215 int ddates_in; /* we have read the increment file */
216 struct dumpdates **ddatev; /* the arrayfied version */
217 void initdumptimes __P((void));
218 void getdumptime __P((void));
219 void putdumptime __P((void));
220 #define ITITERATE(i, ddp) \
221 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
222
223 void sig __P((int signo));
224
225 /*
226 * Compatibility with old systems.
227 */
228 #ifdef COMPAT
229 #include <sys/file.h>
230 #define strchr(a,b) index(a,b)
231 #define strrchr(a,b) rindex(a,b)
232 extern char *strdup(), *ctime();
233 extern int read(), write();
234 extern int errno;
235 #endif
236
237 #ifndef _PATH_UTMP
238 #define _PATH_UTMP "/etc/utmp"
239 #endif
240 #ifndef _PATH_FSTAB
241 #define _PATH_FSTAB "/etc/fstab"
242 #endif
243
244 #ifdef sunos
245 extern char *calloc();
246 extern char *malloc();
247 extern long atol();
248 extern char *strcpy();
249 extern char *strncpy();
250 extern char *strcat();
251 extern time_t time();
252 extern void endgrent();
253 extern void exit();
254 extern off_t lseek();
255 extern const char *strerror();
256 #endif
257