1: #if !defined(lint) && defined(DOSCCS) 2: static char *sccsid = "@(#)dumpmain.c 1.4 (2.11BSD GTE) 1996/2/7"; 3: #endif 4: 5: #include "dump.h" 6: 7: long blocksperfile; 8: int cartridge = 0; 9: static long numarg(); 10: static void missingarg(); 11: 12: char *host = NULL; 13: 14: main(argc, argv) 15: int argc; 16: char *argv[]; 17: { 18: register char *cp; 19: int i, Tflag = 0, honorlevel = 1, mapsize; 20: register struct fstab *dt; 21: 22: density = 160; /* density in 0.1" units */ 23: time(&(spcl.c_date)); 24: 25: tsize = 0; /* Default later, based on 'c' option for cart tapes */ 26: tape = TAPE; 27: increm = NINCREM; 28: incno = '0'; 29: 30: if (argc == 1) { 31: (void) fprintf(stderr, "Must specify a key.\n"); 32: Exit(X_ABORT); 33: } 34: argv++; 35: argc -= 2; 36: 37: for (cp = *argv++; *cp; cp++) { 38: switch (*cp) { 39: case '-': 40: break; 41: 42: case 'w': 43: lastdump('w'); /* tell us only what has to be done */ 44: exit(0); 45: break; 46: 47: case 'W': /* what to do */ 48: lastdump('W'); /* tell us state of what is done */ 49: exit(0); /* do nothing else */ 50: 51: case 'f': /* output file */ 52: if (argc < 1) 53: missingarg('f', "output file"); 54: tape = *argv++; 55: argc--; 56: break; 57: 58: case 'd': /* density, in bits per inch */ 59: density = numarg('d', "density", 60: 10L, 327670L, &argc, &argv) / 10; 61: break; 62: 63: case 's': /* tape size, feet */ 64: tsize = numarg('s', "size", 65: 1L, 0L, &argc, &argv) * 12 * 10; 66: break; 67: 68: case 'T': /* time of last dump */ 69: if (argc < 1) 70: missingarg('T', "time of last dump"); 71: spcl.c_ddate = unctime(*argv); 72: if (spcl.c_ddate < 0) { 73: (void)fprintf(stderr, "bad time \"%s\"\n", 74: *argv); 75: exit(X_ABORT); 76: } 77: Tflag = 1; 78: lastlevel = '?'; 79: argc--; 80: argv++; 81: break; 82: #ifdef notnow 83: case 'b': /* blocks per tape write */ 84: ntrec = numarg('b', "number of blocks per write", 85: 1L, 1000L, &argc, &argv); 86: break; 87: #endif 88: 89: case 'B': /* blocks per output file */ 90: blocksperfile = numarg('B', "number of blocks per file", 91: 1L, 0L, &argc, &argv); 92: break; 93: 94: case 'c': /* Tape is cart. not 9-track */ 95: cartridge = 1; 96: break; 97: 98: /* dump level */ 99: case '0': case '1': case '2': case '3': case '4': 100: case '5': case '6': case '7': case '8': case '9': 101: incno = *cp; 102: break; 103: 104: case 'u': /* update /etc/dumpdates */ 105: uflag++; 106: break; 107: 108: case 'n': /* notify operators */ 109: notify++; 110: break; 111: 112: case 'h': 113: honorlevel = numarg('h', "honor level", 114: 0L, 10L, &argc, &argv); 115: break; 116: 117: default: 118: fprintf(stderr, "bad key '%c%'\n", *cp); 119: exit(X_ABORT); 120: } 121: } 122: if (argc < 1) { 123: (void)fprintf(stderr, "Must specify disk or filesystem\n"); 124: exit(X_ABORT); 125: } 126: disk = *argv++; 127: argc--; 128: if (argc >= 1) { 129: (void)fprintf(stderr, "Unknown arguments to dump:"); 130: while (argc--) 131: (void)fprintf(stderr, " %s", *argv++); 132: (void)fprintf(stderr, "\n"); 133: exit(X_ABORT); 134: } 135: if (Tflag && uflag) { 136: (void)fprintf(stderr, 137: "You cannot use the T and u flags together.\n"); 138: exit(X_ABORT); 139: } 140: if (strcmp(tape, "-") == 0) { 141: pipeout++; 142: tape = "standard output"; 143: } 144: 145: if (blocksperfile) 146: blocksperfile = blocksperfile / NTREC * NTREC; /* round down */ 147: else { 148: /* 149: * Determine how to default tape size and density 150: * 151: * density tape size 152: * 9-track 1600 bpi (160 bytes/.1") 2300 ft. 153: * 9-track 6250 bpi (625 bytes/.1") 2300 ft. 154: * cartridge 8000 bpi (100 bytes/.1") 1700 ft. 155: * (450*4 - slop) 156: */ 157: if (density == 0) 158: density = cartridge ? 100 : 160; 159: if (tsize == 0) 160: tsize = cartridge ? 1700L*120L : 2300L*120L; 161: } 162: 163: if (index(tape, ':')) { 164: host = tape; 165: tape = index(host, ':'); 166: *tape++ = '\0'; 167: #ifdef RDUMP 168: if (rmthost(host) == 0) 169: exit(X_ABORT); 170: #else 171: (void)fprintf(stderr, "remote dump not enabled\n"); 172: exit(X_ABORT); 173: #endif 174: } 175: (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */ 176: 177: if (signal(SIGHUP, sighup) == SIG_IGN) 178: signal(SIGHUP, SIG_IGN); 179: if (signal(SIGTRAP, sigtrap) == SIG_IGN) 180: signal(SIGTRAP, SIG_IGN); 181: if (signal(SIGFPE, sigfpe) == SIG_IGN) 182: signal(SIGFPE, SIG_IGN); 183: if (signal(SIGBUS, sigbus) == SIG_IGN) 184: signal(SIGBUS, SIG_IGN); 185: if (signal(SIGSEGV, sigsegv) == SIG_IGN) 186: signal(SIGSEGV, SIG_IGN); 187: if (signal(SIGTERM, sigterm) == SIG_IGN) 188: signal(SIGTERM, SIG_IGN); 189: if (signal(SIGINT, interrupt) == SIG_IGN) 190: signal(SIGINT, SIG_IGN); 191: 192: set_operators(); /* /etc/group snarfed */ 193: /* 194: * disk can be either the character or block special file name, 195: * or the full file system path name. 196: */ 197: if (dt = getfsfile(disk)) 198: disk = rawname(dt->fs_spec); 199: else 200: if (dt = getfsspec(disk)) 201: disk = rawname(disk); 202: else 203: dt = getfsspec(deraw(disk)); 204: 205: if (!Tflag) 206: getitime(); /* /etc/dumpdates snarfed */ 207: 208: msg("Date of this level %c dump: %s\n", incno, 209: prdate(spcl.c_date)); 210: msg("Date of last level %c dump: %s\n", lastlevel, 211: prdate(spcl.c_ddate)); 212: msg("Dumping %s ", disk); 213: if (dt != 0) 214: msgtail("(%s) ", dt->fs_file); 215: if (host) 216: msgtail("to %s on host %s\n", tape, host); 217: else 218: msgtail("to %s\n", tape); 219: 220: fi = open(disk, 0); 221: if (fi < 0) { 222: msg("Cannot open %s\n", disk); 223: Exit(X_ABORT); 224: } 225: bzero(clrmap, sizeof (clrmap)); 226: bzero(dirmap, sizeof (dirmap)); 227: bzero(nodmap, sizeof (nodmap)); 228: mapsize = roundup(howmany(sizeof(dirmap),NBBY), DEV_BSIZE); 229: 230: esize = 0; 231: 232: nonodump = (incno - '0') < honorlevel; 233: 234: msg("mapping (Pass I) [regular files]\n"); 235: pass(mark, (short *)NULL); /* mark updates esize */ 236: 237: do { 238: msg("mapping (Pass II) [directories]\n"); 239: nadded = 0; 240: pass(add, dirmap); 241: } while(nadded); 242: 243: bmapest(clrmap); 244: bmapest(nodmap); 245: 246: if (pipeout) { 247: esize += 10; /* 10 trailer blocks */ 248: msg("estimated %ld tape blocks.\n", esize); 249: } else { 250: double fetapes; 251: 252: if (blocksperfile) 253: fetapes = (double) esize / blocksperfile; 254: else if (cartridge) { 255: /* Estimate number of tapes, assuming streaming stops at 256: the end of each block written, and not in mid-block. 257: Assume no erroneous blocks; this can be compensated 258: for with an artificially low tape size. */ 259: fetapes = 260: ( esize /* blocks */ 261: * DEV_BSIZE /* bytes/block */ 262: * (1.0/density) /* 0.1" / byte */ 263: + 264: esize /* blocks */ 265: * (1.0/NTREC) /* streaming-stops per block */ 266: * 15.48 /* 0.1" / streaming-stop */ 267: ) * (1.0 / tsize ); /* tape / 0.1" */ 268: } else { 269: /* Estimate number of tapes, for old fashioned 9-track 270: tape */ 271: int tenthsperirg = (density == 625) ? 3 : 7; 272: fetapes = 273: ( esize /* blocks */ 274: * DEV_BSIZE /* bytes / block */ 275: * (1.0/density) /* 0.1" / byte */ 276: + 277: esize /* blocks */ 278: * (1.0/NTREC) /* IRG's / block */ 279: * tenthsperirg /* 0.1" / IRG */ 280: ) * (1.0 / tsize ); /* tape / 0.1" */ 281: } 282: etapes = fetapes; /* truncating assignment */ 283: etapes++; 284: /* count the dumped inodes map on each additional tape */ 285: esize += (etapes - 1) * 286: (howmany(mapsize * sizeof(char), DEV_BSIZE) + 1); 287: esize += etapes + 10; /* headers + 10 trailer blks */ 288: msg("estimated %ld tape blocks on %3.2f tape(s).\n", 289: esize, fetapes); 290: } 291: 292: alloctape(); /* Allocate tape buffer */ 293: 294: otape(); /* bitmap is the first to tape write */ 295: time(&(tstart_writing)); 296: bitmap(clrmap, TS_CLRI); 297: 298: msg("dumping (Pass III) [directories]\n"); 299: pass(dump, dirmap); 300: 301: msg("dumping (Pass IV) [regular files]\n"); 302: pass(dump, nodmap); 303: 304: spcl.c_type = TS_END; 305: for(i=0; i<NTREC; i++) 306: spclrec(); 307: msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume); 308: msg("DUMP IS DONE\n"); 309: 310: putitime(); 311: tape_rewind(); 312: broadcast("DUMP IS DONE!\7\7\n"); 313: Exit(X_FINOK); 314: } 315: 316: /* 317: * Pick up a numeric argument. It must be nonnegative and in the given 318: * range (except that a vmax of 0 means unlimited). 319: */ 320: static long 321: numarg(letter, meaning, vmin, vmax, pargc, pargv) 322: int letter; 323: char *meaning; 324: long vmin, vmax; 325: int *pargc; 326: char ***pargv; 327: { 328: register char *p; 329: long val; 330: char *str; 331: 332: if (--*pargc < 0) 333: missingarg(letter, meaning); 334: str = *(*pargv)++; 335: for (p = str; *p; p++) 336: if (!isdigit(*p)) 337: goto bad; 338: val = atol(str); 339: if (val < vmin || (vmax && val > vmax)) 340: goto bad; 341: return (val); 342: 343: bad: 344: (void)fprintf(stderr, "bad '%c' (%s) value \"%s\"\n", 345: letter, meaning, str); 346: exit(X_ABORT); 347: /* NOTREACHED */ 348: } 349: 350: static void 351: missingarg(letter, meaning) 352: int letter; 353: char *meaning; 354: { 355: 356: (void)fprintf(stderr, "The '%c' flag (%s) requires an argument\n", 357: letter, meaning); 358: exit(X_ABORT); 359: } 360: 361: int sighup(){ msg("SIGHUP() try rewriting\n"); sigAbort();} 362: int sigtrap(){ msg("SIGTRAP() try rewriting\n"); sigAbort();} 363: int sigfpe(){ msg("SIGFPE() try rewriting\n"); sigAbort();} 364: int sigbus(){ msg("SIGBUS() try rewriting\n"); sigAbort();} 365: int sigsegv(){ msg("SIGSEGV() ABORTING!\n"); abort();} 366: int sigalrm(){ msg("SIGALRM() try rewriting\n"); sigAbort();} 367: int sigterm(){ msg("SIGTERM() try rewriting\n"); sigAbort();} 368: 369: sigAbort() 370: { 371: if (pipeout) { 372: msg("Unknown signal, cannot recover\n"); 373: dumpabort(); 374: } 375: msg("Rewriting attempted as response to unknown signal.\n"); 376: fflush(stderr); 377: fflush(stdout); 378: close_rewind(); 379: exit(X_REWRITE); 380: } 381: 382: char *rawname(cp) 383: char *cp; 384: { 385: static char rawbuf[32]; 386: char *dp = rindex(cp, '/'); 387: 388: if (dp == 0) 389: return ((char *) 0); 390: *dp = '\0'; 391: strcpy(rawbuf, cp); 392: *dp++ = '/'; 393: strcat(rawbuf, "/r"); 394: strcat(rawbuf, dp); 395: return (rawbuf); 396: } 397: 398: char *deraw(cp) 399: char *cp; 400: { 401: static char rawbuf[32]; 402: register char *dp; 403: register char *tp; 404: 405: strcpy(rawbuf, cp); 406: 407: dp = rindex(rawbuf, '/'); 408: if (dp++ == 0) 409: return((char *) 0); 410: 411: tp = dp++; 412: while (*tp++ = *dp++); 413: return(rawbuf); 414: }