]> git.wh0rd.org - dump.git/blob - dump/dump.h
Added bzip2 compression to dump.
[dump.git] / dump / dump.h
1 /*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <pop@noos.fr>, 1999-2000
6 * Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
7 *
8 * $Id: dump.h,v 1.32 2001/08/16 15:24:21 stelian Exp $
9 */
10
11 /*-
12 * Copyright (c) 1980, 1993
13 * The Regents of the University of California. All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by the University of
26 * California, Berkeley and its contributors.
27 * 4. Neither the name of the University nor the names of its contributors
28 * may be used to endorse or promote products derived from this software
29 * without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * SUCH DAMAGE.
42 */
43
44 #include <config.h>
45 #include <protocols/dumprestore.h>
46
47 #define MAXINOPB (MAXBSIZE / sizeof(struct dinode))
48 #define MAXNINDIR (MAXBSIZE / sizeof(daddr_t))
49
50 /*
51 * Dump maps used to describe what is to be dumped.
52 */
53 extern int mapsize; /* size of the state maps */
54 extern char *usedinomap; /* map of allocated inodes */
55 extern char *dumpdirmap; /* map of directories to be dumped */
56 extern char *dumpinomap; /* map of files to be dumped */
57 /*
58 * Map manipulation macros.
59 */
60 #define SETINO(ino, map) \
61 map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
62 #define CLRINO(ino, map) \
63 map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY))
64 #define TSTINO(ino, map) \
65 (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
66
67 /*
68 * All calculations done in 0.1" units!
69 */
70 extern const char *disk; /* name of the disk file */
71 extern char tape[MAXPATHLEN];/* name of the tape file */
72 extern char *tapeprefix; /* prefix of the tape file */
73 extern char *dumpdates; /* name of the file containing dump date information*/
74 extern char lastlevel; /* dump level of previous dump */
75 extern char level; /* dump level of this dump */
76 extern int bzipflag; /* compression is done using bzlib */
77 extern int uflag; /* update flag */
78 extern int Mflag; /* multi-volume flag */
79 extern int qflag; /* quit on errors flag */
80 extern char *eot_script; /* end of volume script fiag */
81 extern int diskfd; /* disk file descriptor */
82 extern int tapefd; /* tape file descriptor */
83 extern int pipeout; /* true => output to standard output */
84 extern int fifoout; /* true => output to fifo */
85 extern dump_ino_t curino; /* current inumber; used globally */
86 extern int newtape; /* new tape flag */
87 extern int density; /* density in 0.1" units */
88 extern long tapesize; /* estimated tape size, blocks */
89 extern long tsize; /* tape size in 0.1" units */
90 extern long asize; /* number of 0.1" units written on current tape */
91 extern int etapes; /* estimated number of tapes */
92 extern int nonodump; /* if set, do not honor UF_NODUMP user flags */
93 extern int unlimited; /* if set, write to end of medium */
94 extern int compressed; /* if set, dump is to be compressed */
95 extern long long bytes_written;/* total bytes written to tape */
96 extern long uncomprblks; /* uncompressed blocks written to tape */
97 extern int notify; /* notify operator flag */
98 extern int blockswritten; /* number of blocks written on current tape */
99 extern int tapeno; /* current tape number */
100 extern time_t tstart_writing; /* when started writing the first tape block */
101 extern time_t tend_writing; /* after writing the last tape block */
102 #ifdef __linux__
103 extern ext2_filsys fs;
104 #else
105 extern struct fs *sblock; /* the file system super block */
106 extern char sblock_buf[MAXBSIZE];
107 #endif
108 extern long xferrate; /* averaged transfer rate of all volumes */
109 extern long dev_bsize; /* block size of underlying disk device */
110 extern int dev_bshift; /* log2(dev_bsize) */
111 extern int tp_bshift; /* log2(TP_BSIZE) */
112
113 #ifdef USE_QFA
114 #define QFA_MAGIC "495115637697"
115 #define QFA_VERSION "1.0"
116 extern int gTapeposfd;
117 extern char *gTapeposfile;
118 extern char gTps[255];
119 extern int32_t gThisDumpDate;
120 int GetTapePos __P((long *pos));
121 #endif /* USE_QFA */
122
123 #ifndef __P
124 #include <sys/cdefs.h>
125 #endif
126
127 /* operator interface functions */
128 void broadcast __P((const char *message));
129 time_t do_stats __P((void));
130 void lastdump __P((char arg));
131 void msg __P((const char *fmt, ...));
132 void msgtail __P((const char *fmt, ...));
133 int query __P((const char *question));
134 void quit __P((const char *fmt, ...));
135 void set_operators __P((void));
136 #if defined(SIGINFO)
137 void statussig __P((int signo));
138 #endif
139 void timeest __P((void));
140 time_t unctime __P((const char *str));
141
142 /* mapping rouintes */
143 struct dinode;
144 long blockest __P((struct dinode const *dp));
145 int mapfiles __P((dump_ino_t maxino, long *tapesize));
146 #ifdef __linux__
147 int mapfilesfromdir __P((dump_ino_t maxino, long *tapesize, char *directory));
148 int maponefile __P((dump_ino_t maxino, long *tapesize, char *directory));
149 #endif
150 int mapdirs __P((dump_ino_t maxino, long *tapesize));
151
152 /* file dumping routines */
153 void blksout __P((daddr_t *blkp, int frags, dump_ino_t ino));
154 void bread __P((daddr_t blkno, char *buf, int size));
155 void dumpino __P((struct dinode *dp, dump_ino_t ino));
156 #ifdef __linux__
157 void dumpdirino __P((struct dinode *dp, dump_ino_t ino));
158 #endif
159 void dumpmap __P((char *map, int type, dump_ino_t ino));
160 void writeheader __P((dump_ino_t ino));
161
162 /* tape writing routines */
163 int alloctape __P((void));
164 void close_rewind __P((void));
165 void dumpblock __P((daddr_t blkno, int size));
166 void startnewtape __P((int top));
167 time_t trewind __P((void));
168 void writerec __P((const void *dp, int isspcl));
169 char *mktimeest __P((time_t tnow));
170
171 void Exit __P((int status));
172 void dumpabort __P((int signo));
173 void getfstab __P((void));
174
175 const char *rawname __P((const char *cp));
176 struct dinode *getino __P((dump_ino_t inum));
177
178 /* rdump routines */
179 #ifdef RDUMP
180 int rmthost __P((const char *host));
181 int rmtopen __P((const char *tape, int mode));
182 void rmtclose __P((void));
183 int rmtread __P((char *buf, size_t count));
184 int rmtwrite __P((const char *buf, size_t count));
185 int rmtseek __P((int offset, int pos));
186 struct mtget * rmtstatus __P((void));
187 int rmtioctl __P((int cmd, int count));
188 #endif /* RDUMP */
189
190 void interrupt __P((int signo)); /* in case operator bangs on console */
191 int exclude_ino __P((dump_ino_t ino));
192 void do_exclude_ino __P((dump_ino_t ino, const char *));
193
194 /*
195 * Exit status codes
196 */
197 #define X_FINOK 0 /* normal exit */
198 #define X_STARTUP 1 /* startup error */
199 #define X_REWRITE 2 /* restart writing from the check point */
200 #define X_ABORT 3 /* abort dump; don't attempt checkpointing */
201
202 #define OPGRENT "operator" /* group entry to notify */
203 #ifdef __linux__
204 #define DIALUP "ttyS" /* prefix for dialups */
205 #else
206 #define DIALUP "ttyd" /* prefix for dialups */
207 #endif
208
209 struct fstab *fstabsearch __P((const char *key)); /* search fs_file and fs_spec */
210 #ifdef __linux__
211 struct fstab *fstabsearchdir __P((const char *key, char *dir)); /* search fs_file and fs_spec */
212 #endif
213
214 /*
215 * The contents of the file _PATH_DUMPDATES is maintained both on
216 * a linked list, and then (eventually) arrayified.
217 */
218 struct dumpdates {
219 char dd_name[MAXPATHLEN+3];
220 struct fstab *dd_fstab;
221 char dd_level;
222 time_t dd_ddate;
223 };
224 struct dumptime {
225 struct dumpdates dt_value;
226 struct dumptime *dt_next;
227 };
228 extern struct dumptime *dthead; /* head of the list version */
229 extern int nddates; /* number of records (might be zero) */
230 extern int ddates_in; /* we have read the increment file */
231 extern struct dumpdates **ddatev; /* the arrayfied version */
232 void initdumptimes __P((int));
233 void getdumptime __P((int));
234 void putdumptime __P((void));
235 #define ITITERATE(i, ddp) \
236 for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
237
238 void sig __P((int signo));
239
240 /*
241 * Compatibility with old systems.
242 */
243 #ifdef COMPAT
244 #include <sys/file.h>
245 #define strchr(a,b) index(a,b)
246 #define strrchr(a,b) rindex(a,b)
247 extern char *strdup(), *ctime();
248 extern int read(), write();
249 extern int errno;
250 #endif
251
252 #ifdef __linux__
253 #define DUMP_CURRENT_REV 1
254
255 int dump_fs_open(const char *disk, ext2_filsys *fs);
256 #endif
257
258 #ifndef __linux__
259 #ifndef _PATH_UTMP
260 #define _PATH_UTMP "/etc/utmp"
261 #endif
262 #ifndef _PATH_FSTAB
263 #define _PATH_FSTAB "/etc/fstab"
264 #endif
265 #endif
266
267 #ifdef sunos
268 extern char *calloc();
269 extern char *malloc();
270 extern long atol();
271 extern char *strcpy();
272 extern char *strncpy();
273 extern char *strcat();
274 extern time_t time();
275 extern void endgrent();
276 extern void exit();
277 extern off_t lseek();
278 extern const char *strerror();
279 #endif
280
281 /* 04-Feb-00 ILC */
282 #define IEXCLUDE_MAXNUM 256 /* max size of inode exclude list */
283