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