xref: /original-bsd/sbin/restore/restore.h (revision 2c12987e)
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.8 (Berkeley) 06/01/90
8  */
9 
10 #include <stdio.h>
11 #include <sys/param.h>
12 #include <sys/time.h>
13 #include <ufs/dinode.h>
14 #include <ufs/fs.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 
41 /*
42  * Each file in the file system is described by one of these entries
43  */
44 struct entry {
45 	char	*e_name;		/* the current name of this entry */
46 	u_char	e_namlen;		/* length of this name */
47 	char	e_type;			/* type of this entry, see below */
48 	short	e_flags;		/* status flags, see below */
49 	ino_t	e_ino;			/* inode number in previous file sys */
50 	long	e_index;		/* unique index (for dumpped table) */
51 	struct	entry *e_parent;	/* pointer to parent directory (..) */
52 	struct	entry *e_sibling;	/* next element in this directory (.) */
53 	struct	entry *e_links;		/* hard links to this inode */
54 	struct	entry *e_entries;	/* for directories, their entries */
55 	struct	entry *e_next;		/* hash chain list */
56 };
57 /* types */
58 #define	LEAF 1			/* non-directory entry */
59 #define NODE 2			/* directory entry */
60 #define LINK 4			/* synthesized type, stripped by addentry */
61 /* flags */
62 #define EXTRACT		0x0001	/* entry is to be replaced from the tape */
63 #define NEW		0x0002	/* a new entry to be extracted */
64 #define KEEP		0x0004	/* entry is not to change */
65 #define REMOVED		0x0010	/* entry has been removed */
66 #define TMPNAME		0x0020	/* entry has been given a temporary name */
67 #define EXISTED		0x0040	/* directory already existed during extract */
68 /*
69  * functions defined on entry structs
70  */
71 extern struct entry *lookupino();
72 extern struct entry *lookupname();
73 extern struct entry *lookupparent();
74 extern struct entry *addentry();
75 extern char *myname();
76 extern char *savename();
77 extern char *gentempname();
78 extern char *flagvalues();
79 extern ino_t lowerbnd();
80 extern ino_t upperbnd();
81 #define NIL ((struct entry *)(0))
82 /*
83  * Constants associated with entry structs
84  */
85 #define HARDLINK	1
86 #define SYMLINK		2
87 #define TMPHDR		"RSTTMP"
88 
89 /*
90  * The entry describes the next file available on the tape
91  */
92 struct context {
93 	char	*name;		/* name of file */
94 	ino_t	ino;		/* inumber of file */
95 	struct	dinode *dip;	/* pointer to inode */
96 	char	action;		/* action being taken on this file */
97 } curfile;
98 /* actions */
99 #define	USING	1	/* extracting from the tape */
100 #define	SKIP	2	/* skipping */
101 #define UNKNOWN 3	/* disposition or starting point is unknown */
102 
103 /*
104  * Definitions for library routines operating on directories.
105  */
106 typedef struct dirdesc DIR;
107 extern DIR *rst_opendir();
108 extern struct direct *rst_readdir();
109 
110 /*
111  * Other exported routines
112  */
113 extern ino_t psearch();
114 extern ino_t dirlookup();
115 extern long listfile();
116 extern long deletefile();
117 extern long addfile();
118 extern long nodeupdates();
119 extern long verifyfile();
120 extern char *rindex();
121 extern char *index();
122 extern char *strcat();
123 extern char *strncat();
124 extern char *strcpy();
125 extern char *strncpy();
126 extern char *fgets();
127 extern char *mktemp();
128 extern char *malloc();
129 extern char *calloc();
130 extern char *realloc();
131 extern long lseek();
132 
133 /*
134  * Useful macros
135  */
136 #define	MWORD(m,i) (m[(unsigned)(i-1)/NBBY])
137 #define	MBIT(i)	(1<<((unsigned)(i-1)%NBBY))
138 #define	BIS(i,w)	(MWORD(w,i) |=  MBIT(i))
139 #define	BIC(i,w)	(MWORD(w,i) &= ~MBIT(i))
140 #define	BIT(i,w)	(MWORD(w,i) & MBIT(i))
141 
142 #define dprintf		if (dflag) fprintf
143 #define vprintf		if (vflag) fprintf
144 
145 #define GOOD 1
146 #define FAIL 0
147