xref: /original-bsd/sbin/restore/restore.h (revision 860e07fc)
1 /*
2  * Copyright (c) 1983 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)restore.h	5.12 (Berkeley) 08/09/92
8  */
9 
10 #include <sys/param.h>
11 #include <sys/time.h>
12 #include <ufs/ufs/dinode.h>
13 #include <ufs/ffs/fs.h>
14 #include <stdio.h>
15 
16 /*
17  * Flags
18  */
19 extern int	cvtflag;	/* convert from old to new tape format */
20 extern int	bflag;		/* set input block size */
21 extern int	dflag;		/* print out debugging info */
22 extern int	hflag;		/* restore heirarchies */
23 extern int	mflag;		/* restore by name instead of inode number */
24 extern int	Nflag;		/* do not write the disk */
25 extern int	vflag;		/* print out actions taken */
26 extern int	yflag;		/* always try to recover from tape errors */
27 /*
28  * Global variables
29  */
30 extern char	*dumpmap; 	/* map of inodes on this dump tape */
31 extern char	*clrimap; 	/* map of inodes to be deleted */
32 extern ino_t	maxino;		/* highest numbered inode in this file system */
33 extern long	dumpnum;	/* location of the dump on this tape */
34 extern long	volno;		/* current volume being read */
35 extern long	ntrec;		/* number of TP_BSIZE records per tape block */
36 extern time_t	dumptime;	/* time that this dump begins */
37 extern time_t	dumpdate;	/* time that this dump was made */
38 extern char	command;	/* opration being performed */
39 extern FILE	*terminal;	/* file descriptor for the terminal input */
40 extern int	oldinofmt;	/* reading tape with old format inodes */
41 extern int	Bcvt;		/* need byte swapping on inodes and dirs */
42 
43 /*
44  * Each file in the file system is described by one of these entries
45  */
46 struct entry {
47 	char	*e_name;		/* the current name of this entry */
48 	u_char	e_namlen;		/* length of this name */
49 	char	e_type;			/* type of this entry, see below */
50 	short	e_flags;		/* status flags, see below */
51 	ino_t	e_ino;			/* inode number in previous file sys */
52 	long	e_index;		/* unique index (for dumpped table) */
53 	struct	entry *e_parent;	/* pointer to parent directory (..) */
54 	struct	entry *e_sibling;	/* next element in this directory (.) */
55 	struct	entry *e_links;		/* hard links to this inode */
56 	struct	entry *e_entries;	/* for directories, their entries */
57 	struct	entry *e_next;		/* hash chain list */
58 };
59 /* types */
60 #define	LEAF 1			/* non-directory entry */
61 #define NODE 2			/* directory entry */
62 #define LINK 4			/* synthesized type, stripped by addentry */
63 /* flags */
64 #define EXTRACT		0x0001	/* entry is to be replaced from the tape */
65 #define NEW		0x0002	/* a new entry to be extracted */
66 #define KEEP		0x0004	/* entry is not to change */
67 #define REMOVED		0x0010	/* entry has been removed */
68 #define TMPNAME		0x0020	/* entry has been given a temporary name */
69 #define EXISTED		0x0040	/* directory already existed during extract */
70 /*
71  * functions defined on entry structs
72  */
73 extern struct entry *lookupino();
74 extern struct entry *lookupname();
75 extern struct entry *lookupparent();
76 extern struct entry *addentry();
77 extern char *myname();
78 extern char *savename();
79 extern char *gentempname();
80 extern char *flagvalues();
81 extern ino_t lowerbnd();
82 extern ino_t upperbnd();
83 #define NIL ((struct entry *)(0))
84 /*
85  * Constants associated with entry structs
86  */
87 #define HARDLINK	1
88 #define SYMLINK		2
89 #define TMPHDR		"RSTTMP"
90 
91 /*
92  * The entry describes the next file available on the tape
93  */
94 struct context {
95 	char	*name;		/* name of file */
96 	ino_t	ino;		/* inumber of file */
97 	struct	dinode *dip;	/* pointer to inode */
98 	char	action;		/* action being taken on this file */
99 } curfile;
100 /* actions */
101 #define	USING	1	/* extracting from the tape */
102 #define	SKIP	2	/* skipping */
103 #define UNKNOWN 3	/* disposition or starting point is unknown */
104 
105 /*
106  * Definitions for library routines operating on directories.
107  */
108 typedef struct rstdirdesc RST_DIR;
109 extern RST_DIR *rst_opendir();
110 extern struct direct *rst_readdir();
111 
112 /*
113  * Other exported routines
114  */
115 extern ino_t psearch();
116 extern ino_t dirlookup();
117 extern long listfile();
118 extern long deletefile();
119 extern long addfile();
120 extern long nodeupdates();
121 extern long verifyfile();
122 extern char *rindex();
123 extern char *index();
124 extern char *strcat();
125 extern char *strncat();
126 extern char *strcpy();
127 extern char *strncpy();
128 extern char *fgets();
129 extern char *mktemp();
130 extern char *malloc();
131 extern char *calloc();
132 extern char *realloc();
133 extern long lseek();
134 
135 /*
136  * Flags to setdirmodes.
137  */
138 #define FORCE	0x0001
139 
140 /*
141  * Useful macros
142  */
143 #define	MWORD(m,i) (m[(unsigned)(i-1)/NBBY])
144 #define	MBIT(i)	(1<<((unsigned)(i-1)%NBBY))
145 #define	BIS(i,w)	(MWORD(w,i) |=  MBIT(i))
146 #define	BIC(i,w)	(MWORD(w,i) &= ~MBIT(i))
147 #define	BIT(i,w)	(MWORD(w,i) & MBIT(i))
148 
149 #define dprintf		if (dflag) fprintf
150 #define vprintf		if (vflag) fprintf
151 
152 #define GOOD 1
153 #define FAIL 0
154