xref: /openbsd/sbin/restore/restore.h (revision 9be7043f)
1*9be7043fSmortimer /*	$OpenBSD: restore.h,v 1.10 2021/01/21 00:16:36 mortimer Exp $	*/
2a916033eSmillert /*	$NetBSD: restore.h,v 1.8 1997/07/01 05:37:54 lukem Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*
5df930be7Sderaadt  * Copyright (c) 1983, 1993
6df930be7Sderaadt  *	The Regents of the University of California.  All rights reserved.
7df930be7Sderaadt  * (c) UNIX System Laboratories, Inc.
8df930be7Sderaadt  * All or some portions of this file are derived from material licensed
9df930be7Sderaadt  * to the University of California by American Telephone and Telegraph
10df930be7Sderaadt  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11df930be7Sderaadt  * the permission of UNIX System Laboratories, Inc.
12df930be7Sderaadt  *
13df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
14df930be7Sderaadt  * modification, are permitted provided that the following conditions
15df930be7Sderaadt  * are met:
16df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
17df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
18df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
19df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
20df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
211ef0d710Smillert  * 3. Neither the name of the University nor the names of its contributors
22df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
23df930be7Sderaadt  *    without specific prior written permission.
24df930be7Sderaadt  *
25df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35df930be7Sderaadt  * SUCH DAMAGE.
36df930be7Sderaadt  *
37df930be7Sderaadt  *	@(#)restore.h	8.3 (Berkeley) 9/13/94
38df930be7Sderaadt  */
39df930be7Sderaadt 
40df930be7Sderaadt /*
41df930be7Sderaadt  * Flags
42df930be7Sderaadt  */
43df930be7Sderaadt extern int	cvtflag;	/* convert from old to new tape format */
44df930be7Sderaadt extern int	bflag;		/* set input block size */
45df930be7Sderaadt extern int	dflag;		/* print out debugging info */
46df930be7Sderaadt extern int	hflag;		/* restore heirarchies */
47df930be7Sderaadt extern int	mflag;		/* restore by name instead of inode number */
48df930be7Sderaadt extern int	Nflag;		/* do not write the disk */
49df930be7Sderaadt extern int	vflag;		/* print out actions taken */
50df930be7Sderaadt extern int	yflag;		/* always try to recover from tape errors */
51df930be7Sderaadt /*
52df930be7Sderaadt  * Global variables
53df930be7Sderaadt  */
54df930be7Sderaadt extern char	*dumpmap;	/* map of inodes on this dump tape */
55df930be7Sderaadt extern char	*usedinomap;	/* map of inodes that are in use on this fs */
56df930be7Sderaadt extern ino_t	maxino;		/* highest numbered inode in this file system */
57df930be7Sderaadt extern long	dumpnum;	/* location of the dump on this tape */
58df930be7Sderaadt extern long	volno;		/* current volume being read */
59df930be7Sderaadt extern long	ntrec;		/* number of TP_BSIZE records per tape block */
60df930be7Sderaadt extern time_t	dumptime;	/* time that this dump begins */
61df930be7Sderaadt extern time_t	dumpdate;	/* time that this dump was made */
62a34540b3Smiod extern char	command;	/* operation being performed */
63df930be7Sderaadt extern FILE	*terminal;	/* file descriptor for the terminal input */
64a916033eSmillert extern char	*tmpdir;	/* where to store temporary files */
65df930be7Sderaadt extern int	oldinofmt;	/* reading tape with old format inodes */
66df930be7Sderaadt extern int	Bcvt;		/* need byte swapping on inodes and dirs */
67a916033eSmillert extern char	*__progname;	/* from crt0.o */
68df930be7Sderaadt 
69df930be7Sderaadt /*
70df930be7Sderaadt  * Each file in the file system is described by one of these entries
71df930be7Sderaadt  */
72df930be7Sderaadt struct entry {
73df930be7Sderaadt 	char	*e_name;		/* the current name of this entry */
74df930be7Sderaadt 	u_char	e_namlen;		/* length of this name */
75df930be7Sderaadt 	char	e_type;			/* type of this entry, see below */
76df930be7Sderaadt 	short	e_flags;		/* status flags, see below */
77df930be7Sderaadt 	ino_t	e_ino;			/* inode number in previous file sys */
785c93b216Shenning 	long	e_index;		/* unique index (for dumped table) */
79df930be7Sderaadt 	struct	entry *e_parent;	/* pointer to parent directory (..) */
80df930be7Sderaadt 	struct	entry *e_sibling;	/* next element in this directory (.) */
81df930be7Sderaadt 	struct	entry *e_links;		/* hard links to this inode */
82df930be7Sderaadt 	struct	entry *e_entries;	/* for directories, their entries */
83df930be7Sderaadt 	struct	entry *e_next;		/* hash chain list */
84df930be7Sderaadt };
85df930be7Sderaadt /* types */
86df930be7Sderaadt #define	LEAF 1			/* non-directory entry */
87df930be7Sderaadt #define NODE 2			/* directory entry */
88df930be7Sderaadt #define LINK 4			/* synthesized type, stripped by addentry */
89df930be7Sderaadt /* flags */
90df930be7Sderaadt #define EXTRACT		0x0001	/* entry is to be replaced from the tape */
91df930be7Sderaadt #define NEW		0x0002	/* a new entry to be extracted */
92df930be7Sderaadt #define KEEP		0x0004	/* entry is not to change */
93df930be7Sderaadt #define REMOVED		0x0010	/* entry has been removed */
94df930be7Sderaadt #define TMPNAME		0x0020	/* entry has been given a temporary name */
95df930be7Sderaadt #define EXISTED		0x0040	/* directory already existed during extract */
96df930be7Sderaadt 
97df930be7Sderaadt /*
98df930be7Sderaadt  * Constants associated with entry structs
99df930be7Sderaadt  */
100df930be7Sderaadt #define HARDLINK	1
101df930be7Sderaadt #define SYMLINK		2
102df930be7Sderaadt #define TMPHDR		"RSTTMP"
103df930be7Sderaadt 
104df930be7Sderaadt /*
105df930be7Sderaadt  * The entry describes the next file available on the tape
106df930be7Sderaadt  */
107*9be7043fSmortimer extern struct context {
1080155e653Smillert 	short	action;		/* action being taken on this file */
1090155e653Smillert 	mode_t	mode;		/* mode of file */
110df930be7Sderaadt 	ino_t	ino;		/* inumber of file */
1110155e653Smillert 	uid_t	uid;		/* file owner */
1120155e653Smillert 	gid_t	gid;		/* file group */
1130155e653Smillert 	int	file_flags;	/* status flags (chflags) */
1140155e653Smillert 	int	rdev;		/* device number of file */
1150155e653Smillert 	time_t	atime_sec;	/* access time seconds */
1160155e653Smillert 	time_t	mtime_sec;	/* modified time seconds */
1170155e653Smillert 	time_t	birthtime_sec;	/* creation time seconds */
1180155e653Smillert 	int	atime_nsec;	/* access time nanoseconds */
1190155e653Smillert 	int	mtime_nsec;	/* modified time nanoseconds */
1200155e653Smillert 	int	birthtime_nsec;	/* creation time nanoseconds */
1210155e653Smillert 	off_t	size;		/* size of file */
1220155e653Smillert 	char	*name;		/* name of file */
123df930be7Sderaadt } curfile;
124df930be7Sderaadt /* actions */
125df930be7Sderaadt #define	USING	1	/* extracting from the tape */
126df930be7Sderaadt #define	SKIP	2	/* skipping */
127df930be7Sderaadt #define UNKNOWN 3	/* disposition or starting point is unknown */
128df930be7Sderaadt 
129df930be7Sderaadt /*
130df930be7Sderaadt  * Definitions for library routines operating on directories.
131df930be7Sderaadt  */
132df930be7Sderaadt typedef struct rstdirdesc RST_DIR;
133df930be7Sderaadt 
134df930be7Sderaadt /*
135df930be7Sderaadt  * Flags to setdirmodes.
136df930be7Sderaadt  */
137df930be7Sderaadt #define FORCE	0x0001
138df930be7Sderaadt 
139df930be7Sderaadt /*
140df930be7Sderaadt  * Useful macros
141df930be7Sderaadt  */
142df930be7Sderaadt #define TSTINO(ino, map) \
143df930be7Sderaadt 	(map[(u_int)((ino) - 1) / NBBY] &  (1 << ((u_int)((ino) - 1) % NBBY)))
144df930be7Sderaadt #define	SETINO(ino, map) \
145df930be7Sderaadt 	map[(u_int)((ino) - 1) / NBBY] |=  1 << ((u_int)((ino) - 1) % NBBY)
146df930be7Sderaadt 
147a916033eSmillert #define Dprintf		if (dflag) fprintf
148a916033eSmillert #define Vprintf		if (vflag) fprintf
149df930be7Sderaadt 
150df930be7Sderaadt #define GOOD 1
151df930be7Sderaadt #define FAIL 0
152