|
|
1.1.1.2 ! root 1: /* ! 2: * Copyright (c) 1983 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: 1.1 root 7: #ifndef lint 1.1.1.2 ! root 8: char copyright[] = ! 9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\ ! 10: All rights reserved.\n"; ! 11: #endif not lint 1.1 root 12: 1.1.1.2 ! root 13: #ifndef lint ! 14: static char sccsid[] = "@(#)main.c 5.2 (Berkeley) 6/18/85"; ! 15: #endif not lint 1.1 root 16: 17: /* 18: * Modified to recursively extract all files within a subtree 19: * (supressed by the h option) and recreate the heirarchical 20: * structure of that subtree and move extracted files to their 21: * proper homes (supressed by the m option). 22: * Includes the s (skip files) option for use with multiple 23: * dumps on a single tape. 24: * 8/29/80 by Mike Litzkow 25: * 26: * Modified to work on the new file system and to recover from 27: * tape read errors. 28: * 1/19/82 by Kirk McKusick 29: * 30: * Full incremental restore running entirely in user code and 31: * interactive tape browser. 32: * 1/19/83 by Kirk McKusick 33: */ 34: 35: #include "restore.h" 1.1.1.2 ! root 36: #include <dumprestor.h> 1.1 root 37: #include <signal.h> 38: 1.1.1.2 ! root 39: int bflag = 0, cvtflag = 0, dflag = 0, vflag = 0, yflag = 0; 1.1 root 40: int hflag = 1, mflag = 1; 41: char command = '\0'; 42: long dumpnum = 1; 43: long volno = 0; 1.1.1.2 ! root 44: long ntrec; 1.1 root 45: char *dumpmap; 46: char *clrimap; 47: ino_t maxino; 48: time_t dumptime; 49: time_t dumpdate; 50: FILE *terminal; 51: 52: main(argc, argv) 53: int argc; 54: char *argv[]; 55: { 56: register char *cp; 57: ino_t ino; 1.1.1.2 ! root 58: char *inputdev = "/dev/rcy0s"; 1.1 root 59: char *symtbl = "./restoresymtable"; 60: char name[MAXPATHLEN]; 61: int (*signal())(); 62: extern int onintr(); 63: 64: if (signal(SIGINT, onintr) == SIG_IGN) 65: (void) signal(SIGINT, SIG_IGN); 66: if (signal(SIGTERM, onintr) == SIG_IGN) 67: (void) signal(SIGTERM, SIG_IGN); 68: setlinebuf(stderr); 69: if (argc < 2) { 70: usage: 71: fprintf(stderr, "Usage:\n%s%s%s%s%s", 72: "\trestore tfhsvy [file file ...]\n", 73: "\trestore xfhmsvy [file file ...]\n", 74: "\trestore ifhmsvy\n", 75: "\trestore rfsvy\n", 76: "\trestore Rfsvy\n"); 77: done(1); 78: } 79: argv++; 80: argc -= 2; 81: command = '\0'; 82: for (cp = *argv++; *cp; cp++) { 83: switch (*cp) { 84: case '-': 85: break; 86: case 'c': 87: cvtflag++; 88: break; 89: case 'd': 90: dflag++; 91: break; 92: case 'h': 93: hflag = 0; 94: break; 95: case 'm': 96: mflag = 0; 97: break; 98: case 'v': 99: vflag++; 100: break; 101: case 'y': 102: yflag++; 103: break; 104: case 'f': 105: if (argc < 1) { 106: fprintf(stderr, "missing device specifier\n"); 107: done(1); 108: } 109: inputdev = *argv++; 110: argc--; 111: break; 1.1.1.2 ! root 112: case 'b': ! 113: /* ! 114: * change default tape blocksize ! 115: */ ! 116: bflag++; ! 117: if (argc < 1) { ! 118: fprintf(stderr, "missing block size\n"); ! 119: done(1); ! 120: } ! 121: ntrec = atoi(*argv++); ! 122: if (ntrec <= 0) { ! 123: fprintf(stderr, "Block size must be a positive integer\n"); ! 124: done(1); ! 125: } ! 126: argc--; ! 127: break; 1.1 root 128: case 's': 129: /* 130: * dumpnum (skip to) for multifile dump tapes 131: */ 132: if (argc < 1) { 133: fprintf(stderr, "missing dump number\n"); 134: done(1); 135: } 136: dumpnum = atoi(*argv++); 137: if (dumpnum <= 0) { 138: fprintf(stderr, "Dump number must be a positive integer\n"); 139: done(1); 140: } 141: argc--; 142: break; 143: case 't': 144: case 'T': 145: case 'R': 146: case 'r': 147: case 'x': 148: case 'X': 149: case 'i': 150: if (command != '\0') { 151: fprintf(stderr, 152: "%c and %c are mutually exclusive\n", 153: *cp, command); 154: goto usage; 155: } 156: command = *cp; 157: break; 158: default: 159: fprintf(stderr, "Bad key character %c\n", *cp); 160: goto usage; 161: } 162: } 163: if (command == '\0') { 1.1.1.2 ! root 164: fprintf(stderr, "must specify i, t, r, R, or x\n"); 1.1 root 165: goto usage; 166: } 167: setinput(inputdev); 168: if (argc == 0) { 169: argc = 1; 170: *--argv = "."; 171: } 172: switch (command) { 173: /* 174: * Interactive mode. 175: */ 176: case 'i': 177: setup(); 178: extractdirs(1); 179: initsymtable((char *)0); 180: runcmdshell(); 181: done(0); 182: /* 183: * Incremental restoration of a file system. 184: */ 185: case 'r': 186: setup(); 187: if (dumptime > 0) { 188: /* 189: * This is an incremental dump tape. 190: */ 191: vprintf(stdout, "Begin incremental restore\n"); 192: initsymtable(symtbl); 193: extractdirs(1); 194: removeoldleaves(); 195: vprintf(stdout, "Calculate node updates.\n"); 196: treescan(".", ROOTINO, nodeupdates); 197: findunreflinks(); 198: removeoldnodes(); 199: } else { 200: /* 201: * This is a level zero dump tape. 202: */ 203: vprintf(stdout, "Begin level 0 restore\n"); 204: initsymtable((char *)0); 205: extractdirs(1); 206: vprintf(stdout, "Calculate extraction list.\n"); 207: treescan(".", ROOTINO, nodeupdates); 208: } 209: createleaves(symtbl); 210: createlinks(); 211: setdirmodes(); 212: checkrestore(); 213: if (dflag) { 214: vprintf(stdout, "Verify the directory structure\n"); 215: treescan(".", ROOTINO, verifyfile); 216: } 217: dumpsymtable(symtbl, (long)1); 218: done(0); 219: /* 220: * Resume an incremental file system restoration. 221: */ 222: case 'R': 223: initsymtable(symtbl); 224: skipmaps(); 225: skipdirs(); 226: createleaves(symtbl); 227: createlinks(); 228: setdirmodes(); 229: checkrestore(); 230: dumpsymtable(symtbl, (long)1); 231: done(0); 1.1.1.2 ! root 232: /* ! 233: * List header information of tape ! 234: */ ! 235: case 'T': ! 236: setup(); 1.1 root 237: done(0); 238: /* 239: * List contents of tape. 240: */ 241: case 't': 242: setup(); 243: extractdirs(0); 244: while (argc--) { 245: canon(*argv++, name); 246: ino = dirlookup(name); 247: if (ino == 0) 248: continue; 249: treescan(name, ino, listfile); 250: } 251: done(0); 252: /* 253: * Batch extraction of tape contents. 254: */ 255: case 'x': 256: case 'X': 257: setup(); 258: extractdirs(1); 259: initsymtable((char *)0); 260: while (argc--) { 261: canon(*argv++, name); 262: ino = dirlookup(name); 263: if (ino == 0) 264: continue; 265: if (mflag) 266: pathcheck(name); 267: treescan(name, ino, addfile); 268: } 269: createfiles(); 270: createlinks(); 271: setdirmodes(); 272: if (dflag) 273: checkrestore(); 274: done(0); 275: } 276: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.