dump.h revision 1.35 1 /* $NetBSD: dump.h,v 1.35 2003/03/27 13:56:46 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 /* XXX ondisk32 */
42 #define MAXNINDIR (MAXBSIZE / sizeof(int32_t))
43
44 /*
45 * Filestore-independent UFS data, so code can be more easily shared
46 * between ffs, lfs, and maybe ext2fs and others as well.
47 */
48 struct ufsi {
49 int64_t ufs_dsize; /* file system size, in sectors */
50 int32_t ufs_bsize; /* block size */
51 int32_t ufs_bshift; /* log2(ufs_bsize) */
52 int32_t ufs_fsize; /* fragment size */
53 int32_t ufs_frag; /* block size / frag size */
54 int32_t ufs_fsatoda; /* disk address conversion constant */
55 int32_t ufs_nindir; /* disk addresses per indirect block */
56 int32_t ufs_inopb; /* inodes per block */
57 int32_t ufs_maxsymlinklen; /* max symlink length */
58 int32_t ufs_bmask; /* block mask */
59 int32_t ufs_fmask; /* frag mask */
60 int64_t ufs_qbmask; /* ~ufs_bmask */
61 int64_t ufs_qfmask; /* ~ufs_fmask */
62 };
63 #define fsatoda(u,a) ((a) << (u)->ufs_fsatoda)
64 #define ufs_fragroundup(u,size) /* calculates roundup(size, ufs_fsize) */ \
65 (((size) + (u)->ufs_qfmask) & (u)->ufs_fmask)
66 #define ufs_blkoff(u,loc) /* calculates (loc % u->ufs_bsize) */ \
67 ((loc) & (u)->ufs_qbmask)
68 #define ufs_dblksize(u,d,b) \
69 ((((b) >= NDADDR || (d)->di_size >= ((b)+1) << (u)->ufs_bshift \
70 ? (u)->ufs_bsize \
71 : (ufs_fragroundup((u), ufs_blkoff(u, (d)->di_size))))))
72 struct ufsi *ufsib;
73
74 /*
75 * Dump maps used to describe what is to be dumped.
76 */
77 int mapsize; /* size of the state maps */
78 char *usedinomap; /* map of allocated inodes */
79 char *dumpdirmap; /* map of directories to be dumped */
80 char *dumpinomap; /* map of files to be dumped */
81 /*
82 * Map manipulation macros.
83 */
84 #define SETINO(ino, map) \
85 map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
86 #define CLRINO(ino, map) \
87 map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY))
88 #define TSTINO(ino, map) \
89 (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
90
91 /*
92 * All calculations done in 0.1" units!
93 */
94 char *disk; /* name of the disk file */
95 char *tape; /* name of the tape file */
96 char *dumpdates; /* name of the file containing dump date information*/
97 char *temp; /* name of the file for doing rewrite of dumpdates */
98 char lastlevel; /* dump level of previous dump */
99 char level; /* dump level of this dump */
100 int uflag; /* update flag */
101 int eflag; /* eject flag */
102 int lflag; /* autoload flag */
103 int diskfd; /* disk file descriptor */
104 int tapefd; /* tape file descriptor */
105 int pipeout; /* true => output to standard output */
106 ino_t curino; /* current inumber; used globally */
107 int newtape; /* new tape flag */
108 long tapesize; /* estimated tape size, blocks */
109 long tsize; /* tape size in 0.1" units */
110 long asize; /* number of 0.1" units written on current tape */
111 int etapes; /* estimated number of tapes */
112 int nonodump; /* if set, do not honor UF_NODUMP user flags */
113 int unlimited; /* if set, write to end of medium */
114
115 extern int density; /* density in 0.1" units */
116 extern int notify; /* notify operator flag */
117 extern int timestamp; /* timestamp messages */
118 extern int blockswritten; /* number of blocks written on current tape */
119 extern int tapeno; /* current tape number */
120
121 time_t tstart_writing; /* when started writing the first tape block */
122 int xferrate; /* averaged transfer rate of all volumes */
123 char sblock_buf[MAXBSIZE]; /* buffer to hold the superblock */
124 extern long dev_bsize; /* block size of underlying disk device */
125 int dev_bshift; /* log2(dev_bsize) */
126 int tp_bshift; /* log2(TP_BSIZE) */
127 int needswap; /* file system in swapped byte order */
128 /* some inline functs to help the byte-swapping mess */
129 static __inline u_int16_t iswap16(u_int16_t);
130 static __inline u_int32_t iswap32(u_int32_t);
131 static __inline u_int64_t iswap64(u_int64_t);
132
133 static __inline u_int16_t iswap16(u_int16_t x)
134 {
135 if (needswap)
136 return bswap16(x);
137 else
138 return x;
139 }
140
141 static __inline u_int32_t iswap32(u_int32_t x)
142 {
143 if (needswap)
144 return bswap32(x);
145 else
146 return x;
147 }
148
149 static __inline u_int64_t iswap64(u_int64_t x)
150 {
151 if (needswap)
152 return bswap64(x);
153 else
154 return x;
155 }
156
157 /* filestore-specific hooks */
158 int fs_read_sblock(char *);
159 struct ufsi *fs_parametrize(void);
160 ino_t fs_maxino(void);
161
162 /* operator interface functions */
163 void broadcast(char *);
164 void lastdump(char);
165 void msg(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
166 void msgtail(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
167 int query(char *);
168 void quit(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
169 time_t do_stats(void);
170 void statussig(int);
171 void timeest(void);
172 time_t unctime(char *);
173
174 /* mapping routines */
175 struct dinode;
176 long blockest(struct dinode *);
177 void mapfileino(ino_t, long *, int *);
178 int mapfiles(ino_t, long *, char *, char * const *);
179 int mapdirs(ino_t, long *);
180
181 /* file dumping routines */
182 /* XXX ondisk32 */
183 void blksout(int32_t *, int, ino_t);
184 void dumpino(struct dinode *, ino_t);
185 void dumpmap(char *, int, ino_t);
186 void writeheader(ino_t);
187
188 /* data block caching */
189 void bread(daddr_t, char *, int);
190 void rawread(daddr_t, char *, int);
191 void initcache(int, int);
192 void printcachestats(void);
193
194 /* tape writing routines */
195 int alloctape(void);
196 void close_rewind(void);
197 void dumpblock(daddr_t, int);
198 void startnewtape(int);
199 void trewind(int);
200 void writerec(char *, int);
201
202 void Exit(int);
203 void dumpabort(int);
204 void getfstab(void);
205
206 char *rawname(char *);
207 struct dinode *getino(ino_t);
208
209 void *xcalloc(size_t, size_t);
210 void *xmalloc(size_t);
211 char *xstrdup(const char *);
212
213 /* rdump routines */
214 #if defined(RDUMP) || defined(RRESTORE)
215 void rmtclose(void);
216 int rmthost(char *);
217 int rmtopen(char *, int, int);
218 int rmtwrite(char *, int);
219 int rmtioctl(int, int);
220 #endif /* RDUMP || RRESTORE */
221
222 void interrupt(int); /* in case operator bangs on console */
223
224 /*
225 * Exit status codes
226 */
227 #define X_FINOK 0 /* normal exit */
228 #define X_STARTUP 1 /* startup error */
229 #define X_REWRITE 2 /* restart writing from the check point */
230 #define X_ABORT 3 /* abort dump; don't attempt checkpointing */
231
232 #define OPGRENT "operator" /* group entry to notify */
233 #define DIALUP "ttyd" /* prefix for dialups */
234
235 struct fstab *fstabsearch(const char *); /* search fs_file and fs_spec */
236 struct statfs *mntinfosearch(const char *key);
237
238 #ifndef NAME_MAX
239 #define NAME_MAX 255
240 #endif
241
242 /*
243 * The contents of the file _PATH_DUMPDATES is maintained both on
244 * a linked list, and then (eventually) arrayified.
245 */
246 struct dumpdates {
247 char dd_name[NAME_MAX+3];
248 char dd_level;
249 time_t dd_ddate;
250 };
251
252 extern int nddates; /* number of records (might be zero) */
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 if (ddatev != NULL) \
260 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
261
262 void sig(int signo);
263
264 /*
265 * Compatibility with old systems.
266 */
267 #ifdef COMPAT
268 #include <sys/file.h>
269 #define strchr(a,b) index(a,b)
270 #define strrchr(a,b) rindex(a,b)
271 extern char *strdup(), *ctime();
272 extern int read(), write();
273 extern int errno;
274 #endif
275
276 #ifndef _PATH_FSTAB
277 #define _PATH_FSTAB "/etc/fstab"
278 #endif
279