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