1 static char *sccsid = "@(#)dumpmain.c 1.1 (Berkeley) 10/13/80"; 2 #include "dump.h" 3 4 int notify = 0; /* notify operator flag */ 5 int blockswritten = 0; /* number of blocks written on current tape */ 6 int tapeno = 0; /* current tape number */ 7 int density = 160; /* density in 0.1" units */ 8 9 main(argc, argv) 10 int argc; 11 char *argv[]; 12 { 13 char *arg; 14 register i; 15 float fetapes; 16 register struct fstab *dt; 17 18 time(&(spcl.c_date)); 19 20 tsize = 2300L*12L*10L; 21 tape = TAPE; 22 disk = DISK; 23 increm = NINCREM; 24 25 incno = '9'; 26 uflag = 0; 27 arg = "u"; 28 if(argc > 1) { 29 argv++; 30 argc--; 31 arg = *argv; 32 if (*arg == '-') 33 argc++; 34 } 35 while(*arg) 36 switch (*arg++) { 37 case 'W': /* what to do */ 38 lastdump(); 39 exit(0); /* do nothing else */ 40 break; 41 42 case 'J': /* update old to new */ 43 o_nconvert(); 44 exit(0); /* do nothing else */ 45 break; 46 47 case 'f': /* output file */ 48 if(argc > 1) { 49 argv++; 50 argc--; 51 tape = *argv; 52 } 53 break; 54 55 case 'd': /* density, in bits per inch */ 56 if (argc > 1) { 57 argv++; 58 argc--; 59 density = atoi(*argv) / 10; 60 } 61 break; 62 63 case 's': /* tape size, feet */ 64 if(argc > 1) { 65 argv++; 66 argc--; 67 tsize = atol(*argv); 68 tsize *= 12L*10L; 69 } 70 break; 71 72 case '0': /* dump level */ 73 case '1': 74 case '2': 75 case '3': 76 case '4': 77 case '5': 78 case '6': 79 case '7': 80 case '8': 81 case '9': 82 incno = arg[-1]; 83 break; 84 85 case 'u': /* update /etc/dumpdates */ 86 uflag++; 87 break; 88 89 case 'n': /* notify operators */ 90 notify++; 91 break; 92 93 default: 94 printf("bad key '%c%'\n", arg[-1]); 95 Exit(X_ABORT); 96 } 97 if(argc > 1) { 98 argv++; 99 argc--; 100 disk = *argv; 101 } 102 103 if (signal(SIGHUP, sighup) == SIG_IGN) 104 signal(SIGHUP, SIG_IGN); 105 if (signal(SIGTRAP, sigtrap) == SIG_IGN) 106 signal(SIGTRAP, SIG_IGN); 107 if (signal(SIGFPE, sigfpe) == SIG_IGN) 108 signal(SIGFPE, SIG_IGN); 109 if (signal(SIGBUS, sigbus) == SIG_IGN) 110 signal(SIGBUS, SIG_IGN); 111 if (signal(SIGSEGV, sigsegv) == SIG_IGN) 112 signal(SIGSEGV, SIG_IGN); 113 if (signal(SIGTERM, sigterm) == SIG_IGN) 114 signal(SIGTERM, SIG_IGN); 115 116 117 if (signal(SIGINT, interrupt) == SIG_IGN) 118 signal(SIGINT, SIG_IGN); 119 120 set_operators(); /* /etc/group snarfed */ 121 getfstab(); /* /etc/fstab snarfed */ 122 /* 123 * disk can be either the full special file name, 124 * the suffix of the special file name, 125 * the special name missing the leading '/', 126 * the file system name with or without the leading '/'. 127 */ 128 dt = fstabsearch(disk); 129 if (dt != 0) 130 disk = rawname(dt->fs_spec); 131 getitime(); /* /etc/dumpdates snarfed */ 132 133 msg("Date of this level %c dump: %s\n", incno, prdate(spcl.c_date)); 134 msg("Date of last level %c dump: %s\n", incno, prdate(spcl.c_ddate)); 135 msg("Dumping %s ", disk); 136 if (dt != 0) 137 msgtail("(%s) ", dt->fs_file); 138 msgtail("to %s\n", tape); 139 140 fi = open(disk, 0); 141 if (fi < 0) { 142 msg("Cannot open %s\n", disk); 143 Exit(X_ABORT); 144 } 145 CLR(clrmap); 146 CLR(dirmap); 147 CLR(nodmap); 148 esize = 0; 149 150 msg("mapping (Pass I) [regular files]\n"); 151 pass(mark, (short *)NULL); /* mark updates esize */ 152 153 do { 154 msg("mapping (Pass II) [directories]\n"); 155 nadded = 0; 156 pass(add, dirmap); 157 } while(nadded); 158 159 bmapest(clrmap); 160 bmapest(nodmap); 161 162 fetapes = 163 ( esize /* blocks */ 164 *BSIZE /* bytes / block */ 165 *(1.0/density) /* 0.1" / byte */ 166 + 167 esize /* blocks */ 168 *(1.0/NTREC) /* IRG's / block */ 169 *7 /* 0.1" / IRG */ 170 ) * (1.0 / tsize ) /* tape / 0.1" */ 171 ; 172 etapes = fetapes; /* truncating assignment */ 173 etapes++; 174 /* 175 * esize is typically about 5% too low; we frob it here 176 */ 177 esize += ((5*esize)/100); 178 msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes); 179 180 otape(); /* bitmap is the first to tape write */ 181 time(&(tstart_writing)); 182 bitmap(clrmap, TS_CLRI); 183 184 msg("dumping (Pass III) [directories]\n"); 185 pass(dump, dirmap); 186 187 msg("dumping (Pass IV) [regular files]\n"); 188 pass(dump, nodmap); 189 190 spcl.c_type = TS_END; 191 for(i=0; i<NTREC; i++) 192 spclrec(); 193 msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume); 194 msg("DUMP IS DONE\n"); 195 196 putitime(); 197 close(to); 198 rewind(); 199 broadcast("DUMP IS DONE!\7\7\n"); 200 Exit(X_FINOK); 201 } 202 203 int sighup(){ msg("SIGHUP() try rewriting\n"); sigAbort();} 204 int sigtrap(){ msg("SIGTRAP() try rewriting\n"); sigAbort();} 205 int sigfpe(){ msg("SIGFPE() try rewriting\n"); sigAbort();} 206 int sigbus(){ msg("SIGBUS() try rewriting\n"); sigAbort();} 207 int sigsegv(){ msg("SIGSEGV() ABORTING!\n"); abort();} 208 int sigalrm(){ msg("SIGALRM() try rewriting\n"); sigAbort();} 209 int sigterm(){ msg("SIGTERM() try rewriting\n"); sigAbort();} 210 211 sigAbort() 212 { 213 msg("Rewriting attempted as response to unknown signal.\n"); 214 fflush(stderr); 215 fflush(stdout); 216 close_rewind(); 217 exit(X_REWRITE); 218 } 219 220 char *rawname(cp) 221 char *cp; 222 { 223 static char rawbuf[32]; 224 char *dp = rindex(cp, '/'); 225 226 if (dp == 0) 227 return (0); 228 *dp = 0; 229 strcpy(rawbuf, cp); 230 *dp = '/'; 231 strcat(rawbuf, "/r"); 232 strcat(rawbuf, dp+1); 233 return (rawbuf); 234 } 235