|
|
1.1.1.2 ! root 1: /* ! 2: * Copyright (c) 1980 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: ! 7: #ifndef lint ! 8: static char sccsid[] = "@(#)dumpmain.c 5.1 (Berkeley) 6/5/85"; ! 9: #endif not lint ! 10: 1.1 root 11: #include "dump.h" 12: 13: int notify = 0; /* notify operator flag */ 14: int blockswritten = 0; /* number of blocks written on current tape */ 15: int tapeno = 0; /* current tape number */ 16: int density = 0; /* density in bytes/0.1" */ 17: int ntrec = NTREC; /* # tape blocks in each tape record */ 18: int cartridge = 0; /* Assume non-cartridge tape */ 19: #ifdef RDUMP 20: char *host; 21: #endif 22: 23: main(argc, argv) 24: int argc; 25: char *argv[]; 26: { 27: char *arg; 1.1.1.2 ! root 28: int bflag = 0, i; 1.1 root 29: float fetapes; 30: register struct fstab *dt; 31: 32: time(&(spcl.c_date)); 33: 34: tsize = 0; /* Default later, based on 'c' option for cart tapes */ 35: tape = TAPE; 36: disk = DISK; 37: increm = NINCREM; 38: temp = TEMP; 39: if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) { 40: msg("TP_BSIZE must be a multiple of DEV_BSIZE\n"); 41: dumpabort(); 42: } 43: incno = '9'; 44: uflag = 0; 45: arg = "u"; 46: if(argc > 1) { 47: argv++; 48: argc--; 49: arg = *argv; 50: if (*arg == '-') 51: argc++; 52: } 53: while(*arg) 54: switch (*arg++) { 55: case 'w': 56: lastdump('w'); /* tell us only what has to be done */ 57: exit(0); 58: break; 59: case 'W': /* what to do */ 60: lastdump('W'); /* tell us the current state of what has been done */ 61: exit(0); /* do nothing else */ 62: break; 63: 64: case 'f': /* output file */ 65: if(argc > 1) { 66: argv++; 67: argc--; 68: tape = *argv; 69: } 70: break; 71: 72: case 'd': /* density, in bits per inch */ 73: if (argc > 1) { 74: argv++; 75: argc--; 76: density = atoi(*argv) / 10; 1.1.1.2 ! root 77: if (density >= 625 && !bflag) ! 78: ntrec = HIGHDENSITYTREC; 1.1 root 79: } 80: break; 81: 82: case 's': /* tape size, feet */ 83: if(argc > 1) { 84: argv++; 85: argc--; 86: tsize = atol(*argv); 87: tsize *= 12L*10L; 88: } 89: break; 90: 91: case 'b': /* blocks per tape write */ 92: if(argc > 1) { 93: argv++; 94: argc--; 1.1.1.2 ! root 95: bflag++; 1.1 root 96: ntrec = atol(*argv); 97: } 98: break; 99: 100: case 'c': /* Tape is cart. not 9-track */ 101: cartridge++; 102: break; 103: 104: case '0': /* dump level */ 105: case '1': 106: case '2': 107: case '3': 108: case '4': 109: case '5': 110: case '6': 111: case '7': 112: case '8': 113: case '9': 114: incno = arg[-1]; 115: break; 116: 117: case 'u': /* update /etc/dumpdates */ 118: uflag++; 119: break; 120: 121: case 'n': /* notify operators */ 122: notify++; 123: break; 124: 125: default: 126: fprintf(stderr, "bad key '%c%'\n", arg[-1]); 127: Exit(X_ABORT); 128: } 129: if(argc > 1) { 130: argv++; 131: argc--; 132: disk = *argv; 133: } 134: if (strcmp(tape, "-") == 0) { 135: pipeout++; 136: tape = "standard output"; 137: } 138: 139: /* 140: * Determine how to default tape size and density 141: * 142: * density tape size 143: * 9-track 1600 bpi (160 bytes/.1") 2300 ft. 144: * 9-track 6250 bpi (625 bytes/.1") 2300 ft. 1.1.1.2 ! root 145: * cartridge 8000 bpi (100 bytes/.1") 1700 ft. (450*4 - slop) 1.1 root 146: */ 147: if (density == 0) 148: density = cartridge ? 100 : 160; 149: if (tsize == 0) 1.1.1.2 ! root 150: tsize = cartridge ? 1700L*120L : 2300L*120L; 1.1 root 151: 152: #ifdef RDUMP 153: { char *index(); 154: host = tape; 155: tape = index(host, ':'); 156: if (tape == 0) { 157: msg("need keyletter ``f'' and device ``host:tape''"); 158: exit(1); 159: } 160: *tape++ = 0; 161: if (rmthost(host) == 0) 162: exit(X_ABORT); 163: } 164: #endif 165: if (signal(SIGHUP, sighup) == SIG_IGN) 166: signal(SIGHUP, SIG_IGN); 167: if (signal(SIGTRAP, sigtrap) == SIG_IGN) 168: signal(SIGTRAP, SIG_IGN); 169: if (signal(SIGFPE, sigfpe) == SIG_IGN) 170: signal(SIGFPE, SIG_IGN); 171: if (signal(SIGBUS, sigbus) == SIG_IGN) 172: signal(SIGBUS, SIG_IGN); 173: if (signal(SIGSEGV, sigsegv) == SIG_IGN) 174: signal(SIGSEGV, SIG_IGN); 175: if (signal(SIGTERM, sigterm) == SIG_IGN) 176: signal(SIGTERM, SIG_IGN); 177: 178: 179: if (signal(SIGINT, interrupt) == SIG_IGN) 180: signal(SIGINT, SIG_IGN); 181: 182: set_operators(); /* /etc/group snarfed */ 183: getfstab(); /* /etc/fstab snarfed */ 184: /* 185: * disk can be either the full special file name, 186: * the suffix of the special file name, 187: * the special name missing the leading '/', 188: * the file system name with or without the leading '/'. 189: */ 190: dt = fstabsearch(disk); 191: if (dt != 0) 192: disk = rawname(dt->fs_spec); 193: getitime(); /* /etc/dumpdates snarfed */ 194: 195: msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date)); 196: msg("Date of last level %c dump: %s\n", 197: lastincno, prdate(spcl.c_ddate)); 198: msg("Dumping %s ", disk); 199: if (dt != 0) 200: msgtail("(%s) ", dt->fs_file); 201: #ifdef RDUMP 202: msgtail("to %s on host %s\n", tape, host); 203: #else 204: msgtail("to %s\n", tape); 205: #endif 206: 207: fi = open(disk, 0); 208: if (fi < 0) { 209: msg("Cannot open %s\n", disk); 210: Exit(X_ABORT); 211: } 212: esize = 0; 213: sblock = (struct fs *)buf; 214: sync(); 215: bread(SBLOCK, sblock, SBSIZE); 216: if (sblock->fs_magic != FS_MAGIC) { 217: msg("bad sblock magic number\n"); 218: dumpabort(); 219: } 220: msiz = roundup(howmany(sblock->fs_ipg * sblock->fs_ncg, NBBY), 221: TP_BSIZE); 222: clrmap = (char *)calloc(msiz, sizeof(char)); 223: dirmap = (char *)calloc(msiz, sizeof(char)); 224: nodmap = (char *)calloc(msiz, sizeof(char)); 225: 226: msg("mapping (Pass I) [regular files]\n"); 227: pass(mark, (char *)NULL); /* mark updates esize */ 228: 229: do { 230: msg("mapping (Pass II) [directories]\n"); 231: nadded = 0; 232: pass(add, dirmap); 233: } while(nadded); 234: 235: bmapest(clrmap); 236: bmapest(nodmap); 237: 238: if (cartridge) { 239: /* Estimate number of tapes, assuming streaming stops at 240: the end of each block written, and not in mid-block. 241: Assume no erroneous blocks; this can be compensated for 242: with an artificially low tape size. */ 243: fetapes = 244: ( esize /* blocks */ 245: * TP_BSIZE /* bytes/block */ 246: * (1.0/density) /* 0.1" / byte */ 247: + 248: esize /* blocks */ 249: * (1.0/ntrec) /* streaming-stops per block */ 250: * 15.48 /* 0.1" / streaming-stop */ 251: ) * (1.0 / tsize ); /* tape / 0.1" */ 252: } else { 253: /* Estimate number of tapes, for old fashioned 9-track tape */ 254: int tenthsperirg = (density == 625) ? 3 : 7; 255: fetapes = 256: ( esize /* blocks */ 257: * TP_BSIZE /* bytes / block */ 258: * (1.0/density) /* 0.1" / byte */ 259: + 260: esize /* blocks */ 261: * (1.0/ntrec) /* IRG's / block */ 262: * tenthsperirg /* 0.1" / IRG */ 263: ) * (1.0 / tsize ); /* tape / 0.1" */ 264: } 265: etapes = fetapes; /* truncating assignment */ 266: etapes++; 267: /* count the nodemap on each additional tape */ 268: for (i = 1; i < etapes; i++) 269: bmapest(nodmap); 270: esize += i + 10; /* headers + 10 trailer blocks */ 271: msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes); 272: 273: alloctape(); /* Allocate tape buffer */ 274: 275: otape(); /* bitmap is the first to tape write */ 276: time(&(tstart_writing)); 277: bitmap(clrmap, TS_CLRI); 278: 279: msg("dumping (Pass III) [directories]\n"); 1.1.1.2 ! root 280: pass(dirdump, dirmap); 1.1 root 281: 282: msg("dumping (Pass IV) [regular files]\n"); 283: pass(dump, nodmap); 284: 285: spcl.c_type = TS_END; 286: #ifndef RDUMP 287: for(i=0; i<ntrec; i++) 288: spclrec(); 289: #endif 290: msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume); 291: msg("DUMP IS DONE\n"); 292: 293: putitime(); 294: #ifndef RDUMP 295: if (!pipeout) { 296: close(to); 297: tape_rewind(); 298: } 299: #else 300: tflush(1); 301: tape_rewind(); 302: #endif 303: broadcast("DUMP IS DONE!\7\7\n"); 304: Exit(X_FINOK); 305: } 306: 307: int sighup(){ msg("SIGHUP() try rewriting\n"); sigAbort();} 308: int sigtrap(){ msg("SIGTRAP() try rewriting\n"); sigAbort();} 309: int sigfpe(){ msg("SIGFPE() try rewriting\n"); sigAbort();} 310: int sigbus(){ msg("SIGBUS() try rewriting\n"); sigAbort();} 311: int sigsegv(){ msg("SIGSEGV() ABORTING!\n"); abort();} 312: int sigalrm(){ msg("SIGALRM() try rewriting\n"); sigAbort();} 313: int sigterm(){ msg("SIGTERM() try rewriting\n"); sigAbort();} 314: 315: sigAbort() 316: { 317: if (pipeout) { 318: msg("Unknown signal, cannot recover\n"); 319: dumpabort(); 320: } 321: msg("Rewriting attempted as response to unknown signal.\n"); 322: fflush(stderr); 323: fflush(stdout); 324: close_rewind(); 325: exit(X_REWRITE); 326: } 327: 328: char *rawname(cp) 329: char *cp; 330: { 331: static char rawbuf[32]; 332: char *rindex(); 333: char *dp = rindex(cp, '/'); 334: 335: if (dp == 0) 336: return (0); 337: *dp = 0; 338: strcpy(rawbuf, cp); 339: *dp = '/'; 340: strcat(rawbuf, "/r"); 341: strcat(rawbuf, dp+1); 342: return (rawbuf); 343: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.