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