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