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