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