1144564Simp/*-
21558Srgrimes * Copyright (c) 1983, 1993
31558Srgrimes *	The Regents of the University of California.  All rights reserved.
41558Srgrimes * (c) UNIX System Laboratories, Inc.
51558Srgrimes * All or some portions of this file are derived from material licensed
61558Srgrimes * to the University of California by American Telephone and Telegraph
71558Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81558Srgrimes * the permission of UNIX System Laboratories, Inc.
91558Srgrimes *
101558Srgrimes * Redistribution and use in source and binary forms, with or without
111558Srgrimes * modification, are permitted provided that the following conditions
121558Srgrimes * are met:
131558Srgrimes * 1. Redistributions of source code must retain the above copyright
141558Srgrimes *    notice, this list of conditions and the following disclaimer.
151558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161558Srgrimes *    notice, this list of conditions and the following disclaimer in the
171558Srgrimes *    documentation and/or other materials provided with the distribution.
181558Srgrimes * 4. Neither the name of the University nor the names of its contributors
191558Srgrimes *    may be used to endorse or promote products derived from this software
201558Srgrimes *    without specific prior written permission.
211558Srgrimes *
221558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251558Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321558Srgrimes * SUCH DAMAGE.
331558Srgrimes *
3423669Speter *	@(#)restore.h	8.3 (Berkeley) 9/13/94
3596707Strhodes * $FreeBSD$
361558Srgrimes */
371558Srgrimes
381558Srgrimes/*
391558Srgrimes * Flags
401558Srgrimes */
411558Srgrimesextern int	bflag;		/* set input block size */
421558Srgrimesextern int	dflag;		/* print out debugging info */
43164911Sdwmaloneextern int	Dflag;		/* degraded mode - try hard to get stuff back */
44204111Suqsextern int	hflag;		/* restore hierarchies */
451558Srgrimesextern int	mflag;		/* restore by name instead of inode number */
461558Srgrimesextern int	Nflag;		/* do not write the disk */
4735852Sjkhextern int	uflag;		/* unlink symlink targets */
481558Srgrimesextern int	vflag;		/* print out actions taken */
491558Srgrimesextern int	yflag;		/* always try to recover from tape errors */
501558Srgrimes/*
511558Srgrimes * Global variables
521558Srgrimes */
531558Srgrimesextern char	*dumpmap; 	/* map of inodes on this dump tape */
5423669Speterextern char	*usedinomap; 	/* map of inodes that are in use on this fs */
55102231Strhodesextern ino_t	maxino;		/* highest numbered inode in this file system */
561558Srgrimesextern long	dumpnum;	/* location of the dump on this tape */
571558Srgrimesextern long	volno;		/* current volume being read */
581558Srgrimesextern long	ntrec;		/* number of TP_BSIZE records per tape block */
591558Srgrimesextern time_t	dumptime;	/* time that this dump begins */
601558Srgrimesextern time_t	dumpdate;	/* time that this dump was made */
611558Srgrimesextern char	command;	/* opration being performed */
621558Srgrimesextern FILE	*terminal;	/* file descriptor for the terminal input */
631558Srgrimesextern int	Bcvt;		/* need byte swapping on inodes and dirs */
64144099Simpextern int	oldinofmt;	/* reading tape with FreeBSD 1 format inodes */
651558Srgrimes
661558Srgrimes/*
67102231Strhodes * Each file in the file system is described by one of these entries
681558Srgrimes */
691558Srgrimesstruct entry {
701558Srgrimes	char	*e_name;		/* the current name of this entry */
711558Srgrimes	u_char	e_namlen;		/* length of this name */
721558Srgrimes	char	e_type;			/* type of this entry, see below */
731558Srgrimes	short	e_flags;		/* status flags, see below */
741558Srgrimes	ino_t	e_ino;			/* inode number in previous file sys */
751558Srgrimes	long	e_index;		/* unique index (for dumpped table) */
761558Srgrimes	struct	entry *e_parent;	/* pointer to parent directory (..) */
771558Srgrimes	struct	entry *e_sibling;	/* next element in this directory (.) */
781558Srgrimes	struct	entry *e_links;		/* hard links to this inode */
791558Srgrimes	struct	entry *e_entries;	/* for directories, their entries */
801558Srgrimes	struct	entry *e_next;		/* hash chain list */
811558Srgrimes};
821558Srgrimes/* types */
831558Srgrimes#define	LEAF 1			/* non-directory entry */
841558Srgrimes#define NODE 2			/* directory entry */
851558Srgrimes#define LINK 4			/* synthesized type, stripped by addentry */
861558Srgrimes/* flags */
871558Srgrimes#define EXTRACT		0x0001	/* entry is to be replaced from the tape */
881558Srgrimes#define NEW		0x0002	/* a new entry to be extracted */
891558Srgrimes#define KEEP		0x0004	/* entry is not to change */
901558Srgrimes#define REMOVED		0x0010	/* entry has been removed */
911558Srgrimes#define TMPNAME		0x0020	/* entry has been given a temporary name */
921558Srgrimes#define EXISTED		0x0040	/* directory already existed during extract */
931558Srgrimes
941558Srgrimes/*
951558Srgrimes * Constants associated with entry structs
961558Srgrimes */
971558Srgrimes#define HARDLINK	1
981558Srgrimes#define SYMLINK		2
991558Srgrimes#define TMPHDR		"RSTTMP"
1001558Srgrimes
1011558Srgrimes/*
1021558Srgrimes * The entry describes the next file available on the tape
1031558Srgrimes */
1041558Srgrimesstruct context {
10598542Smckusick	short	action;		/* action being taken on this file */
10698542Smckusick	mode_t	mode;		/* mode of file */
10798542Smckusick	ino_t	ino;		/* inumber of file */
10898542Smckusick	uid_t	uid;		/* file owner */
10998542Smckusick	gid_t	gid;		/* file group */
11098542Smckusick	int	file_flags;	/* status flags (chflags) */
11198542Smckusick	int	rdev;		/* device number of file */
11298542Smckusick	time_t	atime_sec;	/* access time seconds */
11398542Smckusick	time_t	mtime_sec;	/* modified time seconds */
114100207Smckusick	time_t	birthtime_sec;	/* creation time seconds */
11598542Smckusick	int	atime_nsec;	/* access time nanoseconds */
11698542Smckusick	int	mtime_nsec;	/* modified time nanoseconds */
117100207Smckusick	int	birthtime_nsec;	/* creation time nanoseconds */
118167011Smckusick	int	extsize;	/* size of extended attribute data */
11998542Smckusick	off_t	size;		/* size of file */
1201558Srgrimes	char	*name;		/* name of file */
1211558Srgrimes} curfile;
1221558Srgrimes/* actions */
1231558Srgrimes#define	USING	1	/* extracting from the tape */
1241558Srgrimes#define	SKIP	2	/* skipping */
1251558Srgrimes#define UNKNOWN 3	/* disposition or starting point is unknown */
1261558Srgrimes
1271558Srgrimes/*
1281558Srgrimes * Definitions for library routines operating on directories.
1291558Srgrimes */
1301558Srgrimestypedef struct rstdirdesc RST_DIR;
1311558Srgrimes
1321558Srgrimes/*
1331558Srgrimes * Flags to setdirmodes.
1341558Srgrimes */
1351558Srgrimes#define FORCE	0x0001
1361558Srgrimes
1371558Srgrimes/*
1381558Srgrimes * Useful macros
1391558Srgrimes */
1401558Srgrimes#define TSTINO(ino, map) \
141103949Smike	(map[(u_int)((ino) - 1) / CHAR_BIT] & \
142103949Smike	    (1 << ((u_int)((ino) - 1) % CHAR_BIT)))
14323669Speter#define	SETINO(ino, map) \
144103949Smike	map[(u_int)((ino) - 1) / CHAR_BIT] |= \
145103949Smike	    1 << ((u_int)((ino) - 1) % CHAR_BIT)
1461558Srgrimes
1471558Srgrimes#define dprintf		if (dflag) fprintf
1481558Srgrimes#define vprintf		if (vflag) fprintf
1491558Srgrimes
1501558Srgrimes#define GOOD 1
1511558Srgrimes#define FAIL 0
152144099Simp
153144099Simp#define NFS_DR_NEWINODEFMT	0x2	/* Tape uses 4.4 BSD inode format */
154