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