]> git.wh0rd.org - dump.git/blob - restore/restore.h
4f5236f4ac7466c17bbe8bf3c01a4c959db5e6df
[dump.git] / restore / restore.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: restore.h,v 1.32 2005/05/02 15:10:46 stelian Exp $
9 */
10
11 /*
12 * Copyright (c) 1983, 1993
13 * The Regents of the University of California. All rights reserved.
14 * (c) UNIX System Laboratories, Inc.
15 * All or some portions of this file are derived from material licensed
16 * to the University of California by American Telephone and Telegraph
17 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
18 * the permission of UNIX System Laboratories, Inc.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * 3. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 */
44
45 #include <config.h>
46 #include <protocols/dumprestore.h>
47 /*
48 * Flags
49 */
50 extern int aflag; /* automatic volume increment */
51 extern char *Afile; /* archive file */
52 extern int cvtflag; /* convert from old to new tape format */
53 extern int bflag; /* set input block size */
54 extern int dflag; /* print out debugging info */
55 extern int hflag; /* restore heirarchies */
56 extern int lflag; /* assume remote filename is a regular file */
57 extern int Lflag; /* compare errors limit */
58 extern int mflag; /* restore by name instead of inode number */
59 extern int Mflag; /* multi-volume restore */
60 extern int oflag; /* do restore permissions without asking */
61 extern int Vflag; /* multi-volume on a single device like CDROM */
62 extern int Nflag; /* do not write the disk */
63 extern int uflag; /* unlink symlink targets */
64 extern int vflag; /* print out actions taken */
65 extern int yflag; /* always try to recover from tape errors */
66 extern int zflag; /* tape is in compressed format */
67 extern int ufs2flag; /* tape is a FreeBSD UFS2 dump */
68 extern char* bot_script; /* beginning of tape script */
69 /*
70 * Global variables
71 */
72 extern char *host; /* name of the remote host */
73 extern char *dumpmap; /* map of inodes on this dump tape */
74 extern char *usedinomap; /* map of inodes that are in use on this fs */
75 extern dump_ino_t maxino; /* highest numbered inode in this file system */
76 extern long dumpnum; /* location of the dump on this tape */
77 extern long volno; /* current volume being read */
78 extern long ntrec; /* number of TP_BSIZE records per tape block */
79 extern time_t dumptime; /* time that this dump begins */
80 extern time_t dumpdate; /* time that this dump was made */
81 extern char command; /* opration being performed */
82 extern FILE *terminal; /* file descriptor for the terminal input */
83 extern int pipein; /* input is from a pipe */
84 extern char *tmpdir; /* name of temp directory */
85 extern int oldinofmt; /* reading tape with old format inodes */
86 extern int Bcvt; /* need byte swapping on inodes and dirs */
87 extern int compare_ignore_not_found;
88 /* used to compare incremental dumps, */
89 /* so messages about "not found" files */
90 /* isn't seen. */
91 extern int compare_errors; /* did we encounter any compare errors? */
92 extern char filesys[NAMELEN];/* name of dumped filesystem */
93 extern dump_ino_t volinfo[]; /* which inode on which volume archive info */
94 extern int wdfd; /* original working directory */
95
96 #define DIRHASH_SIZE 1024
97
98 /*
99 * Each file in the file system is described by one of these entries
100 */
101 struct entry {
102 char *e_name; /* the current name of this entry */
103 u_char e_namlen; /* length of this name */
104 char e_type; /* type of this entry, see below */
105 short e_flags; /* status flags, see below */
106 dump_ino_t e_ino; /* inode number in previous file sys */
107 long e_index; /* unique index (for dumpped table) */
108 struct entry *e_parent; /* pointer to parent directory (..) */
109 struct entry *e_sibling; /* next element in this directory (.) */
110 struct entry *e_links; /* hard links to this inode */
111 struct entry **e_entries; /* for directories, their entries */
112 struct entry *e_next; /* hash chain list */
113 };
114 /* types */
115 #define LEAF 1 /* non-directory entry */
116 #define NODE 2 /* directory entry */
117 #define LINK 4 /* synthesized type, stripped by addentry */
118 /* flags */
119 #define EXTRACT 0x0001 /* entry is to be replaced from the tape */
120 #define NEW 0x0002 /* a new entry to be extracted */
121 #define KEEP 0x0004 /* entry is not to change */
122 #define REMOVED 0x0010 /* entry has been removed */
123 #define TMPNAME 0x0020 /* entry has been given a temporary name */
124 #define EXISTED 0x0040 /* directory already existed during extract */
125
126 /*
127 * Constants associated with entry structs
128 */
129 #define HARDLINK 1
130 #define SYMLINK 2
131 #define TMPHDR "RSTTMP"
132
133 /*
134 * The entry describes the next file available on the tape
135 */
136 struct context {
137 char *name; /* name of file */
138 dump_ino_t ino; /* inumber of file */
139 #if defined(__linux__) || defined(sunos)
140 struct new_bsd_inode *dip; /* pointer to inode */
141 #else
142 struct dinode *dip; /* pointer to inode */
143 #endif
144 char action; /* action being taken on this file */
145 } curfile;
146 /* actions */
147 #define USING 1 /* extracting from the tape */
148 #define SKIP 2 /* skipping */
149 #define UNKNOWN 3 /* disposition or starting point is unknown */
150
151 /*
152 * Definitions for library routines operating on directories.
153 */
154 typedef struct rstdirdesc RST_DIR;
155
156 /*
157 * Flags to setdirmodes.
158 */
159 #define FORCE 0x0001
160
161 /*
162 * Useful macros
163 */
164 #define TSTINO(ino, map) \
165 (map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
166 #define SETINO(ino, map) \
167 map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
168
169 #define Dprintf if (dflag) fprintf
170 #define Vprintf if (vflag) fprintf
171
172 #define GOOD 1
173 #define FAIL 0
174
175 #ifdef USE_QFA
176 #define QFA_MAGIC "495115637697"
177 #define QFA_VERSION "1.0"
178 extern FILE *gTapeposfp;
179 extern char *gTapeposfile;
180 extern char gTps[255];
181 extern long gSeekstart;
182 extern int tapeposflag;
183 extern int gTapeposfd;
184 extern int createtapeposflag;
185 extern unsigned long qfadumpdate;
186 extern long long curtapepos;
187 #ifdef sunos
188 int fdsmtc;
189 long scsiid;
190 char smtcpath[2048];
191 #endif
192 #endif /* USE_QFA */
193
194 #define do_compare_error \
195 if (++compare_errors >= Lflag && Lflag) { \
196 printf("Compare errors limit reached, exiting...\n"); \
197 exit(2); \
198 }
199
200 #define XATTR_MAXSIZE 4096