]> git.wh0rd.org Git - dump.git/blob - dump/dump.h
QFA support.
[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.23 2001/04/10 12:46:53 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 int     mapsize;        /* size of the state maps */
54 char    *usedinomap;    /* map of allocated inodes */
55 char    *dumpdirmap;    /* map of directories to be dumped */
56 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 const char *disk;               /* name of the disk file */
71 char    tape[MAXPATHLEN];       /* name of the tape file */
72 char    *tapeprefix;    /* prefix of the tape file */
73 char    *dumpdates;     /* name of the file containing dump date information*/
74 char    lastlevel;      /* dump level of previous dump */
75 char    level;          /* dump level of this dump */
76 int     uflag;          /* update flag */
77 int     Mflag;          /* multi-volume flag */
78 char    *eot_script;    /* end of volume script fiag */
79 int     diskfd;         /* disk file descriptor */
80 int     tapefd;         /* tape file descriptor */
81 int     pipeout;        /* true => output to standard output */
82 dump_ino_t curino;      /* current inumber; used globally */
83 int     newtape;        /* new tape flag */
84 int     density;        /* density in 0.1" units */
85 long    tapesize;       /* estimated tape size, blocks */
86 long    tsize;          /* tape size in 0.1" units */
87 long    asize;          /* number of 0.1" units written on current tape */
88 int     etapes;         /* estimated number of tapes */
89 int     nonodump;       /* if set, do not honor UF_NODUMP user flags */
90 int     unlimited;      /* if set, write to end of medium */
91 int     compressed;     /* if set, dump is to be compressed */
92 long long bytes_written;/* total bytes written to tape */
93 long    uncomprblks;    /* uncompressed blocks written to tape */
94 int     notify;         /* notify operator flag */
95 int     blockswritten;  /* number of blocks written on current tape */
96 int     tapeno;         /* current tape number */
97 time_t  tstart_writing; /* when started writing the first tape block */
98 time_t  tend_writing;   /* after writing the last tape block */
99 #ifdef __linux__
100 ext2_filsys fs;
101 #else
102 struct  fs *sblock;     /* the file system super block */
103 char    sblock_buf[MAXBSIZE];
104 #endif
105 long    xferrate;       /* averaged transfer rate of all volumes */
106 long    dev_bsize;      /* block size of underlying disk device */
107 int     dev_bshift;     /* log2(dev_bsize) */
108 int     tp_bshift;      /* log2(TP_BSIZE) */
109
110 #ifdef USE_QFA
111 #define QFA_MAGIC       "495115637697"
112 #define QFA_VERSION     "1.0"
113 int     gTapeposfd;
114 char    *gTapeposfile;
115 char    gTps[255];
116 int     GetTapePos __P((long *pos));
117 #endif /* USE_QFA */
118
119 #ifndef __P
120 #include <sys/cdefs.h>
121 #endif
122
123 /* operator interface functions */
124 void    broadcast __P((const char *message));
125 time_t  do_stats __P((void));
126 void    lastdump __P((char arg));
127 void    msg __P((const char *fmt, ...));
128 void    msgtail __P((const char *fmt, ...));
129 int     query __P((const char *question));
130 void    quit __P((const char *fmt, ...));
131 void    set_operators __P((void));
132 #if defined(SIGINFO)
133 void    statussig __P((int signo));
134 #endif
135 void    timeest __P((void));
136 time_t  unctime __P((const char *str));
137
138 /* mapping rouintes */
139 struct  dinode;
140 long    blockest __P((struct dinode const *dp));
141 int     mapfiles __P((dump_ino_t maxino, long *tapesize));
142 #ifdef  __linux__
143 int     mapfilesfromdir __P((dump_ino_t maxino, long *tapesize, char *directory));
144 #endif
145 int     mapdirs __P((dump_ino_t maxino, long *tapesize));
146
147 /* file dumping routines */
148 void    blksout __P((daddr_t *blkp, int frags, dump_ino_t ino));
149 void    bread __P((daddr_t blkno, char *buf, int size));
150 void    dumpino __P((struct dinode *dp, dump_ino_t ino));
151 #ifdef  __linux__
152 void    dumpdirino __P((struct dinode *dp, dump_ino_t ino));
153 #endif
154 void    dumpmap __P((char *map, int type, dump_ino_t ino));
155 void    writeheader __P((dump_ino_t ino));
156
157 /* tape writing routines */
158 int     alloctape __P((void));
159 void    close_rewind __P((void));
160 void    dumpblock __P((daddr_t blkno, int size));
161 void    startnewtape __P((int top));
162 time_t  trewind __P((void));
163 void    writerec __P((const void *dp, int isspcl));
164 char    *mktimeest __P((time_t tnow));
165
166 void    Exit __P((int status));
167 void    dumpabort __P((int signo));
168 void    getfstab __P((void));
169
170 const char *rawname __P((const char *cp));
171 struct  dinode *getino __P((dump_ino_t inum));
172
173 /* rdump routines */
174 #ifdef RDUMP
175 int     rmthost __P((const char *host));
176 int     rmtopen __P((const char *tape, int mode));
177 void    rmtclose __P((void));
178 int     rmtread __P((char *buf, size_t count));
179 int     rmtwrite __P((const char *buf, size_t count));
180 int     rmtseek __P((int offset, int pos));
181 struct mtget * rmtstatus __P((void));
182 int     rmtioctl __P((int cmd, int count));
183 #endif /* RDUMP */
184
185 void    interrupt __P((int signo));     /* in case operator bangs on console */
186
187 /*
188  *      Exit status codes
189  */
190 #define X_FINOK         0       /* normal exit */
191 #define X_STARTUP       1       /* startup error */
192 #define X_REWRITE       2       /* restart writing from the check point */
193 #define X_ABORT         3       /* abort dump; don't attempt checkpointing */
194
195 #define OPGRENT "operator"              /* group entry to notify */
196 #ifdef  __linux__
197 #define DIALUP  "ttyS"                  /* prefix for dialups */
198 #else
199 #define DIALUP  "ttyd"                  /* prefix for dialups */
200 #endif
201
202 struct  fstab *fstabsearch __P((const char *key));      /* search fs_file and fs_spec */
203 #ifdef  __linux__
204 struct  fstab *fstabsearchdir __P((const char *key, char *dir));        /* search fs_file and fs_spec */
205 #endif
206
207 /*
208  *      The contents of the file _PATH_DUMPDATES is maintained both on
209  *      a linked list, and then (eventually) arrayified.
210  */
211 struct dumpdates {
212         char    dd_name[MAXPATHLEN+3];
213         struct fstab *dd_fstab;
214         char    dd_level;
215         time_t  dd_ddate;
216 };
217 struct dumptime {
218         struct  dumpdates dt_value;
219         struct  dumptime *dt_next;
220 };
221 struct  dumptime *dthead;       /* head of the list version */
222 int     nddates;                /* number of records (might be zero) */
223 int     ddates_in;              /* we have read the increment file */
224 struct  dumpdates **ddatev;     /* the arrayfied version */
225 void    initdumptimes __P((int));
226 void    getdumptime __P((int));
227 void    putdumptime __P((void));
228 #define ITITERATE(i, ddp) \
229         for (ddp = ddatev[i = 0]; i < nddates; ddp = ddatev[++i])
230
231 void    sig __P((int signo));
232
233 /*
234  * Compatibility with old systems.
235  */
236 #ifdef COMPAT
237 #include <sys/file.h>
238 #define strchr(a,b)     index(a,b)
239 #define strrchr(a,b)    rindex(a,b)
240 extern char *strdup(), *ctime();
241 extern int read(), write();
242 extern int errno;
243 #endif
244
245 #ifdef  __linux__
246 #define DUMP_CURRENT_REV        1
247
248 int dump_fs_open(const char *disk, ext2_filsys *fs);
249 #endif
250
251 #ifndef __linux__
252 #ifndef _PATH_UTMP
253 #define _PATH_UTMP      "/etc/utmp"
254 #endif
255 #ifndef _PATH_FSTAB
256 #define _PATH_FSTAB     "/etc/fstab"
257 #endif
258 #endif
259
260 #ifdef sunos
261 extern char *calloc();
262 extern char *malloc();
263 extern long atol();
264 extern char *strcpy();
265 extern char *strncpy();
266 extern char *strcat();
267 extern time_t time();
268 extern void endgrent();
269 extern void exit();
270 extern off_t lseek();
271 extern const char *strerror();
272 #endif
273
274                                 /* 04-Feb-00 ILC */
275 #define IEXCLUDE_MAXNUM 256     /* max size of inode exclude list */
276