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