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