dump.h revision 1.52 1 /* $NetBSD: dump.h,v 1.52 2015/07/28 05:09:34 dholland 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)dump.h 8.2 (Berkeley) 4/28/95
32 */
33
34 #include <machine/bswap.h>
35 #ifdef DUMP_LFS
36 #include <ufs/lfs/lfs.h>
37 #include <ufs/lfs/lfs_accessors.h>
38 #endif
39 #include <ufs/ufs/dinode.h>
40 #include <protocols/dumprestore.h>
41
42 union dinode {
43 struct ufs1_dinode dp1;
44 struct ufs2_dinode dp2;
45 #ifdef DUMP_LFS
46 struct ulfs1_dinode dlp1;
47 struct ulfs2_dinode dlp2;
48 #endif
49 };
50 #define DIP(dp, field) \
51 (is_ufs2 ? (dp)->dp2.di_##field : (dp)->dp1.di_##field)
52
53 #define DIP_SET(dp, field, val) do { \
54 if (is_ufs2) \
55 (dp)->dp2.di_##field = (val); \
56 else \
57 (dp)->dp1.di_##field = (val); \
58 } while (0)
59
60 /*
61 * Filestore-independent UFS data, so code can be more easily shared
62 * between ffs, lfs, and maybe ext2fs and others as well.
63 */
64 struct ufsi {
65 int64_t ufs_dsize; /* file system size, in sectors */
66 int32_t ufs_bsize; /* block size */
67 int32_t ufs_bshift; /* log2(ufs_bsize) */
68 int32_t ufs_fsize; /* fragment size */
69 int32_t ufs_frag; /* block size / frag size */
70 int32_t ufs_fsatoda; /* disk address conversion constant */
71 int32_t ufs_nindir; /* disk addresses per indirect block */
72 int32_t ufs_inopb; /* inodes per block */
73 int32_t ufs_maxsymlinklen; /* max symlink length */
74 int32_t ufs_bmask; /* block mask */
75 int32_t ufs_fmask; /* frag mask */
76 int64_t ufs_qbmask; /* ~ufs_bmask */
77 int64_t ufs_qfmask; /* ~ufs_fmask */
78 };
79 #define fsatoda(u,a) ((a) << (u)->ufs_fsatoda)
80 #define ufs_fragroundup(u,size) /* calculates roundup(size, ufs_fsize) */ \
81 (((size) + (u)->ufs_qfmask) & (u)->ufs_fmask)
82 #define ufs_blkoff(u,loc) /* calculates (loc % u->ufs_bsize) */ \
83 ((loc) & (u)->ufs_qbmask)
84 #define ufs_dblksize(u,d,b) \
85 ((((b) >= UFS_NDADDR || DIP((d), size) >= ((b)+1) << (u)->ufs_bshift \
86 ? (u)->ufs_bsize \
87 : (ufs_fragroundup((u), ufs_blkoff(u, DIP((d), size)))))))
88 struct ufsi *ufsib;
89
90 /*
91 * Dump maps used to describe what is to be dumped.
92 */
93 int mapsize; /* size of the state maps */
94 char *usedinomap; /* map of allocated inodes */
95 char *dumpdirmap; /* map of directories to be dumped */
96 char *dumpinomap; /* map of files to be dumped */
97 /*
98 * Map manipulation macros.
99 */
100 #define SETINO(ino, map) \
101 map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
102 #define CLRINO(ino, map) \
103 map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY))
104 #define TSTINO(ino, map) \
105 (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
106
107 /*
108 * All calculations done in 0.1" units!
109 */
110 char *disk; /* name of the disk file */
111 char *disk_dev; /* name of the raw device we are dumping */
112 const char *tape; /* name of the tape file */
113 const char *dumpdates; /* name of the file containing dump date information*/
114 const char *temp; /* name of the file for doing rewrite of dumpdates */
115 char lastlevel; /* dump level of previous dump */
116 char level; /* dump level of this dump */
117 int uflag; /* update flag */
118 int eflag; /* eject flag */
119 int lflag; /* autoload flag */
120 int diskfd; /* disk file descriptor */
121 int tapefd; /* tape file descriptor */
122 int pipeout; /* true => output to standard output */
123 int trueinc; /* true => "true incremental", i.e use last 9 as ref */
124 ino_t curino; /* current inumber; used globally */
125 int newtape; /* new tape flag */
126 u_int64_t tapesize; /* estimated tape size, blocks */
127 long tsize; /* tape size in 0.1" units */
128 long asize; /* number of 0.1" units written on current tape */
129 int etapes; /* estimated number of tapes */
130 int nonodump; /* if set, do not honor UF_NODUMP user flags */
131 int unlimited; /* if set, write to end of medium */
132
133 extern int density; /* density in 0.1" units */
134 extern int notify; /* notify operator flag */
135 extern int timestamp; /* timestamp messages */
136 extern int blockswritten; /* number of blocks written on current tape */
137 extern int tapeno; /* current tape number */
138 extern int is_ufs2;
139
140 time_t tstart_writing; /* when started writing the first tape block */
141 time_t tstart_volume; /* when started writing the current volume */
142 int xferrate; /* averaged transfer rate of all volumes */
143 char sblock_buf[MAXBSIZE]; /* buffer to hold the superblock */
144 extern long dev_bsize; /* block size of underlying disk device */
145 int dev_bshift; /* log2(dev_bsize) */
146 int tp_bshift; /* log2(TP_BSIZE) */
147 int needswap; /* file system in swapped byte order */
148
149
150 /* some inline functions to help the byte-swapping mess */
151 static inline u_int16_t iswap16(u_int16_t);
152 static inline u_int32_t iswap32(u_int32_t);
153 static inline u_int64_t iswap64(u_int64_t);
154
155 static inline u_int16_t iswap16(u_int16_t x)
156 {
157 if (needswap)
158 return bswap16(x);
159 else
160 return x;
161 }
162
163 static inline u_int32_t iswap32(u_int32_t x)
164 {
165 if (needswap)
166 return bswap32(x);
167 else
168 return x;
169 }
170
171 static inline u_int64_t iswap64(u_int64_t x)
172 {
173 if (needswap)
174 return bswap64(x);
175 else
176 return x;
177 }
178
179 /* filestore-specific hooks */
180 int fs_read_sblock(char *);
181 struct ufsi *fs_parametrize(void);
182 ino_t fs_maxino(void);
183 void fs_mapinodes(ino_t, u_int64_t *, int *);
184
185 /* operator interface functions */
186 void broadcast(const char *);
187 void lastdump(char);
188 void msg(const char *fmt, ...) __printflike(1, 2);
189 void msgtail(const char *fmt, ...) __printflike(1, 2);
190 int query(const char *);
191 void quit(const char *fmt, ...) __printflike(1, 2);
192 time_t do_stats(void);
193 void statussig(int);
194 void timeest(void);
195 time_t unctime(const char *);
196
197 /* mapping routines */
198 union dinode;
199 int64_t blockest(union dinode *);
200 void mapfileino(ino_t, u_int64_t *, int *);
201 int mapfiles(ino_t, u_int64_t *, char *, char * const *);
202 int mapdirs(ino_t, u_int64_t *);
203
204 /* file dumping routines */
205 void blksout32(int32_t *, int, ino_t);
206 void blksout64(int64_t *, int, ino_t);
207 void dumpino(union dinode *, ino_t);
208 #ifndef RRESTORE
209 void dumpmap(char *, int, ino_t);
210 #endif
211 void writeheader(ino_t);
212
213 /* data block caching */
214 void bread(daddr_t, char *, int);
215 void rawread(daddr_t, char *, int);
216 void initcache(int, int);
217 void printcachestats(void);
218
219 /* tape writing routines */
220 int alloctape(void);
221 void close_rewind(void);
222 void dumpblock(daddr_t, int);
223 void startnewtape(int);
224 void trewind(int);
225 void writerec(const char *, int);
226
227 void Exit(int);
228 void dumpabort(int);
229 void getfstab(void);
230
231 char *rawname(char *);
232 union dinode *getino(ino_t);
233
234 void *xcalloc(size_t, size_t);
235 void *xmalloc(size_t);
236 char *xstrdup(const char *);
237
238 /* LFS snapshot hooks */
239 #ifdef DUMP_LFS
240 int lfs_wrap_stop(char *);
241 void lfs_wrap_go(void);
242 #endif
243
244 /* rdump routines */
245 #if defined(RDUMP) || defined(RRESTORE)
246 void rmtclose(void);
247 int rmthost(const char *);
248 int rmtopen(const char *, int, int);
249 int rmtwrite(const char *, int);
250 int rmtioctl(int, int);
251 #endif /* RDUMP || RRESTORE */
252
253 void interrupt(int); /* in case operator bangs on console */
254
255 /*
256 * Exit status codes
257 */
258 #define X_FINOK 0 /* normal exit */
259 #define X_STARTUP 1 /* startup error */
260 #define X_REWRITE 2 /* restart writing from the check point */
261 #define X_ABORT 3 /* abort dump; don't attempt checkpointing */
262
263 #define OPGRENT "operator" /* group entry to notify */
264 #define DIALUP "ttyd" /* prefix for dialups */
265
266 struct fstab *fstabsearch(const char *); /* search fs_file and fs_spec */
267 struct statvfs *mntinfosearch(const char *key);
268
269 #ifndef NAME_MAX
270 #define NAME_MAX 255
271 #endif
272
273 /*
274 * The contents of the file _PATH_DUMPDATES is maintained both on
275 * a linked list, and then (eventually) arrayified.
276 */
277 struct dumpdates {
278 char dd_name[NAME_MAX+3];
279 char dd_level;
280 time_t dd_ddate;
281 };
282
283 extern int nddates; /* number of records (might be zero) */
284 extern struct dumpdates **ddatev; /* the arrayfied version */
285
286 void initdumptimes(void);
287 void getdumptime(void);
288 void putdumptime(void);
289 #define ITITERATE(i, ddp) \
290 if (ddatev != NULL) \
291 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
292
293 void sig(int signo);
294
295 #ifndef _PATH_FSTAB
296 #define _PATH_FSTAB "/etc/fstab"
297 #endif
298