1*12331Smckusick static char *sccsid = "@(#)main.c 1.12 (Berkeley) 05/08/83"; 21423Sroot #include "dump.h" 31423Sroot 41423Sroot int notify = 0; /* notify operator flag */ 51423Sroot int blockswritten = 0; /* number of blocks written on current tape */ 61423Sroot int tapeno = 0; /* current tape number */ 710910Ssam int density = 0; /* density in bytes/0.1" */ 810910Ssam int ntrec = NTREC; /* # tape blocks in each tape record */ 910910Ssam int cartridge = 0; /* Assume non-cartridge tape */ 106882Ssam #ifdef RDUMP 116882Ssam char *host; 126882Ssam #endif 131423Sroot 141423Sroot main(argc, argv) 151423Sroot int argc; 161423Sroot char *argv[]; 171423Sroot { 181423Sroot char *arg; 195328Smckusic int i; 201423Sroot float fetapes; 211423Sroot register struct fstab *dt; 221423Sroot 231423Sroot time(&(spcl.c_date)); 241423Sroot 2510910Ssam tsize = 0; /* Default later, based on 'c' option for cart tapes */ 261423Sroot tape = TAPE; 271423Sroot disk = DISK; 281423Sroot increm = NINCREM; 295328Smckusic if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) { 305328Smckusic msg("TP_BSIZE must be a multiple of DEV_BSIZE\n"); 315328Smckusic dumpabort(); 325328Smckusic } 331423Sroot incno = '9'; 341423Sroot uflag = 0; 351423Sroot arg = "u"; 361423Sroot if(argc > 1) { 371423Sroot argv++; 381423Sroot argc--; 391423Sroot arg = *argv; 401423Sroot if (*arg == '-') 411423Sroot argc++; 421423Sroot } 431423Sroot while(*arg) 441423Sroot switch (*arg++) { 451463Sroot case 'w': 461463Sroot lastdump('w'); /* tell us only what has to be done */ 471463Sroot exit(0); 481463Sroot break; 491423Sroot case 'W': /* what to do */ 501463Sroot lastdump('W'); /* tell us the current state of what has been done */ 511423Sroot exit(0); /* do nothing else */ 521423Sroot break; 531423Sroot 541423Sroot case 'J': /* update old to new */ 551423Sroot o_nconvert(); 561423Sroot exit(0); /* do nothing else */ 571423Sroot break; 581423Sroot 591423Sroot case 'f': /* output file */ 601423Sroot if(argc > 1) { 611423Sroot argv++; 621423Sroot argc--; 631423Sroot tape = *argv; 641423Sroot } 651423Sroot break; 661423Sroot 671423Sroot case 'd': /* density, in bits per inch */ 681423Sroot if (argc > 1) { 691423Sroot argv++; 701423Sroot argc--; 711423Sroot density = atoi(*argv) / 10; 721423Sroot } 731423Sroot break; 741423Sroot 751423Sroot case 's': /* tape size, feet */ 761423Sroot if(argc > 1) { 771423Sroot argv++; 781423Sroot argc--; 791423Sroot tsize = atol(*argv); 801423Sroot tsize *= 12L*10L; 811423Sroot } 821423Sroot break; 831423Sroot 8410910Ssam case 'b': /* blocks per tape write */ 8510910Ssam if(argc > 1) { 8610910Ssam argv++; 8710910Ssam argc--; 8810910Ssam ntrec = atol(*argv); 8910910Ssam } 9010910Ssam break; 9110910Ssam 9210910Ssam case 'c': /* Tape is cart. not 9-track */ 9310910Ssam cartridge++; 9410910Ssam break; 9510910Ssam 961423Sroot case '0': /* dump level */ 971423Sroot case '1': 981423Sroot case '2': 991423Sroot case '3': 1001423Sroot case '4': 1011423Sroot case '5': 1021423Sroot case '6': 1031423Sroot case '7': 1041423Sroot case '8': 1051423Sroot case '9': 1061423Sroot incno = arg[-1]; 1071423Sroot break; 1081423Sroot 1091423Sroot case 'u': /* update /etc/dumpdates */ 1101423Sroot uflag++; 1111423Sroot break; 1121423Sroot 1131423Sroot case 'n': /* notify operators */ 1141423Sroot notify++; 1151423Sroot break; 1161423Sroot 1171423Sroot default: 118*12331Smckusick fprintf(stderr, "bad key '%c%'\n", arg[-1]); 1191423Sroot Exit(X_ABORT); 1201423Sroot } 1211423Sroot if(argc > 1) { 1221423Sroot argv++; 1231423Sroot argc--; 1241423Sroot disk = *argv; 1251423Sroot } 126*12331Smckusick if (strcmp(tape, "-") == 0) { 127*12331Smckusick pipeout++; 128*12331Smckusick tape = "standard output"; 129*12331Smckusick } 13010910Ssam 13110910Ssam /* 13210910Ssam * Determine how to default tape size and density 13310910Ssam * 13410910Ssam * density tape size 13510910Ssam * 9-track 1600 bpi (160 bytes/.1") 2300 ft. 13610910Ssam * 9-track 6250 bpi (625 bytes/.1") 2300 ft. 13710910Ssam * cartridge 8000 bpi (100 bytes/.1") 4000 ft. (450*9 - slop) 13810910Ssam */ 13910910Ssam if (density == 0) 14010910Ssam density = cartridge ? 100 : 160; 14110910Ssam if (tsize == 0) 14210910Ssam tsize = cartridge ? 4000L*120L : 2300L*120L; 14310910Ssam 1446886Ssam #ifdef RDUMP 1456886Ssam { char *index(); 1466886Ssam host = tape; 1476886Ssam tape = index(host, ':'); 1486886Ssam if (tape == 0) { 1496886Ssam msg("need keyletter ``f'' and device ``host:tape''"); 1506886Ssam exit(1); 1516886Ssam } 1526886Ssam *tape++ = 0; 1536886Ssam if (rmthost(host) == 0) 1546886Ssam exit(X_ABORT); 1556886Ssam } 1566886Ssam #endif 1571423Sroot if (signal(SIGHUP, sighup) == SIG_IGN) 1581423Sroot signal(SIGHUP, SIG_IGN); 1591423Sroot if (signal(SIGTRAP, sigtrap) == SIG_IGN) 1601423Sroot signal(SIGTRAP, SIG_IGN); 1611423Sroot if (signal(SIGFPE, sigfpe) == SIG_IGN) 1621423Sroot signal(SIGFPE, SIG_IGN); 1631423Sroot if (signal(SIGBUS, sigbus) == SIG_IGN) 1641423Sroot signal(SIGBUS, SIG_IGN); 1651423Sroot if (signal(SIGSEGV, sigsegv) == SIG_IGN) 1661423Sroot signal(SIGSEGV, SIG_IGN); 1671423Sroot if (signal(SIGTERM, sigterm) == SIG_IGN) 1681423Sroot signal(SIGTERM, SIG_IGN); 1691423Sroot 1701423Sroot 1711423Sroot if (signal(SIGINT, interrupt) == SIG_IGN) 1721423Sroot signal(SIGINT, SIG_IGN); 1731423Sroot 1741423Sroot set_operators(); /* /etc/group snarfed */ 1751423Sroot getfstab(); /* /etc/fstab snarfed */ 1761423Sroot /* 1771423Sroot * disk can be either the full special file name, 1781423Sroot * the suffix of the special file name, 1791423Sroot * the special name missing the leading '/', 1801423Sroot * the file system name with or without the leading '/'. 1811423Sroot */ 1821423Sroot dt = fstabsearch(disk); 1831423Sroot if (dt != 0) 1841423Sroot disk = rawname(dt->fs_spec); 1851423Sroot getitime(); /* /etc/dumpdates snarfed */ 1861423Sroot 1871423Sroot msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date)); 1881423Sroot msg("Date of last level %c dump: %s\n", incno, prdate(spcl.c_ddate)); 1891423Sroot msg("Dumping %s ", disk); 1901423Sroot if (dt != 0) 1911423Sroot msgtail("(%s) ", dt->fs_file); 1928506Smckusick #ifdef RDUMP 1938506Smckusick msgtail("to %s on host %s\n", tape, host); 1948506Smckusick #else 1958371Smckusick msgtail("to %s\n", tape); 1966882Ssam #endif 1971423Sroot 1981423Sroot fi = open(disk, 0); 1991423Sroot if (fi < 0) { 2001423Sroot msg("Cannot open %s\n", disk); 2011423Sroot Exit(X_ABORT); 2021423Sroot } 2031423Sroot esize = 0; 2045328Smckusic sblock = (struct fs *)buf; 2055328Smckusic sync(); 2065342Smckusic bread(SBLOCK, sblock, SBSIZE); 2075328Smckusic if (sblock->fs_magic != FS_MAGIC) { 2085328Smckusic msg("bad sblock magic number\n"); 2095328Smckusic dumpabort(); 2105328Smckusic } 2115328Smckusic msiz = roundup(howmany(sblock->fs_ipg * sblock->fs_ncg, NBBY), 2125328Smckusic TP_BSIZE); 2135328Smckusic clrmap = (char *)calloc(msiz, sizeof(char)); 2145328Smckusic dirmap = (char *)calloc(msiz, sizeof(char)); 2155328Smckusic nodmap = (char *)calloc(msiz, sizeof(char)); 2161423Sroot 2171423Sroot msg("mapping (Pass I) [regular files]\n"); 2185328Smckusic pass(mark, (char *)NULL); /* mark updates esize */ 2191423Sroot 2201423Sroot do { 2211423Sroot msg("mapping (Pass II) [directories]\n"); 2221423Sroot nadded = 0; 2231423Sroot pass(add, dirmap); 2241423Sroot } while(nadded); 2251423Sroot 2261423Sroot bmapest(clrmap); 2271423Sroot bmapest(nodmap); 2281423Sroot 22910910Ssam if (cartridge) { 23010910Ssam /* Estimate number of tapes, assuming streaming stops at 23110910Ssam the end of each block written, and not in mid-block. 23210910Ssam Assume no erroneous blocks; this can be compensated for 23310910Ssam with an artificially low tape size. */ 23410910Ssam fetapes = 2355328Smckusic ( esize /* blocks */ 23610910Ssam * TP_BSIZE /* bytes/block */ 23710910Ssam * (1.0/density) /* 0.1" / byte */ 23810910Ssam + 23910910Ssam esize /* blocks */ 24010910Ssam * (1.0/ntrec) /* streaming-stops per block */ 24110910Ssam * 15.48 /* 0.1" / streaming-stop */ 24210910Ssam ) * (1.0 / tsize ); /* tape / 0.1" */ 24310910Ssam } else { 24410910Ssam /* Estimate number of tapes, for old fashioned 9-track tape */ 24510910Ssam int tenthsperirg = (density == 625) ? 3 : 7; 24610910Ssam fetapes = 24710910Ssam ( esize /* blocks */ 2485328Smckusic * TP_BSIZE /* bytes / block */ 2495328Smckusic * (1.0/density) /* 0.1" / byte */ 2501423Sroot + 2515328Smckusic esize /* blocks */ 25210910Ssam * (1.0/ntrec) /* IRG's / block */ 25310910Ssam * tenthsperirg /* 0.1" / IRG */ 2545328Smckusic * 7 /* 0.1" / IRG */ 25510910Ssam ) * (1.0 / tsize ); /* tape / 0.1" */ 25610910Ssam } 2571423Sroot etapes = fetapes; /* truncating assignment */ 2581423Sroot etapes++; 2595328Smckusic /* count the nodemap on each additional tape */ 2605328Smckusic for (i = 1; i < etapes; i++) 2615328Smckusic bmapest(nodmap); 2625328Smckusic esize += i + 10; /* headers + 10 trailer blocks */ 2631423Sroot msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes); 2641423Sroot 26510910Ssam alloctape(); /* Allocate tape buffer */ 26610910Ssam 2671423Sroot otape(); /* bitmap is the first to tape write */ 2681423Sroot time(&(tstart_writing)); 2691423Sroot bitmap(clrmap, TS_CLRI); 2701423Sroot 2711423Sroot msg("dumping (Pass III) [directories]\n"); 2721423Sroot pass(dump, dirmap); 2731423Sroot 2741423Sroot msg("dumping (Pass IV) [regular files]\n"); 2751423Sroot pass(dump, nodmap); 2761423Sroot 2771423Sroot spcl.c_type = TS_END; 2786882Ssam #ifndef RDUMP 27910910Ssam for(i=0; i<ntrec; i++) 2801423Sroot spclrec(); 2816882Ssam #endif 2821423Sroot msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume); 2831423Sroot msg("DUMP IS DONE\n"); 2841423Sroot 2851423Sroot putitime(); 2866882Ssam #ifndef RDUMP 287*12331Smckusick if (!pipeout) { 288*12331Smckusick close(to); 289*12331Smckusick rewind(); 290*12331Smckusick } 2916882Ssam #else 2926882Ssam tflush(1); 293*12331Smckusick rewind(); 2946882Ssam #endif 2951423Sroot broadcast("DUMP IS DONE!\7\7\n"); 2961423Sroot Exit(X_FINOK); 2971423Sroot } 2981423Sroot 2991423Sroot int sighup(){ msg("SIGHUP() try rewriting\n"); sigAbort();} 3001423Sroot int sigtrap(){ msg("SIGTRAP() try rewriting\n"); sigAbort();} 3011423Sroot int sigfpe(){ msg("SIGFPE() try rewriting\n"); sigAbort();} 3021423Sroot int sigbus(){ msg("SIGBUS() try rewriting\n"); sigAbort();} 3031423Sroot int sigsegv(){ msg("SIGSEGV() ABORTING!\n"); abort();} 3041423Sroot int sigalrm(){ msg("SIGALRM() try rewriting\n"); sigAbort();} 3051423Sroot int sigterm(){ msg("SIGTERM() try rewriting\n"); sigAbort();} 3061423Sroot 3071423Sroot sigAbort() 3081423Sroot { 309*12331Smckusick if (pipeout) { 310*12331Smckusick msg("Unknown signal, cannot recover\n"); 311*12331Smckusick dumpabort(); 312*12331Smckusick } 3131423Sroot msg("Rewriting attempted as response to unknown signal.\n"); 3141423Sroot fflush(stderr); 3151423Sroot fflush(stdout); 3161423Sroot close_rewind(); 3171423Sroot exit(X_REWRITE); 3181423Sroot } 3191423Sroot 3201423Sroot char *rawname(cp) 3211423Sroot char *cp; 3221423Sroot { 3231423Sroot static char rawbuf[32]; 3244608Smckusic char *rindex(); 3251423Sroot char *dp = rindex(cp, '/'); 3261423Sroot 3271423Sroot if (dp == 0) 3281423Sroot return (0); 3291423Sroot *dp = 0; 3301423Sroot strcpy(rawbuf, cp); 3311423Sroot *dp = '/'; 3321423Sroot strcat(rawbuf, "/r"); 3331423Sroot strcat(rawbuf, dp+1); 3341423Sroot return (rawbuf); 3351423Sroot } 336