1 /* 2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * @(#)restore.h 5.7 (Berkeley) 02/15/90 18 */ 19 20 #include <stdio.h> 21 #include <sys/param.h> 22 #include <sys/time.h> 23 #include <ufs/dinode.h> 24 #include <ufs/fs.h> 25 26 /* 27 * Flags 28 */ 29 extern int cvtflag; /* convert from old to new tape format */ 30 extern int bflag; /* set input block size */ 31 extern int dflag; /* print out debugging info */ 32 extern int hflag; /* restore heirarchies */ 33 extern int mflag; /* restore by name instead of inode number */ 34 extern int Nflag; /* do not write the disk */ 35 extern int vflag; /* print out actions taken */ 36 extern int yflag; /* always try to recover from tape errors */ 37 /* 38 * Global variables 39 */ 40 extern char *dumpmap; /* map of inodes on this dump tape */ 41 extern char *clrimap; /* map of inodes to be deleted */ 42 extern ino_t maxino; /* highest numbered inode in this file system */ 43 extern long dumpnum; /* location of the dump on this tape */ 44 extern long volno; /* current volume being read */ 45 extern long ntrec; /* number of TP_BSIZE records per tape block */ 46 extern time_t dumptime; /* time that this dump begins */ 47 extern time_t dumpdate; /* time that this dump was made */ 48 extern char command; /* opration being performed */ 49 extern FILE *terminal; /* file descriptor for the terminal input */ 50 51 /* 52 * Each file in the file system is described by one of these entries 53 */ 54 struct entry { 55 char *e_name; /* the current name of this entry */ 56 u_char e_namlen; /* length of this name */ 57 char e_type; /* type of this entry, see below */ 58 short e_flags; /* status flags, see below */ 59 ino_t e_ino; /* inode number in previous file sys */ 60 long e_index; /* unique index (for dumpped table) */ 61 struct entry *e_parent; /* pointer to parent directory (..) */ 62 struct entry *e_sibling; /* next element in this directory (.) */ 63 struct entry *e_links; /* hard links to this inode */ 64 struct entry *e_entries; /* for directories, their entries */ 65 struct entry *e_next; /* hash chain list */ 66 }; 67 /* types */ 68 #define LEAF 1 /* non-directory entry */ 69 #define NODE 2 /* directory entry */ 70 #define LINK 4 /* synthesized type, stripped by addentry */ 71 /* flags */ 72 #define EXTRACT 0x0001 /* entry is to be replaced from the tape */ 73 #define NEW 0x0002 /* a new entry to be extracted */ 74 #define KEEP 0x0004 /* entry is not to change */ 75 #define REMOVED 0x0010 /* entry has been removed */ 76 #define TMPNAME 0x0020 /* entry has been given a temporary name */ 77 #define EXISTED 0x0040 /* directory already existed during extract */ 78 /* 79 * functions defined on entry structs 80 */ 81 extern struct entry *lookupino(); 82 extern struct entry *lookupname(); 83 extern struct entry *lookupparent(); 84 extern struct entry *addentry(); 85 extern char *myname(); 86 extern char *savename(); 87 extern char *gentempname(); 88 extern char *flagvalues(); 89 extern ino_t lowerbnd(); 90 extern ino_t upperbnd(); 91 #define NIL ((struct entry *)(0)) 92 /* 93 * Constants associated with entry structs 94 */ 95 #define HARDLINK 1 96 #define SYMLINK 2 97 #define TMPHDR "RSTTMP" 98 99 /* 100 * The entry describes the next file available on the tape 101 */ 102 struct context { 103 char *name; /* name of file */ 104 ino_t ino; /* inumber of file */ 105 struct dinode *dip; /* pointer to inode */ 106 char action; /* action being taken on this file */ 107 } curfile; 108 /* actions */ 109 #define USING 1 /* extracting from the tape */ 110 #define SKIP 2 /* skipping */ 111 #define UNKNOWN 3 /* disposition or starting point is unknown */ 112 113 /* 114 * Definitions for library routines operating on directories. 115 */ 116 typedef struct dirdesc DIR; 117 extern DIR *rst_opendir(); 118 extern struct direct *rst_readdir(); 119 120 /* 121 * Other exported routines 122 */ 123 extern ino_t psearch(); 124 extern ino_t dirlookup(); 125 extern long listfile(); 126 extern long deletefile(); 127 extern long addfile(); 128 extern long nodeupdates(); 129 extern long verifyfile(); 130 extern char *rindex(); 131 extern char *index(); 132 extern char *strcat(); 133 extern char *strncat(); 134 extern char *strcpy(); 135 extern char *strncpy(); 136 extern char *fgets(); 137 extern char *mktemp(); 138 extern char *malloc(); 139 extern char *calloc(); 140 extern char *realloc(); 141 extern long lseek(); 142 143 /* 144 * Useful macros 145 */ 146 #define MWORD(m,i) (m[(unsigned)(i-1)/NBBY]) 147 #define MBIT(i) (1<<((unsigned)(i-1)%NBBY)) 148 #define BIS(i,w) (MWORD(w,i) |= MBIT(i)) 149 #define BIC(i,w) (MWORD(w,i) &= ~MBIT(i)) 150 #define BIT(i,w) (MWORD(w,i) & MBIT(i)) 151 152 #define dprintf if (dflag) fprintf 153 #define vprintf if (vflag) fprintf 154 155 #define GOOD 1 156 #define FAIL 0 157