Commit | Line | Data |
---|---|---|
c2714ef5 | 1 | /* |
2 | * Copyright (c) UNIX System Laboratories, Inc. All or some portions | |
3 | * of this file are derived from material licensed to the | |
4 | * University of California by American Telephone and Telegraph Co. | |
5 | * or UNIX System Laboratories, Inc. and are reproduced herein with | |
6 | * the permission of UNIX System Laboratories, Inc. | |
7 | * | |
8 | * $Id$ | |
9 | */ | |
15637ed4 RG |
10 | /* |
11 | * Copyright (c) 1983 The Regents of the University of California. | |
12 | * All rights reserved. | |
13 | * | |
14 | * Redistribution and use in source and binary forms, with or without | |
15 | * modification, are permitted provided that the following conditions | |
16 | * are met: | |
17 | * 1. Redistributions of source code must retain the above copyright | |
18 | * notice, this list of conditions and the following disclaimer. | |
19 | * 2. Redistributions in binary form must reproduce the above copyright | |
20 | * notice, this list of conditions and the following disclaimer in the | |
21 | * documentation and/or other materials provided with the distribution. | |
22 | * 3. All advertising materials mentioning features or use of this software | |
23 | * must display the following acknowledgement: | |
24 | * This product includes software developed by the University of | |
25 | * California, Berkeley and its contributors. | |
26 | * 4. Neither the name of the University nor the names of its contributors | |
27 | * may be used to endorse or promote products derived from this software | |
28 | * without specific prior written permission. | |
29 | * | |
30 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
31 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
36 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
37 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
39 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
40 | * SUCH DAMAGE. | |
41 | * | |
42 | * @(#)restore.h 5.8 (Berkeley) 6/1/90 | |
43 | */ | |
44 | ||
45 | #include <stdio.h> | |
46 | #include <sys/param.h> | |
47 | #include <sys/time.h> | |
48 | #include <ufs/dinode.h> | |
49 | #include <ufs/fs.h> | |
50 | ||
51 | /* | |
52 | * Flags | |
53 | */ | |
54 | extern int cvtflag; /* convert from old to new tape format */ | |
55 | extern int bflag; /* set input block size */ | |
56 | extern int dflag; /* print out debugging info */ | |
57 | extern int hflag; /* restore heirarchies */ | |
58 | extern int mflag; /* restore by name instead of inode number */ | |
59 | extern int Nflag; /* do not write the disk */ | |
60 | extern int vflag; /* print out actions taken */ | |
61 | extern int yflag; /* always try to recover from tape errors */ | |
62 | /* | |
63 | * Global variables | |
64 | */ | |
65 | extern char *dumpmap; /* map of inodes on this dump tape */ | |
66 | extern char *clrimap; /* map of inodes to be deleted */ | |
67 | extern ino_t maxino; /* highest numbered inode in this file system */ | |
68 | extern long dumpnum; /* location of the dump on this tape */ | |
69 | extern long volno; /* current volume being read */ | |
70 | extern long ntrec; /* number of TP_BSIZE records per tape block */ | |
71 | extern time_t dumptime; /* time that this dump begins */ | |
72 | extern time_t dumpdate; /* time that this dump was made */ | |
73 | extern char command; /* opration being performed */ | |
74 | extern FILE *terminal; /* file descriptor for the terminal input */ | |
75 | ||
76 | /* | |
77 | * Each file in the file system is described by one of these entries | |
78 | */ | |
79 | struct entry { | |
80 | char *e_name; /* the current name of this entry */ | |
81 | u_char e_namlen; /* length of this name */ | |
82 | char e_type; /* type of this entry, see below */ | |
83 | short e_flags; /* status flags, see below */ | |
84 | ino_t e_ino; /* inode number in previous file sys */ | |
85 | long e_index; /* unique index (for dumpped table) */ | |
86 | struct entry *e_parent; /* pointer to parent directory (..) */ | |
87 | struct entry *e_sibling; /* next element in this directory (.) */ | |
88 | struct entry *e_links; /* hard links to this inode */ | |
89 | struct entry *e_entries; /* for directories, their entries */ | |
90 | struct entry *e_next; /* hash chain list */ | |
91 | }; | |
92 | /* types */ | |
93 | #define LEAF 1 /* non-directory entry */ | |
94 | #define NODE 2 /* directory entry */ | |
95 | #define LINK 4 /* synthesized type, stripped by addentry */ | |
96 | /* flags */ | |
97 | #define EXTRACT 0x0001 /* entry is to be replaced from the tape */ | |
98 | #define NEW 0x0002 /* a new entry to be extracted */ | |
99 | #define KEEP 0x0004 /* entry is not to change */ | |
100 | #define REMOVED 0x0010 /* entry has been removed */ | |
101 | #define TMPNAME 0x0020 /* entry has been given a temporary name */ | |
102 | #define EXISTED 0x0040 /* directory already existed during extract */ | |
103 | /* | |
104 | * functions defined on entry structs | |
105 | */ | |
106 | extern struct entry *lookupino(); | |
107 | extern struct entry *lookupname(); | |
108 | extern struct entry *lookupparent(); | |
109 | extern struct entry *addentry(); | |
110 | extern char *myname(); | |
111 | extern char *savename(); | |
112 | extern char *gentempname(); | |
113 | extern char *flagvalues(); | |
114 | extern ino_t lowerbnd(); | |
115 | extern ino_t upperbnd(); | |
116 | #define NIL ((struct entry *)(0)) | |
117 | /* | |
118 | * Constants associated with entry structs | |
119 | */ | |
120 | #define HARDLINK 1 | |
121 | #define SYMLINK 2 | |
122 | #define TMPHDR "RSTTMP" | |
123 | ||
124 | /* | |
125 | * The entry describes the next file available on the tape | |
126 | */ | |
127 | struct context { | |
128 | char *name; /* name of file */ | |
129 | ino_t ino; /* inumber of file */ | |
130 | struct dinode *dip; /* pointer to inode */ | |
131 | char action; /* action being taken on this file */ | |
132 | } curfile; | |
133 | /* actions */ | |
134 | #define USING 1 /* extracting from the tape */ | |
135 | #define SKIP 2 /* skipping */ | |
136 | #define UNKNOWN 3 /* disposition or starting point is unknown */ | |
137 | ||
138 | /* | |
139 | * Definitions for library routines operating on directories. | |
140 | */ | |
141 | typedef struct dirdesc DIR; | |
142 | extern DIR *rst_opendir(); | |
143 | extern struct direct *rst_readdir(); | |
144 | ||
145 | /* | |
146 | * Other exported routines | |
147 | */ | |
148 | extern ino_t psearch(); | |
149 | extern ino_t dirlookup(); | |
150 | extern long listfile(); | |
151 | extern long deletefile(); | |
152 | extern long addfile(); | |
153 | extern long nodeupdates(); | |
154 | extern long verifyfile(); | |
155 | extern char *rindex(); | |
156 | extern char *index(); | |
157 | extern char *strcat(); | |
158 | extern char *strncat(); | |
159 | extern char *strcpy(); | |
160 | extern char *strncpy(); | |
161 | extern char *fgets(); | |
162 | extern char *mktemp(); | |
163 | extern char *malloc(); | |
164 | extern char *calloc(); | |
165 | extern char *realloc(); | |
166 | extern long lseek(); | |
167 | ||
168 | /* | |
169 | * Useful macros | |
170 | */ | |
171 | #define MWORD(m,i) (m[(unsigned)(i-1)/NBBY]) | |
172 | #define MBIT(i) (1<<((unsigned)(i-1)%NBBY)) | |
173 | #define BIS(i,w) (MWORD(w,i) |= MBIT(i)) | |
174 | #define BIC(i,w) (MWORD(w,i) &= ~MBIT(i)) | |
175 | #define BIT(i,w) (MWORD(w,i) & MBIT(i)) | |
176 | ||
177 | #define dprintf if (dflag) fprintf | |
178 | #define vprintf if (vflag) fprintf | |
179 | ||
180 | #define GOOD 1 | |
181 | #define FAIL 0 |