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