dump.h revision 1.26 1 1.26 lukem /* $NetBSD: dump.h,v 1.26 2001/05/27 14:17:56 lukem Exp $ */
2 1.9 cgd
3 1.1 cgd /*-
4 1.7 mycroft * Copyright (c) 1980, 1993
5 1.7 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd *
35 1.13 lukem * @(#)dump.h 8.2 (Berkeley) 4/28/95
36 1.1 cgd */
37 1.15 bouyer
38 1.15 bouyer #include <machine/bswap.h>
39 1.1 cgd
40 1.1 cgd #define MAXINOPB (MAXBSIZE / sizeof(struct dinode))
41 1.1 cgd #define MAXNINDIR (MAXBSIZE / sizeof(daddr_t))
42 1.1 cgd
43 1.1 cgd /*
44 1.19 perseant * Filestore-independent UFS data, so code can be more easily shared
45 1.19 perseant * between ffs, lfs, and maybe ext2fs and others as well.
46 1.19 perseant */
47 1.19 perseant struct ufsi {
48 1.19 perseant int64_t ufs_dsize; /* filesystem size, in sectors */
49 1.19 perseant int32_t ufs_bsize; /* block size */
50 1.19 perseant int32_t ufs_bshift; /* log2(ufs_bsize) */
51 1.19 perseant int32_t ufs_fsize; /* fragment size */
52 1.19 perseant int32_t ufs_frag; /* block size / frag size */
53 1.19 perseant int32_t ufs_fsatoda; /* disk address conversion constant */
54 1.19 perseant int32_t ufs_nindir; /* disk addresses per indirect block */
55 1.19 perseant int32_t ufs_inopb; /* inodes per block */
56 1.19 perseant int32_t ufs_maxsymlinklen; /* max symlink length */
57 1.19 perseant int32_t ufs_bmask; /* block mask */
58 1.19 perseant int32_t ufs_fmask; /* frag mask */
59 1.19 perseant int64_t ufs_qbmask; /* ~ufs_bmask */
60 1.19 perseant int64_t ufs_qfmask; /* ~ufs_fmask */
61 1.19 perseant };
62 1.19 perseant #define fsatoda(u,a) ((a) << (u)->ufs_fsatoda)
63 1.19 perseant #define ufs_fragroundup(u,size) /* calculates roundup(size, ufs_fsize) */ \
64 1.19 perseant (((size) + (u)->ufs_qfmask) & (u)->ufs_fmask)
65 1.19 perseant #define ufs_blkoff(u,loc) /* calculates (loc % u->ufs_bsize) */ \
66 1.19 perseant ((loc) & (u)->ufs_qbmask)
67 1.19 perseant #define ufs_dblksize(u,d,b) \
68 1.19 perseant ((((b) >= NDADDR || (d)->di_size >= ((b)+1) << (u)->ufs_bshift \
69 1.19 perseant ? (u)->ufs_bsize \
70 1.19 perseant : (ufs_fragroundup((u), ufs_blkoff(u, (d)->di_size))))))
71 1.19 perseant struct ufsi *ufsib;
72 1.19 perseant
73 1.19 perseant /*
74 1.1 cgd * Dump maps used to describe what is to be dumped.
75 1.1 cgd */
76 1.1 cgd int mapsize; /* size of the state maps */
77 1.1 cgd char *usedinomap; /* map of allocated inodes */
78 1.1 cgd char *dumpdirmap; /* map of directories to be dumped */
79 1.1 cgd char *dumpinomap; /* map of files to be dumped */
80 1.1 cgd /*
81 1.1 cgd * Map manipulation macros.
82 1.1 cgd */
83 1.1 cgd #define SETINO(ino, map) \
84 1.1 cgd map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
85 1.1 cgd #define CLRINO(ino, map) \
86 1.1 cgd map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY))
87 1.1 cgd #define TSTINO(ino, map) \
88 1.1 cgd (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
89 1.1 cgd
90 1.1 cgd /*
91 1.1 cgd * All calculations done in 0.1" units!
92 1.1 cgd */
93 1.1 cgd char *disk; /* name of the disk file */
94 1.1 cgd char *tape; /* name of the tape file */
95 1.1 cgd char *dumpdates; /* name of the file containing dump date information*/
96 1.1 cgd char *temp; /* name of the file for doing rewrite of dumpdates */
97 1.1 cgd char lastlevel; /* dump level of previous dump */
98 1.1 cgd char level; /* dump level of this dump */
99 1.1 cgd int uflag; /* update flag */
100 1.24 tron int eflag; /* eject flag */
101 1.1 cgd int diskfd; /* disk file descriptor */
102 1.1 cgd int tapefd; /* tape file descriptor */
103 1.1 cgd int pipeout; /* true => output to standard output */
104 1.1 cgd ino_t curino; /* current inumber; used globally */
105 1.1 cgd int newtape; /* new tape flag */
106 1.1 cgd long tapesize; /* estimated tape size, blocks */
107 1.1 cgd long tsize; /* tape size in 0.1" units */
108 1.1 cgd long asize; /* number of 0.1" units written on current tape */
109 1.1 cgd int etapes; /* estimated number of tapes */
110 1.7 mycroft int nonodump; /* if set, do not honor UF_NODUMP user flags */
111 1.1 cgd
112 1.22 christos extern int density; /* density in 0.1" units */
113 1.22 christos extern int notify; /* notify operator flag */
114 1.22 christos extern int blockswritten; /* number of blocks written on current tape */
115 1.22 christos extern int tapeno; /* current tape number */
116 1.22 christos
117 1.1 cgd time_t tstart_writing; /* when started writing the first tape block */
118 1.10 lukem int xferrate; /* averaged transfer rate of all volumes */
119 1.19 perseant char sblock_buf[MAXBSIZE]; /* buffer to hold the superblock */
120 1.21 scw extern long dev_bsize; /* block size of underlying disk device */
121 1.1 cgd int dev_bshift; /* log2(dev_bsize) */
122 1.1 cgd int tp_bshift; /* log2(TP_BSIZE) */
123 1.14 bouyer int needswap; /* file system in swapped byte order */
124 1.14 bouyer /* some inline functs to help the byte-swapping mess */
125 1.26 lukem static __inline u_int16_t iswap16(u_int16_t);
126 1.26 lukem static __inline u_int32_t iswap32(u_int32_t);
127 1.26 lukem static __inline u_int64_t iswap64(u_int64_t);
128 1.26 lukem
129 1.26 lukem static __inline u_int16_t iswap16(u_int16_t x)
130 1.26 lukem {
131 1.14 bouyer if (needswap)
132 1.14 bouyer return bswap16(x);
133 1.26 lukem else
134 1.26 lukem return x;
135 1.14 bouyer }
136 1.14 bouyer
137 1.26 lukem static __inline u_int32_t iswap32(u_int32_t x)
138 1.14 bouyer {
139 1.14 bouyer if (needswap)
140 1.14 bouyer return bswap32(x);
141 1.26 lukem else
142 1.26 lukem return x;
143 1.14 bouyer }
144 1.14 bouyer
145 1.26 lukem static __inline u_int64_t iswap64(u_int64_t x)
146 1.14 bouyer {
147 1.14 bouyer if (needswap)
148 1.14 bouyer return bswap64(x);
149 1.26 lukem else
150 1.26 lukem return x;
151 1.26 lukem }
152 1.19 perseant
153 1.19 perseant /* filestore-specific hooks */
154 1.26 lukem int fs_read_sblock(char *);
155 1.26 lukem struct ufsi *fs_parametrize(void);
156 1.26 lukem ino_t fs_maxino(void);
157 1.7 mycroft
158 1.1 cgd /* operator interface functions */
159 1.26 lukem void broadcast(char *);
160 1.26 lukem void lastdump(char);
161 1.26 lukem void msg(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
162 1.26 lukem void msgtail(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
163 1.26 lukem int query(char *);
164 1.26 lukem void quit(const char *fmt, ...) __attribute__((__format__(__printf__,1,2)));
165 1.26 lukem void set_operators(void);
166 1.26 lukem time_t do_stats(void);
167 1.26 lukem void statussig(int);
168 1.26 lukem void timeest(void);
169 1.26 lukem time_t unctime(char *);
170 1.1 cgd
171 1.10 lukem /* mapping routines */
172 1.6 cgd struct dinode;
173 1.26 lukem long blockest(struct dinode *);
174 1.26 lukem void mapfileino(ino_t, long *, int *);
175 1.26 lukem int mapfiles(ino_t, long *, char *, char * const *);
176 1.26 lukem int mapdirs(ino_t, long *);
177 1.1 cgd
178 1.1 cgd /* file dumping routines */
179 1.26 lukem void blksout(daddr_t *, int, ino_t);
180 1.26 lukem void dumpino(struct dinode *, ino_t);
181 1.26 lukem void dumpmap(char *, int, ino_t);
182 1.26 lukem void writeheader(ino_t);
183 1.16 bouyer
184 1.16 bouyer /* data block caching */
185 1.26 lukem void bread(daddr_t, char *, int);
186 1.26 lukem void rawread(daddr_t, char *, int);
187 1.26 lukem void initcache(int, int);
188 1.26 lukem void printcachestats(void);
189 1.1 cgd
190 1.1 cgd /* tape writing routines */
191 1.26 lukem int alloctape(void);
192 1.26 lukem void close_rewind(void);
193 1.26 lukem void dumpblock(daddr_t, int);
194 1.26 lukem void startnewtape(int);
195 1.26 lukem void trewind(int);
196 1.26 lukem void writerec(char *, int);
197 1.26 lukem
198 1.26 lukem void Exit(int);
199 1.26 lukem void dumpabort(int);
200 1.26 lukem void getfstab(void);
201 1.1 cgd
202 1.26 lukem char *rawname(char *);
203 1.26 lukem struct dinode *getino(ino_t);
204 1.1 cgd
205 1.7 mycroft /* rdump routines */
206 1.23 christos #if defined(RDUMP) || defined(RRESTORE)
207 1.26 lukem void rmtclose(void);
208 1.26 lukem int rmthost(char *);
209 1.26 lukem int rmtopen(char *, int);
210 1.26 lukem int rmtwrite(char *, int);
211 1.23 christos #endif /* RDUMP || RRESTORE */
212 1.7 mycroft
213 1.26 lukem void interrupt(int); /* in case operator bangs on console */
214 1.1 cgd
215 1.1 cgd /*
216 1.1 cgd * Exit status codes
217 1.1 cgd */
218 1.1 cgd #define X_FINOK 0 /* normal exit */
219 1.1 cgd #define X_REWRITE 2 /* restart writing from the check point */
220 1.6 cgd #define X_ABORT 3 /* abort dump; don't attempt checkpointing */
221 1.1 cgd
222 1.1 cgd #define OPGRENT "operator" /* group entry to notify */
223 1.1 cgd #define DIALUP "ttyd" /* prefix for dialups */
224 1.1 cgd
225 1.26 lukem struct fstab *fstabsearch(char *); /* search fs_file and fs_spec */
226 1.6 cgd
227 1.6 cgd #ifndef NAME_MAX
228 1.6 cgd #define NAME_MAX 255
229 1.6 cgd #endif
230 1.1 cgd
231 1.1 cgd /*
232 1.1 cgd * The contents of the file _PATH_DUMPDATES is maintained both on
233 1.1 cgd * a linked list, and then (eventually) arrayified.
234 1.1 cgd */
235 1.1 cgd struct dumpdates {
236 1.6 cgd char dd_name[NAME_MAX+3];
237 1.1 cgd char dd_level;
238 1.1 cgd time_t dd_ddate;
239 1.1 cgd };
240 1.1 cgd struct dumptime {
241 1.1 cgd struct dumpdates dt_value;
242 1.1 cgd struct dumptime *dt_next;
243 1.1 cgd };
244 1.22 christos
245 1.22 christos extern struct dumptime *dthead; /* head of the list version */
246 1.22 christos extern int nddates; /* number of records (might be zero) */
247 1.22 christos extern int ddates_in; /* we have read the increment file */
248 1.22 christos extern struct dumpdates **ddatev; /* the arrayfied version */
249 1.22 christos
250 1.26 lukem void initdumptimes(void);
251 1.26 lukem void getdumptime(void);
252 1.26 lukem void putdumptime(void);
253 1.1 cgd #define ITITERATE(i, ddp) \
254 1.6 cgd for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
255 1.1 cgd
256 1.26 lukem void sig(int signo);
257 1.1 cgd
258 1.1 cgd /*
259 1.1 cgd * Compatibility with old systems.
260 1.1 cgd */
261 1.7 mycroft #ifdef COMPAT
262 1.1 cgd #include <sys/file.h>
263 1.8 mycroft #define strchr(a,b) index(a,b)
264 1.8 mycroft #define strrchr(a,b) rindex(a,b)
265 1.8 mycroft extern char *strdup(), *ctime();
266 1.7 mycroft extern int read(), write();
267 1.1 cgd extern int errno;
268 1.6 cgd #endif
269 1.6 cgd
270 1.7 mycroft #ifndef _PATH_UTMP
271 1.7 mycroft #define _PATH_UTMP "/etc/utmp"
272 1.7 mycroft #endif
273 1.7 mycroft #ifndef _PATH_FSTAB
274 1.7 mycroft #define _PATH_FSTAB "/etc/fstab"
275 1.1 cgd #endif
276