dump.h revision 1.20 1 /* $NetBSD: dump.h,v 1.20 2000/10/10 20:24:50 is 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 diskfd; /* disk file descriptor */
101 int tapefd; /* tape file descriptor */
102 int pipeout; /* true => output to standard output */
103 ino_t curino; /* current inumber; used globally */
104 int newtape; /* new tape flag */
105 int density; /* density in 0.1" units */
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 int notify; /* notify operator flag */
113 int blockswritten; /* number of blocks written on current tape */
114 int tapeno; /* current tape number */
115 time_t tstart_writing; /* when started writing the first tape block */
116 int xferrate; /* averaged transfer rate of all volumes */
117 char sblock_buf[MAXBSIZE]; /* buffer to hold the superblock */
118 long dev_bsize; /* block size of underlying disk device */
119 int dev_bshift; /* log2(dev_bsize) */
120 int tp_bshift; /* log2(TP_BSIZE) */
121 int needswap; /* file system in swapped byte order */
122 /* some inline functs to help the byte-swapping mess */
123 static __inline u_int16_t iswap16 __P((u_int16_t));
124 static __inline u_int32_t iswap32 __P((u_int32_t));
125 static __inline u_int64_t iswap64 __P((u_int64_t));
126
127 static __inline u_int16_t iswap16(x)
128 u_int16_t x;
129 {
130 if (needswap)
131 return bswap16(x);
132 else return x;
133 }
134
135 static __inline u_int32_t iswap32(x)
136 u_int32_t x;
137 {
138 if (needswap)
139 return bswap32(x);
140 else return x;
141 }
142
143 static __inline u_int64_t iswap64(x)
144 u_int64_t x;
145 {
146 if (needswap)
147 return bswap64(x);
148 else return x;
149 }
150
151 #ifndef __P
152 #include <sys/cdefs.h>
153 #endif
154
155 /* filestore-specific hooks */
156 int fs_read_sblock __P((char *));
157 struct ufsi *fs_parametrize __P((void));
158 ino_t fs_maxino __P((void));
159
160 /* operator interface functions */
161 void broadcast __P((char *message));
162 void lastdump __P((int arg)); /* int should be char */
163 void msg __P((const char *fmt, ...)) __attribute__((__format__(__printf__,1,2)));
164 void msgtail __P((const char *fmt, ...)) __attribute__((__format__(__printf__,1,2)));
165 int query __P((char *question));
166 void quit __P((const char *fmt, ...)) __attribute__((__format__(__printf__,1,2)));
167 void set_operators __P((void));
168 time_t do_stats __P((void));
169 void statussig __P((int));
170 void timeest __P((void));
171 time_t unctime __P((char *str));
172
173 /* mapping routines */
174 struct dinode;
175 long blockest __P((struct dinode *dp));
176 void mapfileino __P((ino_t, long *, int *));
177 int mapfiles __P((ino_t maxino, long *tapesize, char *disk,
178 char * const *dirv));
179 int mapdirs __P((ino_t maxino, long *tapesize));
180
181 /* file dumping routines */
182 void blksout __P((daddr_t *blkp, int frags, ino_t ino));
183 void dumpino __P((struct dinode *dp, ino_t ino));
184 void dumpmap __P((char *map, int type, ino_t ino));
185 void writeheader __P((ino_t ino));
186
187 /* data block caching */
188 void bread __P((daddr_t blkno, char *buf, int size));
189 void rawread __P((daddr_t, char *, int));
190 void initcache __P((int, int));
191 void printcachestats __P((void));
192
193 /* tape writing routines */
194 int alloctape __P((void));
195 void close_rewind __P((void));
196 void dumpblock __P((daddr_t blkno, int size));
197 void startnewtape __P((int top));
198 void trewind __P((void));
199 void writerec __P((char *dp, int isspcl));
200
201 void Exit __P((int status));
202 void dumpabort __P((int signo));
203 void getfstab __P((void));
204
205 char *rawname __P((char *cp));
206 struct dinode *getino __P((ino_t inum));
207
208 /* rdump routines */
209 #ifdef RDUMP
210 void rmtclose __P((void));
211 int rmthost __P((char *host));
212 int rmtopen __P((char *tape, int mode));
213 int rmtwrite __P((char *buf, int count));
214 #endif /* RDUMP */
215
216 void interrupt __P((int signo)); /* in case operator bangs on console */
217
218 /*
219 * Exit status codes
220 */
221 #define X_FINOK 0 /* normal exit */
222 #define X_REWRITE 2 /* restart writing from the check point */
223 #define X_ABORT 3 /* abort dump; don't attempt checkpointing */
224
225 #define OPGRENT "operator" /* group entry to notify */
226 #define DIALUP "ttyd" /* prefix for dialups */
227
228 struct fstab *fstabsearch __P((char *key)); /* search fs_file and fs_spec */
229
230 #ifndef NAME_MAX
231 #define NAME_MAX 255
232 #endif
233
234 /*
235 * The contents of the file _PATH_DUMPDATES is maintained both on
236 * a linked list, and then (eventually) arrayified.
237 */
238 struct dumpdates {
239 char dd_name[NAME_MAX+3];
240 char dd_level;
241 time_t dd_ddate;
242 };
243 struct dumptime {
244 struct dumpdates dt_value;
245 struct dumptime *dt_next;
246 };
247 struct dumptime *dthead; /* head of the list version */
248 int nddates; /* number of records (might be zero) */
249 int ddates_in; /* we have read the increment file */
250 struct dumpdates **ddatev; /* the arrayfied version */
251 void initdumptimes __P((void));
252 void getdumptime __P((void));
253 void putdumptime __P((void));
254 #define ITITERATE(i, ddp) \
255 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
256
257 void sig __P((int signo));
258
259 /*
260 * Compatibility with old systems.
261 */
262 #ifdef COMPAT
263 #include <sys/file.h>
264 #define strchr(a,b) index(a,b)
265 #define strrchr(a,b) rindex(a,b)
266 extern char *strdup(), *ctime();
267 extern int read(), write();
268 extern int errno;
269 #endif
270
271 #ifndef _PATH_UTMP
272 #define _PATH_UTMP "/etc/utmp"
273 #endif
274 #ifndef _PATH_FSTAB
275 #define _PATH_FSTAB "/etc/fstab"
276 #endif
277
278 #ifdef sunos
279 extern char *calloc();
280 extern char *malloc();
281 extern long atol();
282 extern char *strcpy();
283 extern char *strncpy();
284 extern char *strcat();
285 extern time_t time();
286 extern void endgrent();
287 extern void exit();
288 extern off_t lseek();
289 extern const char *strerror();
290 #endif
291