1*12082Smckusick static char *sccsid = "@(#)dumpmain.c 1.3 (Berkeley) 04/28/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 */ 71423Sroot int density = 160; /* density in 0.1" units */ 81423Sroot 91423Sroot main(argc, argv) 101423Sroot int argc; 111423Sroot char *argv[]; 121423Sroot { 131423Sroot char *arg; 141423Sroot register i; 151423Sroot float fetapes; 161423Sroot register struct fstab *dt; 171423Sroot 181423Sroot time(&(spcl.c_date)); 191423Sroot 201423Sroot tsize = 2300L*12L*10L; 211423Sroot tape = TAPE; 221423Sroot disk = DISK; 231423Sroot increm = NINCREM; 241423Sroot 251423Sroot incno = '9'; 261423Sroot uflag = 0; 271423Sroot arg = "u"; 281423Sroot if(argc > 1) { 291423Sroot argv++; 301423Sroot argc--; 311423Sroot arg = *argv; 321423Sroot if (*arg == '-') 331423Sroot argc++; 341423Sroot } 351423Sroot while(*arg) 361423Sroot switch (*arg++) { 371463Sroot case 'w': 381463Sroot lastdump('w'); /* tell us only what has to be done */ 391463Sroot exit(0); 401463Sroot break; 411423Sroot case 'W': /* what to do */ 421463Sroot lastdump('W'); /* tell us the current state of what has been done */ 431423Sroot exit(0); /* do nothing else */ 441423Sroot break; 451423Sroot 461423Sroot case 'J': /* update old to new */ 471423Sroot o_nconvert(); 481423Sroot exit(0); /* do nothing else */ 491423Sroot break; 501423Sroot 511423Sroot case 'f': /* output file */ 521423Sroot if(argc > 1) { 531423Sroot argv++; 541423Sroot argc--; 551423Sroot tape = *argv; 561423Sroot } 571423Sroot break; 581423Sroot 591423Sroot case 'd': /* density, in bits per inch */ 601423Sroot if (argc > 1) { 611423Sroot argv++; 621423Sroot argc--; 631423Sroot density = atoi(*argv) / 10; 641423Sroot } 651423Sroot break; 661423Sroot 671423Sroot case 's': /* tape size, feet */ 681423Sroot if(argc > 1) { 691423Sroot argv++; 701423Sroot argc--; 711423Sroot tsize = atol(*argv); 721423Sroot tsize *= 12L*10L; 731423Sroot } 741423Sroot break; 751423Sroot 761423Sroot case '0': /* dump level */ 771423Sroot case '1': 781423Sroot case '2': 791423Sroot case '3': 801423Sroot case '4': 811423Sroot case '5': 821423Sroot case '6': 831423Sroot case '7': 841423Sroot case '8': 851423Sroot case '9': 861423Sroot incno = arg[-1]; 871423Sroot break; 881423Sroot 891423Sroot case 'u': /* update /etc/dumpdates */ 901423Sroot uflag++; 911423Sroot break; 921423Sroot 931423Sroot case 'n': /* notify operators */ 941423Sroot notify++; 951423Sroot break; 961423Sroot 971423Sroot default: 98*12082Smckusick fprintf(stderr, "bad key '%c%'\n", arg[-1]); 991423Sroot Exit(X_ABORT); 1001423Sroot } 101*12082Smckusick if(strcmp(tape, "-") == 0) { 102*12082Smckusick pipeout++; 103*12082Smckusick tape = "standard output"; 104*12082Smckusick } 1051423Sroot if(argc > 1) { 1061423Sroot argv++; 1071423Sroot argc--; 1081423Sroot disk = *argv; 1091423Sroot } 1101423Sroot 1111423Sroot if (signal(SIGHUP, sighup) == SIG_IGN) 1121423Sroot signal(SIGHUP, SIG_IGN); 1131423Sroot if (signal(SIGTRAP, sigtrap) == SIG_IGN) 1141423Sroot signal(SIGTRAP, SIG_IGN); 1151423Sroot if (signal(SIGFPE, sigfpe) == SIG_IGN) 1161423Sroot signal(SIGFPE, SIG_IGN); 1171423Sroot if (signal(SIGBUS, sigbus) == SIG_IGN) 1181423Sroot signal(SIGBUS, SIG_IGN); 1191423Sroot if (signal(SIGSEGV, sigsegv) == SIG_IGN) 1201423Sroot signal(SIGSEGV, SIG_IGN); 1211423Sroot if (signal(SIGTERM, sigterm) == SIG_IGN) 1221423Sroot signal(SIGTERM, SIG_IGN); 1231423Sroot 1241423Sroot 1251423Sroot if (signal(SIGINT, interrupt) == SIG_IGN) 1261423Sroot signal(SIGINT, SIG_IGN); 1271423Sroot 1281423Sroot set_operators(); /* /etc/group snarfed */ 1291423Sroot getfstab(); /* /etc/fstab snarfed */ 1301423Sroot /* 1311423Sroot * disk can be either the full special file name, 1321423Sroot * the suffix of the special file name, 1331423Sroot * the special name missing the leading '/', 1341423Sroot * the file system name with or without the leading '/'. 1351423Sroot */ 1361423Sroot dt = fstabsearch(disk); 1371423Sroot if (dt != 0) 1381423Sroot disk = rawname(dt->fs_spec); 1391423Sroot getitime(); /* /etc/dumpdates snarfed */ 1401423Sroot 1411423Sroot msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date)); 1421423Sroot msg("Date of last level %c dump: %s\n", incno, prdate(spcl.c_ddate)); 1431423Sroot msg("Dumping %s ", disk); 1441423Sroot if (dt != 0) 1451423Sroot msgtail("(%s) ", dt->fs_file); 1461423Sroot msgtail("to %s\n", tape); 1471423Sroot 1481423Sroot fi = open(disk, 0); 1491423Sroot if (fi < 0) { 1501423Sroot msg("Cannot open %s\n", disk); 1511423Sroot Exit(X_ABORT); 1521423Sroot } 1531423Sroot CLR(clrmap); 1541423Sroot CLR(dirmap); 1551423Sroot CLR(nodmap); 1561423Sroot esize = 0; 1571423Sroot 1581423Sroot msg("mapping (Pass I) [regular files]\n"); 1591423Sroot pass(mark, (short *)NULL); /* mark updates esize */ 1601423Sroot 1611423Sroot do { 1621423Sroot msg("mapping (Pass II) [directories]\n"); 1631423Sroot nadded = 0; 1641423Sroot pass(add, dirmap); 1651423Sroot } while(nadded); 1661423Sroot 1671423Sroot bmapest(clrmap); 1681423Sroot bmapest(nodmap); 1691423Sroot 1701423Sroot fetapes = 1711423Sroot ( esize /* blocks */ 1721423Sroot *BSIZE /* bytes / block */ 1731423Sroot *(1.0/density) /* 0.1" / byte */ 1741423Sroot + 1751423Sroot esize /* blocks */ 1761423Sroot *(1.0/NTREC) /* IRG's / block */ 1771423Sroot *7 /* 0.1" / IRG */ 1781423Sroot ) * (1.0 / tsize ) /* tape / 0.1" */ 1791423Sroot ; 1801423Sroot etapes = fetapes; /* truncating assignment */ 1811423Sroot etapes++; 1821423Sroot /* 1831423Sroot * esize is typically about 5% too low; we frob it here 1841423Sroot */ 1851423Sroot esize += ((5*esize)/100); 1861423Sroot msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes); 1871423Sroot 1881423Sroot otape(); /* bitmap is the first to tape write */ 1891423Sroot time(&(tstart_writing)); 1901423Sroot bitmap(clrmap, TS_CLRI); 1911423Sroot 1921423Sroot msg("dumping (Pass III) [directories]\n"); 1931423Sroot pass(dump, dirmap); 1941423Sroot 1951423Sroot msg("dumping (Pass IV) [regular files]\n"); 1961423Sroot pass(dump, nodmap); 1971423Sroot 1981423Sroot spcl.c_type = TS_END; 1991423Sroot for(i=0; i<NTREC; i++) 2001423Sroot spclrec(); 2011423Sroot msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume); 2021423Sroot msg("DUMP IS DONE\n"); 2031423Sroot 2041423Sroot putitime(); 205*12082Smckusick if (!pipeout) { 206*12082Smckusick close(to); 207*12082Smckusick rewind(); 208*12082Smckusick } 2091423Sroot broadcast("DUMP IS DONE!\7\7\n"); 2101423Sroot Exit(X_FINOK); 2111423Sroot } 2121423Sroot 2131423Sroot int sighup(){ msg("SIGHUP() try rewriting\n"); sigAbort();} 2141423Sroot int sigtrap(){ msg("SIGTRAP() try rewriting\n"); sigAbort();} 2151423Sroot int sigfpe(){ msg("SIGFPE() try rewriting\n"); sigAbort();} 2161423Sroot int sigbus(){ msg("SIGBUS() try rewriting\n"); sigAbort();} 2171423Sroot int sigsegv(){ msg("SIGSEGV() ABORTING!\n"); abort();} 2181423Sroot int sigalrm(){ msg("SIGALRM() try rewriting\n"); sigAbort();} 2191423Sroot int sigterm(){ msg("SIGTERM() try rewriting\n"); sigAbort();} 2201423Sroot 2211423Sroot sigAbort() 2221423Sroot { 2231423Sroot msg("Rewriting attempted as response to unknown signal.\n"); 2241423Sroot fflush(stderr); 2251423Sroot fflush(stdout); 2261423Sroot close_rewind(); 2271423Sroot exit(X_REWRITE); 2281423Sroot } 2291423Sroot 2301423Sroot char *rawname(cp) 2311423Sroot char *cp; 2321423Sroot { 2331423Sroot static char rawbuf[32]; 234*12082Smckusick char *dp = (char *)rindex(cp, '/'); 2351423Sroot 2361423Sroot if (dp == 0) 2371423Sroot return (0); 2381423Sroot *dp = 0; 2391423Sroot strcpy(rawbuf, cp); 2401423Sroot *dp = '/'; 2411423Sroot strcat(rawbuf, "/r"); 2421423Sroot strcat(rawbuf, dp+1); 2431423Sroot return (rawbuf); 2441423Sroot } 245