Changeset 58 in MondoRescue
- Timestamp:
- Oct 10, 2005, 11:22:08 AM (20 years ago)
- Location:
- trunk/mondo/mondo/common
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-archive.c
r49 r58 336 336 zipparams = tmp1; 337 337 } else { 338 asprintf(&zipparams, " %s", "");338 asprintf(&zipparams, ""); 339 339 log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp); 340 340 } … … 995 995 asprintf(&archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, 996 996 bkpinfo->tmpdir, 0L); 997 archiving_set_no = 0 L;997 archiving_set_no = 0; 998 998 while (does_file_exist(archiving_filelist_fname)) { 999 999 paranoid_free(archiving_filelist_fname); … … 1490 1490 } 1491 1491 } 1492 paranoid_free(transfer_block);1493 1492 1494 1493 log_msg(8, "About to enter while() loop"); … … 1598 1597 log_to_screen(tmp); 1599 1598 paranoid_free(tmp); 1599 paranoid_free(transfer_block); 1600 1600 paranoid_free(result_str); 1601 1601 return (retval); -
trunk/mondo/mondo/common/libmondo-archive.h
r30 r58 1 1 /* libmondo-archive.h 2 * $Id : libmondo-archive.h,v 1.3 2004/06/17 08:49:06 hugo Exp$2 * $Id$ 3 3 */ 4 4 -
trunk/mondo/mondo/common/libmondo-stream.c
r30 r58 1 1 /* libmondo-stream.c 2 $Id : libmondo-stream.c,v 1.4 2004/06/21 20:20:36 hugo Exp$2 $Id$ 3 3 4 4 ...tools for talking to tapes, Monitas streams, etc. … … 112 112 113 113 /*@unused@*/ 114 //static char cvsid[] = "$Id : libmondo-stream.c,v 1.4 2004/06/21 20:20:36 hugo Exp$";114 //static char cvsid[] = "$Id$"; 115 115 extern bool g_sigpipe; 116 116 extern int g_tape_buffer_size_MB; … … 137 137 * The current media number we're using. This value is 1-based. 138 138 */ 139 int g_current_media_number =-1;139 int g_current_media_number = -1; 140 140 141 141 /** … … 146 146 /* @} - end of globalGroup */ 147 147 148 int write_backcatalog_to_tape 148 int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo); 149 149 150 150 … … 163 163 * @note This should be called by restore processes only. 164 164 */ 165 int 166 closein_cdstream (struct s_bkpinfo *bkpinfo) 167 { 168 return (closein_tape (bkpinfo)); 165 int closein_cdstream(struct s_bkpinfo *bkpinfo) 166 { 167 return (closein_tape(bkpinfo)); 169 168 } 170 169 … … 179 178 * @bug @p bkpinfo parameter is unused. 180 179 */ 181 int 182 closein_tape (struct s_bkpinfo *bkpinfo) 183 { 184 /*@ int's ********************************************************/ 185 int retval = 0; 186 int res = 0; 187 int ctrl_chr = '\0'; 188 189 /*@ buffers ******************************************************/ 190 char fname[MAX_STR_LEN]; 191 192 /*@ long long's **************************************************/ 193 long long size; 194 char *blk; 195 int i; 196 197 blk = (char*)malloc(256*1024); 198 199 log_it("closein_tape() -- entering"); 200 res = read_header_block_from_stream (&size, fname, &ctrl_chr); 201 retval += res; 202 if (ctrl_chr != BLK_END_OF_BACKUP) 203 { 204 wrong_marker (BLK_END_OF_BACKUP, ctrl_chr); 205 } 206 res = read_header_block_from_stream (&size, fname, &ctrl_chr); 207 retval += res; 208 if (ctrl_chr != BLK_END_OF_TAPE) 209 { 210 wrong_marker (BLK_END_OF_TAPE, ctrl_chr); 211 } 212 for(i=0; i<8 && !feof(g_tape_stream); i++) 213 { 214 (void) fread (blk, 1, 256*1024, g_tape_stream); 215 } 216 sleep(1); 217 paranoid_system("sync"); 218 sleep(1); 219 paranoid_pclose (g_tape_stream); 220 log_it("closein_tape() -- leaving"); 180 int closein_tape(struct s_bkpinfo *bkpinfo) 181 { 182 /*@ int's ******************************************************* */ 183 int retval = 0; 184 int res = 0; 185 int ctrl_chr = '\0'; 186 187 /*@ buffers ***************************************************** */ 188 char fname[MAX_STR_LEN]; 189 190 /*@ long long's ************************************************* */ 191 long long size; 192 char *blk; 193 int i; 194 195 blk = (char *) malloc(256 * 1024); 196 197 log_it("closein_tape() -- entering"); 198 res = read_header_block_from_stream(&size, fname, &ctrl_chr); 199 retval += res; 200 if (ctrl_chr != BLK_END_OF_BACKUP) { 201 wrong_marker(BLK_END_OF_BACKUP, ctrl_chr); 202 } 203 res = read_header_block_from_stream(&size, fname, &ctrl_chr); 204 retval += res; 205 if (ctrl_chr != BLK_END_OF_TAPE) { 206 wrong_marker(BLK_END_OF_TAPE, ctrl_chr); 207 } 208 for (i = 0; i < 8 && !feof(g_tape_stream); i++) { 209 (void) fread(blk, 1, 256 * 1024, g_tape_stream); 210 } 211 sleep(1); 212 paranoid_system("sync"); 213 sleep(1); 214 paranoid_pclose(g_tape_stream); 215 log_it("closein_tape() -- leaving"); 221 216 /* 222 217 for(i=0; i < g_tapecatalog->entries; i++) … … 225 220 } 226 221 */ 227 if (!bkpinfo->please_dont_eject) 228 { eject_device(bkpinfo->media_device); } 229 paranoid_free(blk); 230 paranoid_free(g_tapecatalog); 231 return (retval); 222 if (!bkpinfo->please_dont_eject) { 223 eject_device(bkpinfo->media_device); 224 } 225 paranoid_free(blk); 226 paranoid_free(g_tapecatalog); 227 return (retval); 232 228 } 233 229 … … 241 237 * @note This should be called by backup processes only. 242 238 */ 243 int 244 closeout_tape (struct s_bkpinfo *bkpinfo) 245 { 246 /*@ int's ********************************************************/ 247 int retval = 0; 239 int closeout_tape(struct s_bkpinfo *bkpinfo) 240 { 241 /*@ int's ******************************************************* */ 242 int retval = 0; 248 243 // int res = 0; 249 244 // int ctrl_chr = '\0'; 250 245 251 /*@ buffers ***************************************************** */246 /*@ buffers ***************************************************** */ 252 247 // char fname[MAX_STR_LEN]; 253 248 254 /*@ long long's ************************************************* */249 /*@ long long's ************************************************* */ 255 250 // long long size; 256 int i; 257 char *blk; 258 259 blk = (char*)malloc(256*1024); 260 261 sleep(1); 262 paranoid_system("sync"); 263 sleep(1); 264 log_it("closeout_tape() -- entering"); 265 retval+=write_header_block_to_stream (0, "end-of-backup", BLK_END_OF_BACKUP); 266 retval+=write_header_block_to_stream (0, "end-of-tape", BLK_END_OF_TAPE); /* just in case */ 251 int i; 252 char *blk; 253 254 blk = (char *) malloc(256 * 1024); 255 256 sleep(1); 257 paranoid_system("sync"); 258 sleep(1); 259 log_it("closeout_tape() -- entering"); 260 retval += 261 write_header_block_to_stream(0, "end-of-backup", 262 BLK_END_OF_BACKUP); 263 retval += write_header_block_to_stream(0, "end-of-tape", BLK_END_OF_TAPE); /* just in case */ 267 264 /* write 1MB of crap */ 268 for (i = 0; i < 256*1024; i++) 269 { 270 blk[i] = (int)(random()&0xFF); 271 } 272 for (i = 0; i < 4*8; i++) 273 { 274 (void) fwrite (blk, 1, 256*1024, g_tape_stream); 275 if (should_we_write_to_next_tape (bkpinfo->media_size[g_current_media_number], 256*1024)) 276 { 277 start_to_write_to_next_tape (bkpinfo); 278 } 279 } 265 for (i = 0; i < 256 * 1024; i++) { 266 blk[i] = (int) (random() & 0xFF); 267 } 268 for (i = 0; i < 4 * 8; i++) { 269 (void) fwrite(blk, 1, 256 * 1024, g_tape_stream); 270 if (should_we_write_to_next_tape 271 (bkpinfo->media_size[g_current_media_number], 256 * 1024)) { 272 start_to_write_to_next_tape(bkpinfo); 273 } 274 } 280 275 /* write 1MB of zeroes */ 281 276 /* … … 293 288 } 294 289 */ 295 sleep(2); 296 paranoid_pclose (g_tape_stream); 297 log_it("closeout_tape() -- leaving"); 298 for(i=0; i<g_tapecatalog->entries; i++) 299 { 300 log_it("i=%d type=%s num=%d aux=%ld posK=%lld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux, g_tapecatalog->el[i].tape_posK); 301 } 302 // if (!bkpinfo->please_dont_eject) 303 // { eject_device(bkpinfo->media_device); } 304 paranoid_free(blk); 305 paranoid_free(g_tapecatalog); 306 return (retval); 307 } 308 309 310 311 bool mt_says_tape_exists(char*dev) 312 { 313 char *command; 314 int res; 315 316 malloc_string(command); 317 sprintf(command, "mt -f %s status", dev); 318 res = run_program_and_log_output(command, 1); 319 paranoid_free(command); 320 if (res) { return(FALSE); } else { return(TRUE); } 290 sleep(2); 291 paranoid_pclose(g_tape_stream); 292 log_it("closeout_tape() -- leaving"); 293 for (i = 0; i < g_tapecatalog->entries; i++) { 294 log_it("i=%d type=%s num=%d aux=%ld posK=%lld", i, 295 (g_tapecatalog->el[i].type == 296 fileset) ? "fileset" : "bigslice", 297 g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux, 298 g_tapecatalog->el[i].tape_posK); 299 } 300 // if (!bkpinfo->please_dont_eject) 301 // { eject_device(bkpinfo->media_device); } 302 paranoid_free(blk); 303 paranoid_free(g_tapecatalog); 304 return (retval); 305 } 306 307 308 309 bool mt_says_tape_exists(char *dev) 310 { 311 char *command; 312 int res; 313 314 malloc_string(command); 315 sprintf(command, "mt -f %s status", dev); 316 res = run_program_and_log_output(command, 1); 317 paranoid_free(command); 318 if (res) { 319 return (FALSE); 320 } else { 321 return (TRUE); 322 } 321 323 } 322 324 … … 330 332 * @return 0 if success, nonzero if failure (in which @p dev and @p siz are undefined). 331 333 */ 332 int 333 find_tape_device_and_size (char*dev, char*siz) 334 { 335 char tmp[MAX_STR_LEN]; 336 char command[MAX_STR_LEN*2]; 337 char cdr_exe[MAX_STR_LEN]; 334 int find_tape_device_and_size(char *dev, char *siz) 335 { 336 char tmp[MAX_STR_LEN]; 337 char command[MAX_STR_LEN * 2]; 338 char cdr_exe[MAX_STR_LEN]; 338 339 // char tape_description_[MAX_STR_LEN]; 339 340 // char tape_manufacturer_cdr[MAX_STR_LEN]; 340 341 // FILE*fin; 341 int res; 342 343 log_to_screen("I am looking for your tape streamer. Please wait."); 344 dev[0] = siz[0] = '\0'; 345 if (find_home_of_exe("cdrecord")) 346 { strcpy(cdr_exe, "cdrecord"); } 347 else 348 { strcpy(cdr_exe, "dvdrecord"); } 349 sprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", cdr_exe); 350 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 351 if (atoi(tmp)!=1) 352 { 353 log_it("Either too few or too many tape streamers for me to detect..."); 354 strcpy(dev, VANILLA_SCSI_TAPE); 355 return 1; 356 } 357 sprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", cdr_exe); 358 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 359 if (strlen (tmp) < 2) 360 { 361 log_it ("Could not find tape device"); 362 return 1; 363 } 364 sprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", cdr_exe); 365 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 366 strcpy (dev, VANILLA_SCSI_TAPE); 367 dev[strlen(dev)-1] = '\0'; 368 strcat(dev, tmp); // e.g. '/dev/st0' becomes '/dev/stN' 369 res = 0; 370 if (!mt_says_tape_exists(dev)) 371 { 372 strcpy(dev, ALT_TAPE); 373 if (!mt_says_tape_exists(dev)) 374 { 375 log_it ("Cannot openin %s", dev); 376 strcpy(dev, "/dev/st0"); 377 if (!mt_says_tape_exists(dev)) 378 { 379 log_it ("Cannot openin %s", dev); 380 strcpy(dev, "/dev/osst0"); 381 if (!mt_says_tape_exists(dev)) 382 { res++; } 383 else 384 { res=0; } 385 } 386 } 387 } 388 389 log_it("At this point, dev = %s and res = %d" , dev, res); 390 391 strcpy(tmp, call_program_and_get_last_line_of_output("\ 342 int res; 343 344 log_to_screen("I am looking for your tape streamer. Please wait."); 345 dev[0] = siz[0] = '\0'; 346 if (find_home_of_exe("cdrecord")) { 347 strcpy(cdr_exe, "cdrecord"); 348 } else { 349 strcpy(cdr_exe, "dvdrecord"); 350 } 351 sprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", 352 cdr_exe); 353 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 354 if (atoi(tmp) != 1) { 355 log_it 356 ("Either too few or too many tape streamers for me to detect..."); 357 strcpy(dev, VANILLA_SCSI_TAPE); 358 return 1; 359 } 360 sprintf(command, 361 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", 362 cdr_exe); 363 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 364 if (strlen(tmp) < 2) { 365 log_it("Could not find tape device"); 366 return 1; 367 } 368 sprintf(command, 369 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", 370 cdr_exe); 371 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 372 strcpy(dev, VANILLA_SCSI_TAPE); 373 dev[strlen(dev) - 1] = '\0'; 374 strcat(dev, tmp); // e.g. '/dev/st0' becomes '/dev/stN' 375 res = 0; 376 if (!mt_says_tape_exists(dev)) { 377 strcpy(dev, ALT_TAPE); 378 if (!mt_says_tape_exists(dev)) { 379 log_it("Cannot openin %s", dev); 380 strcpy(dev, "/dev/st0"); 381 if (!mt_says_tape_exists(dev)) { 382 log_it("Cannot openin %s", dev); 383 strcpy(dev, "/dev/osst0"); 384 if (!mt_says_tape_exists(dev)) { 385 res++; 386 } else { 387 res = 0; 388 } 389 } 390 } 391 } 392 393 log_it("At this point, dev = %s and res = %d", dev, res); 394 395 strcpy(tmp, call_program_and_get_last_line_of_output("\ 392 396 cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \ 393 397 grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \ 394 398 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'")); 395 399 396 if (mt_says_tape_exists(dev)) 397 { res = 0; } 398 else 399 { 400 log_it("Turning %s", dev); 401 strcpy(tmp, (strrchr(dev, '/')!=NULL)?strrchr(dev, '/'):dev); 402 sprintf(dev, "/dev/os%s", tmp); 403 log_it("...into %s", dev); 404 if (mt_says_tape_exists(dev)) 405 { res=0; } 406 else 407 { res++; } 408 } 409 410 siz[0] = '\0'; 411 log_it("res=%d; dev=%s", res, dev); 412 413 if (res) { return(res); } 414 415 if (strlen(tmp)<2) { siz[0]='\0'; log_it("Warning - size of tape unknown"); return(0); } 416 else { strcpy(siz, tmp); return(0); } 417 } 418 419 420 421 422 423 424 int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo, long long *ptmp_size, char *tmp_fname, int *pctrl_chr, char*xattr_fname, char*acl_fname) 425 { 426 int res=0; 427 int retval=0; 428 400 if (mt_says_tape_exists(dev)) { 401 res = 0; 402 } else { 403 log_it("Turning %s", dev); 404 strcpy(tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev); 405 sprintf(dev, "/dev/os%s", tmp); 406 log_it("...into %s", dev); 407 if (mt_says_tape_exists(dev)) { 408 res = 0; 409 } else { 410 res++; 411 } 412 } 413 414 siz[0] = '\0'; 415 log_it("res=%d; dev=%s", res, dev); 416 417 if (res) { 418 return (res); 419 } 420 421 if (strlen(tmp) < 2) { 422 siz[0] = '\0'; 423 log_it("Warning - size of tape unknown"); 424 return (0); 425 } else { 426 strcpy(siz, tmp); 427 return (0); 428 } 429 } 430 431 432 433 434 435 436 int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo, 437 long long *ptmp_size, char *tmp_fname, 438 int *pctrl_chr, char *xattr_fname, 439 char *acl_fname) 440 { 441 int res = 0; 442 int retval = 0; 443 429 444 // xattr 430 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 431 if(*pctrl_chr!=BLK_START_EXAT_FILE){wrong_marker(BLK_START_EXAT_FILE,*pctrl_chr);} 432 if (!strstr(tmp_fname, "xattr")) { fatal_error("Wrong order, sunshine."); } 433 read_file_from_stream_to_file(bkpinfo, xattr_fname, *ptmp_size); 434 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 435 if(*pctrl_chr!= BLK_STOP_EXAT_FILE) {wrong_marker(BLK_STOP_EXAT_FILE,*pctrl_chr);} 445 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 446 if (*pctrl_chr != BLK_START_EXAT_FILE) { 447 wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr); 448 } 449 if (!strstr(tmp_fname, "xattr")) { 450 fatal_error("Wrong order, sunshine."); 451 } 452 read_file_from_stream_to_file(bkpinfo, xattr_fname, *ptmp_size); 453 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 454 if (*pctrl_chr != BLK_STOP_EXAT_FILE) { 455 wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr); 456 } 436 457 // acl 437 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 438 if (!strstr(tmp_fname, "acl")) { fatal_error("Wrong order, sunshine."); } 439 if(*pctrl_chr!=BLK_START_EXAT_FILE){wrong_marker(BLK_START_EXAT_FILE,*pctrl_chr);} 440 read_file_from_stream_to_file(bkpinfo, acl_fname, *ptmp_size); 441 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 442 if(*pctrl_chr!= BLK_STOP_EXAT_FILE){wrong_marker(BLK_STOP_EXAT_FILE,*pctrl_chr);} 443 res=read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 444 if(*pctrl_chr!= BLK_STOP_EXTENDED_ATTRIBUTES) 445 { wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES,*pctrl_chr); } 458 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 459 if (!strstr(tmp_fname, "acl")) { 460 fatal_error("Wrong order, sunshine."); 461 } 462 if (*pctrl_chr != BLK_START_EXAT_FILE) { 463 wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr); 464 } 465 read_file_from_stream_to_file(bkpinfo, acl_fname, *ptmp_size); 466 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 467 if (*pctrl_chr != BLK_STOP_EXAT_FILE) { 468 wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr); 469 } 470 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 471 if (*pctrl_chr != BLK_STOP_EXTENDED_ATTRIBUTES) { 472 wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES, *pctrl_chr); 473 } 446 474 // tarball itself 447 res=read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 448 log_msg(1, "Got xattr and acl; now looking for afioball"); 449 return(retval); 450 } 451 452 453 int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char*xattr_fname, char*acl_fname) 454 { 455 int res=0; 475 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr); 476 log_msg(1, "Got xattr and acl; now looking for afioball"); 477 return (retval); 478 } 479 480 481 int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char *xattr_fname, 482 char *acl_fname) 483 { 484 int res = 0; 456 485 // EXATs 457 write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_START_EXTENDED_ATTRIBUTES); 486 write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, 487 BLK_START_EXTENDED_ATTRIBUTES); 458 488 // xattr 459 write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_START_EXAT_FILE); 460 write_file_to_stream_from_file(bkpinfo, xattr_fname); 461 write_header_block_to_stream(-1, xattr_fname, BLK_STOP_EXAT_FILE); 489 write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, 490 BLK_START_EXAT_FILE); 491 write_file_to_stream_from_file(bkpinfo, xattr_fname); 492 write_header_block_to_stream(-1, xattr_fname, BLK_STOP_EXAT_FILE); 462 493 // acl 463 write_header_block_to_stream(length_of_file(acl_fname), acl_fname, BLK_START_EXAT_FILE); 464 write_file_to_stream_from_file(bkpinfo, acl_fname); 465 write_header_block_to_stream(-1, acl_fname, BLK_STOP_EXAT_FILE); 466 write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, BLK_STOP_EXTENDED_ATTRIBUTES); 467 return(res); 494 write_header_block_to_stream(length_of_file(acl_fname), acl_fname, 495 BLK_START_EXAT_FILE); 496 write_file_to_stream_from_file(bkpinfo, acl_fname); 497 write_header_block_to_stream(-1, acl_fname, BLK_STOP_EXAT_FILE); 498 write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname, 499 BLK_STOP_EXTENDED_ATTRIBUTES); 500 return (res); 468 501 } 469 502 … … 479 512 void insist_on_this_tape_number(int tapeno) 480 513 { 481 int i; 482 char tmp[MAX_STR_LEN]; 483 484 log_it("Insisting on tape #%d", tapeno); 485 if (g_current_media_number != tapeno) 486 { 487 // log_it("g_current_media_number = %d", g_current_media_number); 488 sprintf(tmp, "When the tape drive goes quiet, please insert volume %d in this series.", tapeno); 489 popup_and_OK (tmp); 490 open_evalcall_form ("Waiting while the tape drive settles"); 491 } 492 else 493 { 494 open_evalcall_form ("Waiting while the tape drive rewinds"); 495 } 496 497 for(i=0; i<=100; i+=2) 498 { 499 usleep(100000); 500 update_evalcall_form (i); 501 } 502 close_evalcall_form(); 503 log_it("I assume user has inserted it. They _say_ they have..."); 504 g_current_media_number = tapeno; 505 506 // log_it("g_current_media_number = %d", g_current_media_number); 507 log_it("OK, I've finished insisting. On with the revelry."); 514 int i; 515 char tmp[MAX_STR_LEN]; 516 517 log_it("Insisting on tape #%d", tapeno); 518 if (g_current_media_number != tapeno) { 519 // log_it("g_current_media_number = %d", g_current_media_number); 520 sprintf(tmp, 521 "When the tape drive goes quiet, please insert volume %d in this series.", 522 tapeno); 523 popup_and_OK(tmp); 524 open_evalcall_form("Waiting while the tape drive settles"); 525 } else { 526 open_evalcall_form("Waiting while the tape drive rewinds"); 527 } 528 529 for (i = 0; i <= 100; i += 2) { 530 usleep(100000); 531 update_evalcall_form(i); 532 } 533 close_evalcall_form(); 534 log_it("I assume user has inserted it. They _say_ they have..."); 535 g_current_media_number = tapeno; 536 537 // log_it("g_current_media_number = %d", g_current_media_number); 538 log_it("OK, I've finished insisting. On with the revelry."); 508 539 } 509 540 … … 514 545 * Debugging aid - log the offset we're at on the tape (reading or writing). 515 546 */ 516 void 517 log_tape_pos (void) 518 { 519 /*@ buffers ******************************************************/ 520 521 522 /*@ end vars ****************************************************/ 523 524 log_it ("Tape position -- %ld KB (%ld MB)", (long) g_tape_posK, 525 (long) g_tape_posK >> 10); 547 void log_tape_pos(void) 548 { 549 /*@ buffers ***************************************************** */ 550 551 552 /*@ end vars *************************************************** */ 553 554 log_it("Tape position -- %ld KB (%ld MB)", (long) g_tape_posK, 555 (long) g_tape_posK >> 10); 526 556 } 527 557 … … 542 572 int maintain_collection_of_recent_archives(char *td, char *latest_fname) 543 573 { 544 long long final_alleged_writeK, final_projected_certain_writeK, final_actually_certain_writeK=0, cposK, bufsize_K; 545 int last, curr, i; 546 t_archtype type=other; 547 char command[MAX_STR_LEN]; 548 char tmpdir[MAX_STR_LEN]; 549 char old_fname[MAX_STR_LEN]; 550 char *p; 551 char suffix[16]; 552 553 bufsize_K = (long long)(1024LL * (1+g_tape_buffer_size_MB) ); 554 sprintf(tmpdir, "%s/tmpfs/backcatalog", td); 555 if ((p=strrchr(latest_fname, '.'))) { strcpy(suffix, ++p); } else { suffix[0] = '\0'; } 556 if (strstr(latest_fname, ".afio.") || strstr(latest_fname, ".star.")) { type = fileset; } 557 else if (strstr(latest_fname, "slice")) { type = biggieslice; } 558 else 559 { 560 log_it("fname = %s", latest_fname); 561 fatal_error("Unknown type. Internal error in maintain_collection_of_recent_archives()"); 562 } 563 mkdir(tmpdir, 0x700); 564 sprintf(command, "cp -f %s %s", latest_fname, tmpdir); 565 if (run_program_and_log_output(command, 6)) { log_it("Warning - failed to copy %s to backcatalog at %s", latest_fname, tmpdir); } 566 last = g_tapecatalog->entries-1; 567 if ( last<=0 ) 568 { 569 iamhere("Too early to start deleting from collection."); 570 return( 0 ); 571 } 572 final_alleged_writeK = g_tapecatalog->el[last].tape_posK; 573 final_projected_certain_writeK = final_alleged_writeK - bufsize_K; 574 for( curr=last; curr>=0; curr--) 575 { 576 cposK = g_tapecatalog->el[curr].tape_posK; 577 if (cposK < final_projected_certain_writeK) 578 { 579 final_actually_certain_writeK = cposK; 580 break; 581 } 582 } 583 if ( curr<0 ) 584 { 585 iamhere( "Not far enough into tape to start deleting old archives from collection." ); 586 return( 0 ); 587 } 574 long long final_alleged_writeK, final_projected_certain_writeK, 575 final_actually_certain_writeK = 0, cposK, bufsize_K; 576 int last, curr, i; 577 t_archtype type = other; 578 char command[MAX_STR_LEN]; 579 char tmpdir[MAX_STR_LEN]; 580 char old_fname[MAX_STR_LEN]; 581 char *p; 582 char suffix[16]; 583 584 bufsize_K = (long long) (1024LL * (1 + g_tape_buffer_size_MB)); 585 sprintf(tmpdir, "%s/tmpfs/backcatalog", td); 586 if ((p = strrchr(latest_fname, '.'))) { 587 strcpy(suffix, ++p); 588 } else { 589 suffix[0] = '\0'; 590 } 591 if (strstr(latest_fname, ".afio.") || strstr(latest_fname, ".star.")) { 592 type = fileset; 593 } else if (strstr(latest_fname, "slice")) { 594 type = biggieslice; 595 } else { 596 log_it("fname = %s", latest_fname); 597 fatal_error 598 ("Unknown type. Internal error in maintain_collection_of_recent_archives()"); 599 } 600 mkdir(tmpdir, 0x700); 601 sprintf(command, "cp -f %s %s", latest_fname, tmpdir); 602 if (run_program_and_log_output(command, 6)) { 603 log_it("Warning - failed to copy %s to backcatalog at %s", 604 latest_fname, tmpdir); 605 } 606 last = g_tapecatalog->entries - 1; 607 if (last <= 0) { 608 iamhere("Too early to start deleting from collection."); 609 return (0); 610 } 611 final_alleged_writeK = g_tapecatalog->el[last].tape_posK; 612 final_projected_certain_writeK = final_alleged_writeK - bufsize_K; 613 for (curr = last; curr >= 0; curr--) { 614 cposK = g_tapecatalog->el[curr].tape_posK; 615 if (cposK < final_projected_certain_writeK) { 616 final_actually_certain_writeK = cposK; 617 break; 618 } 619 } 620 if (curr < 0) { 621 iamhere 622 ("Not far enough into tape to start deleting old archives from collection."); 623 return (0); 624 } 588 625 // log_it( "There are %lld KB (more than %d KB) in my backcatalog", final_alleged_writeK - final_actually_certain_writeK, bufsize_K); 589 626 590 for(i=curr-1; i>=0 && curr-i<10; i--) 591 { 592 sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname); 593 unlink(old_fname); 594 } 595 return(0); 627 for (i = curr - 1; i >= 0 && curr - i < 10; i--) { 628 sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname); 629 unlink(old_fname); 630 } 631 return (0); 596 632 } 597 633 … … 605 641 * @note Equivalent to openin_tape() for now, but don't count on this behavior. 606 642 */ 607 int 608 openin_cdstream (struct s_bkpinfo *bkpinfo) 609 { 610 return (openin_tape (bkpinfo)); 643 int openin_cdstream(struct s_bkpinfo *bkpinfo) 644 { 645 return (openin_tape(bkpinfo)); 611 646 } 612 647 … … 619 654 620 655 621 int set_tape_block_size_with_mt(char*tapedev, long internal_tape_block_size) 622 { 623 char *tmp; 624 int res; 625 626 if (strncmp(tapedev, "/dev/", 5)) 627 { 628 log_msg(1, "Not using 'mt setblk'. This isn't an actual /dev entry."); 629 return(0); 630 } 631 malloc_string( tmp ); 632 sprintf(tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size); 633 res = run_program_and_log_output(tmp, 3); 634 paranoid_free( tmp ); 635 return(res); 656 int set_tape_block_size_with_mt(char *tapedev, 657 long internal_tape_block_size) 658 { 659 char *tmp; 660 int res; 661 662 if (strncmp(tapedev, "/dev/", 5)) { 663 log_msg(1, 664 "Not using 'mt setblk'. This isn't an actual /dev entry."); 665 return (0); 666 } 667 malloc_string(tmp); 668 sprintf(tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size); 669 res = run_program_and_log_output(tmp, 3); 670 paranoid_free(tmp); 671 return (res); 636 672 } 637 673 … … 646 682 * @note This will also work with a cdstream for now, but don't count on this behavior. 647 683 */ 648 int 649 openin_tape (struct s_bkpinfo *bkpinfo) 650 { 651 /*@ buffer ******************************************************/ 652 char fname[MAX_STR_LEN]; 653 char *datablock; 654 char tmp[MAX_STR_LEN]; 655 char old_cwd[MAX_STR_LEN]; 656 char outfname[MAX_STR_LEN]; 657 /*@ int ********************************************************/ 658 int i; 659 int j; 660 int res; 661 long length, templong; 662 size_t k; 663 int retval = 0; 664 int ctrl_chr; 665 666 /*@ long long **************************************************/ 667 long long size; 668 669 /*@ pointers ***************************************************/ 670 FILE *fout; 671 672 /*@ end vars ****************************************************/ 673 674 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device); 675 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { fatal_error("Cannot alloc mem for tape catalog"); } 676 g_tapecatalog->entries = 0; 677 g_tape_posK = 0; 678 if (g_tape_stream) { log_it("FYI - I won't 'openin' the tape. It's already open."); return(0); } 679 insist_on_this_tape_number(1); 680 sprintf (outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir); 681 make_hole_for_file (outfname); 682 683 set_tape_block_size_with_mt(bkpinfo->media_device, bkpinfo->internal_tape_block_size); 684 int openin_tape(struct s_bkpinfo *bkpinfo) 685 { 686 /*@ buffer ***************************************************** */ 687 char fname[MAX_STR_LEN]; 688 char *datablock; 689 char tmp[MAX_STR_LEN]; 690 char old_cwd[MAX_STR_LEN]; 691 char outfname[MAX_STR_LEN]; 692 /*@ int ******************************************************* */ 693 int i; 694 int j; 695 int res; 696 long length, templong; 697 size_t k; 698 int retval = 0; 699 int ctrl_chr; 700 701 /*@ long long ************************************************* */ 702 long long size; 703 704 /*@ pointers ************************************************** */ 705 FILE *fout; 706 707 /*@ end vars *************************************************** */ 708 709 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device); 710 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { 711 fatal_error("Cannot alloc mem for tape catalog"); 712 } 713 g_tapecatalog->entries = 0; 714 g_tape_posK = 0; 715 if (g_tape_stream) { 716 log_it("FYI - I won't 'openin' the tape. It's already open."); 717 return (0); 718 } 719 insist_on_this_tape_number(1); 720 sprintf(outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir); 721 make_hole_for_file(outfname); 722 723 set_tape_block_size_with_mt(bkpinfo->media_device, 724 bkpinfo->internal_tape_block_size); 684 725 685 726 // start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE); 686 log_it ("Opening IN tape"); 687 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) { log_OS_error(g_tape_fifo); log_to_screen ("Cannot openin stream device"); return(1); } 688 log_to_screen ("Reading stream"); 689 log_it ("stream device = '%s'", bkpinfo->media_device); 727 log_it("Opening IN tape"); 728 if (! 729 (g_tape_stream = 730 open_device_via_buffer(bkpinfo->media_device, 'r', 731 bkpinfo->internal_tape_block_size))) { 732 log_OS_error(g_tape_fifo); 733 log_to_screen("Cannot openin stream device"); 734 return (1); 735 } 736 log_to_screen("Reading stream"); 737 log_it("stream device = '%s'", bkpinfo->media_device); 690 738 /* skip data disks */ 691 open_evalcall_form("Skipping data disks on stream");692 log_to_screen("Skipping data disks on stream");693 if (!(fout = fopen (outfname, "w"))) 694 { 695 log_OS_error(outfname);696 log_to_screen ("Cannot openout datadisk all.tar.gz file");697 return(-1); 698 } 699 if (!(datablock = (char*)malloc(256*1024))) { log_to_screen("Unable to malloc 256*1024"); exit(1); } 700 for (i = 0; i < 32; i++) 701 { 702 for (j = 0; j < 4; j++) 703 {704 for(length=0, k=0; length<256*1024; length+=k) 705 { 706 k=fread(datablock+length, 1, 256*1024 - length,g_tape_stream);707 708 (void) fwrite(datablock, 1, (size_t) length, fout);709 g_tape_posK += length/1024;710 }711 if (i>8)// otherwise, 'buffer' distorts calculations712 713 templong = ((i-8) * 4 + j) * 100 / (128-8*4);714 update_evalcall_form ((int)(templong));715 716 717 paranoid_fclose(fout);718 739 open_evalcall_form("Skipping data disks on stream"); 740 log_to_screen("Skipping data disks on stream"); 741 if (!(fout = fopen(outfname, "w"))) { 742 log_OS_error(outfname); 743 log_to_screen("Cannot openout datadisk all.tar.gz file"); 744 return (-1); 745 } 746 if (!(datablock = (char *) malloc(256 * 1024))) { 747 log_to_screen("Unable to malloc 256*1024"); 748 exit(1); 749 } 750 for (i = 0; i < 32; i++) { 751 for (j = 0; j < 4; j++) { 752 for (length = 0, k = 0; length < 256 * 1024; length += k) { 753 k = fread(datablock + length, 1, 256 * 1024 - length, 754 g_tape_stream); 755 } 756 (void) fwrite(datablock, 1, (size_t) length, fout); 757 g_tape_posK += length / 1024; 758 } 759 if (i > 8) // otherwise, 'buffer' distorts calculations 760 { 761 templong = ((i - 8) * 4 + j) * 100 / (128 - 8 * 4); 762 update_evalcall_form((int) (templong)); 763 } 764 } 765 paranoid_fclose(fout); 766 paranoid_free(datablock); 719 767 /* find initial blocks */ 720 res = read_header_block_from_stream (&size, fname, &ctrl_chr); 721 retval += res; 722 if (ctrl_chr != BLK_START_OF_TAPE) 723 { 724 wrong_marker (BLK_START_OF_TAPE, ctrl_chr); 725 } 726 res = read_header_block_from_stream (&size, fname, &ctrl_chr); 727 retval += res; 728 if (ctrl_chr != BLK_START_OF_BACKUP) 729 { 730 wrong_marker (BLK_START_OF_BACKUP, ctrl_chr); 731 } 732 close_evalcall_form (); 733 log_it ("Saved all.tar.gz to '%s'", outfname); 734 (void) getcwd (old_cwd, MAX_STR_LEN); 735 chdir (bkpinfo->tmpdir); 736 sprintf (tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null", outfname); 737 paranoid_system(tmp); 738 paranoid_system ("cp -f tmp/mondo-restore.cfg . 2> /dev/null"); 739 chdir (old_cwd); 740 unlink (outfname); 741 return (retval); 768 res = read_header_block_from_stream(&size, fname, &ctrl_chr); 769 retval += res; 770 if (ctrl_chr != BLK_START_OF_TAPE) { 771 wrong_marker(BLK_START_OF_TAPE, ctrl_chr); 772 } 773 res = read_header_block_from_stream(&size, fname, &ctrl_chr); 774 retval += res; 775 if (ctrl_chr != BLK_START_OF_BACKUP) { 776 wrong_marker(BLK_START_OF_BACKUP, ctrl_chr); 777 } 778 close_evalcall_form(); 779 log_it("Saved all.tar.gz to '%s'", outfname); 780 (void) getcwd(old_cwd, MAX_STR_LEN); 781 chdir(bkpinfo->tmpdir); 782 sprintf(tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null", 783 outfname); 784 paranoid_system(tmp); 785 paranoid_system("cp -f tmp/mondo-restore.cfg . 2> /dev/null"); 786 chdir(old_cwd); 787 unlink(outfname); 788 return (retval); 742 789 } 743 790 … … 750 797 * @note This should be called only from backup processes. 751 798 */ 752 int 753 openout_cdstream (char *cddev, int speed) 754 { 755 /*@ buffers ******************************************************/ 756 char command[MAX_STR_LEN*2]; 757 758 /*@ end vars ****************************************************/ 799 int openout_cdstream(char *cddev, int speed) 800 { 801 /*@ buffers ***************************************************** */ 802 char command[MAX_STR_LEN * 2]; 803 804 /*@ end vars *************************************************** */ 759 805 760 806 /* add 'dummy' if testing */ 761 sprintf(command,762 763 807 sprintf(command, 808 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", 809 cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE); 764 810 /* initialise the catalog */ 765 g_current_media_number = 1; 766 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { fatal_error("Cannot alloc mem for tape catalog"); } 767 g_tapecatalog->entries = 0; 811 g_current_media_number = 1; 812 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { 813 fatal_error("Cannot alloc mem for tape catalog"); 814 } 815 g_tapecatalog->entries = 0; 768 816 /* log stuff */ 769 log_it("Opening OUT cdstream with the command");770 log_it(command);817 log_it("Opening OUT cdstream with the command"); 818 log_it(command); 771 819 /* log_it("Let's see what happens, shall we?"); */ 772 g_tape_stream = popen (command, "w"); 773 if (g_tape_stream) 774 { 775 return (0); 776 } 777 else 778 { 779 log_to_screen ("Failed to openout to cdstream (fifo)"); 780 return (1); 781 } 820 g_tape_stream = popen(command, "w"); 821 if (g_tape_stream) { 822 return (0); 823 } else { 824 log_to_screen("Failed to openout to cdstream (fifo)"); 825 return (1); 826 } 782 827 } 783 828 … … 789 834 * EXISTING DATA on the tape! 790 835 */ 791 int 792 openout_tape (char *tapedev, long internal_tape_block_size) 836 int openout_tape(char *tapedev, long internal_tape_block_size) 793 837 { 794 838 // char sz_call_to_buffer[MAX_STR_LEN]; 795 796 g_current_media_number = 1; 797 if (g_tape_stream) { log_it("FYI - I won't 'openout' the tape. It's already open."); return(0); } 798 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { fatal_error("Cannot alloc mem for tape catalog"); } 799 g_tapecatalog->entries = 0; 800 g_tape_posK = 0; 801 802 set_tape_block_size_with_mt(tapedev, internal_tape_block_size); 803 log_it ("Opening OUT tape"); 804 if (!(g_tape_stream = open_device_via_buffer(tapedev, 'w', internal_tape_block_size))) { log_OS_error(g_tape_fifo); log_to_screen ("Cannot openin stream device"); return(1); } 805 return(0); 839 840 g_current_media_number = 1; 841 if (g_tape_stream) { 842 log_it("FYI - I won't 'openout' the tape. It's already open."); 843 return (0); 844 } 845 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { 846 fatal_error("Cannot alloc mem for tape catalog"); 847 } 848 g_tapecatalog->entries = 0; 849 g_tape_posK = 0; 850 851 set_tape_block_size_with_mt(tapedev, internal_tape_block_size); 852 log_it("Opening OUT tape"); 853 if (! 854 (g_tape_stream = 855 open_device_via_buffer(tapedev, 'w', internal_tape_block_size))) { 856 log_OS_error(g_tape_fifo); 857 log_to_screen("Cannot openin stream device"); 858 return (1); 859 } 860 return (0); 806 861 } 807 862 … … 817 872 */ 818 873 int 819 read_file_from_stream_to_file 820 821 { 822 823 /*@ int ******************************************************** */824 825 826 /*@ end vars *************************************************** */827 828 res = read_file_from_stream_FULL(bkpinfo, outfile, NULL, size);829 830 874 read_file_from_stream_to_file(struct s_bkpinfo *bkpinfo, char *outfile, 875 long long size) 876 { 877 878 /*@ int ******************************************************** */ 879 int res; 880 881 /*@ end vars *************************************************** */ 882 883 res = read_file_from_stream_FULL(bkpinfo, outfile, NULL, size); 884 885 return (res); 831 886 } 832 887 … … 842 897 */ 843 898 int 844 read_file_from_stream_to_stream 845 846 { 847 848 /*@ int ******************************************************** */849 850 851 /*@ end vars *************************************************** */852 853 res = read_file_from_stream_FULL(bkpinfo, NULL, fout, size);899 read_file_from_stream_to_stream(struct s_bkpinfo *bkpinfo, FILE * fout, 900 long long size) 901 { 902 903 /*@ int ******************************************************** */ 904 int res; 905 906 /*@ end vars *************************************************** */ 907 908 res = read_file_from_stream_FULL(bkpinfo, NULL, fout, size); 854 909 /* fflush(g_tape_stream); 855 910 fflush(fout);*/ 856 911 return (res); 857 912 } 858 913 … … 872 927 */ 873 928 int 874 read_file_from_stream_FULL 875 FILE * foutstream, long long orig_size)876 { 877 /*@ buffers ***************************************************** */878 879 880 881 882 929 read_file_from_stream_FULL(struct s_bkpinfo *bkpinfo, char *outfname, 930 FILE * foutstream, long long orig_size) 931 { 932 /*@ buffers ***************************************************** */ 933 char *tmp; 934 char *datablock; 935 char *temp_fname; 936 char *temp_cksum; 937 char *actual_cksum; 883 938 // char *pA, *pB; 884 939 885 /*@ int ********************************************************* */886 940 /*@ int ********************************************************* */ 941 int retval = 0; 887 942 #ifdef EXTRA_TAPE_CHECKSUMS 888 943 int i, ch; 889 944 #endif 890 891 892 893 /*@ pointers **************************************************** */894 895 896 /*@ long ***************************************************** */897 945 int noof_blocks; 946 int ctrl_chr; 947 int res; 948 /*@ pointers **************************************************** */ 949 FILE *fout; 950 951 /*@ long ***************************************************** */ 952 long bytes_to_write = 0 /*,i */ ; 898 953 // long bytes_successfully_read_in_this_time = 0; 899 954 900 /*@ long long ****************************************************/ 901 long long temp_size, size; 902 long bytes_read, bytes_to_read; 903 long long total_read_from_tape_for_this_file = 0; 904 long long where_I_was_before_tape_change = 0; 905 /*@ unsigned int *************************************************/ 906 /* unsigned int ch; */ 907 unsigned int crc16; 908 unsigned int crctt; 909 910 bool had_to_resync=FALSE; 911 912 /*@ init ********************************************************/ 913 malloc_string(tmp); 914 malloc_string(temp_fname); 915 malloc_string(temp_cksum); 916 malloc_string(actual_cksum); 917 datablock = malloc(TAPE_BLOCK_SIZE); 918 crc16 = 0; 919 crctt = 0; 920 size = orig_size; 921 922 /*@ end vars ****************************************************/ 923 924 res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr); 925 if (orig_size != temp_size && orig_size != -1) 926 { 927 sprintf (tmp, 928 "output file's size should be %ld K but is apparently %ld K", 929 (long) size >> 10, (long) temp_size >> 10); 930 log_to_screen (tmp); 931 } 932 if (ctrl_chr != BLK_START_FILE) 933 { 934 wrong_marker (BLK_START_FILE, ctrl_chr); 935 return(1); 936 } 937 sprintf (tmp, "Reading file from tape; writing to '%s'; %ld KB", outfname, 938 (long) size >> 10); 939 940 if (foutstream) { fout = foutstream; } 941 else { fout = fopen (outfname, "w"); } 942 if (!fout) 943 { 944 log_OS_error (outfname); 945 log_to_screen ("Cannot openout file"); 946 return(1); 947 } 948 total_read_from_tape_for_this_file = 0; 949 for (noof_blocks = 0; size > 0; noof_blocks++, size-=bytes_to_write, total_read_from_tape_for_this_file+=bytes_read) 950 { 951 bytes_to_write = (size < TAPE_BLOCK_SIZE) ? (long)size : TAPE_BLOCK_SIZE; 952 bytes_to_read = TAPE_BLOCK_SIZE; 953 bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream); 954 while(bytes_read < bytes_to_read) 955 { // next tape! 956 // crctt=crc16=0; 957 where_I_was_before_tape_change = size; 958 log_msg(4, "where_I_was_... = %lld", where_I_was_before_tape_change); 959 start_to_read_from_next_tape(bkpinfo); 960 log_msg(4, "Started reading from next tape."); 961 skip_incoming_files_until_we_find_this_one(temp_fname); 962 log_msg(4, "Skipped irrelevant files OK."); 963 for(size = orig_size; size > where_I_was_before_tape_change; size-=bytes_to_write) 964 { 965 bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream); 966 } 967 log_msg(4, "'size' is now %lld (should be %lld)", size, where_I_was_before_tape_change); 968 log_to_screen("Successfully re-sync'd tape"); 969 had_to_resync = TRUE; 970 bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream); 971 } 972 973 (void) fwrite (datablock, 1, (size_t) bytes_to_write, fout); // for blocking reasons, bytes_successfully_read_in isn't necessarily the same as bytes_to_write 955 /*@ long long *************************************************** */ 956 long long temp_size, size; 957 long bytes_read, bytes_to_read; 958 long long total_read_from_tape_for_this_file = 0; 959 long long where_I_was_before_tape_change = 0; 960 /*@ unsigned int ************************************************ */ 961 /* unsigned int ch; */ 962 unsigned int crc16; 963 unsigned int crctt; 964 965 bool had_to_resync = FALSE; 966 967 /*@ init ******************************************************* */ 968 malloc_string(tmp); 969 malloc_string(temp_fname); 970 malloc_string(temp_cksum); 971 malloc_string(actual_cksum); 972 datablock = malloc(TAPE_BLOCK_SIZE); 973 crc16 = 0; 974 crctt = 0; 975 size = orig_size; 976 977 /*@ end vars *************************************************** */ 978 979 res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr); 980 if (orig_size != temp_size && orig_size != -1) { 981 sprintf(tmp, 982 "output file's size should be %ld K but is apparently %ld K", 983 (long) size >> 10, (long) temp_size >> 10); 984 log_to_screen(tmp); 985 } 986 if (ctrl_chr != BLK_START_FILE) { 987 wrong_marker(BLK_START_FILE, ctrl_chr); 988 return (1); 989 } 990 sprintf(tmp, "Reading file from tape; writing to '%s'; %ld KB", 991 outfname, (long) size >> 10); 992 993 if (foutstream) { 994 fout = foutstream; 995 } else { 996 fout = fopen(outfname, "w"); 997 } 998 if (!fout) { 999 log_OS_error(outfname); 1000 log_to_screen("Cannot openout file"); 1001 return (1); 1002 } 1003 total_read_from_tape_for_this_file = 0; 1004 for (noof_blocks = 0; size > 0; 1005 noof_blocks++, size -= 1006 bytes_to_write, total_read_from_tape_for_this_file += 1007 bytes_read) { 1008 bytes_to_write = 1009 (size < TAPE_BLOCK_SIZE) ? (long) size : TAPE_BLOCK_SIZE; 1010 bytes_to_read = TAPE_BLOCK_SIZE; 1011 bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream); 1012 while (bytes_read < bytes_to_read) { // next tape! 1013 // crctt=crc16=0; 1014 where_I_was_before_tape_change = size; 1015 log_msg(4, "where_I_was_... = %lld", 1016 where_I_was_before_tape_change); 1017 start_to_read_from_next_tape(bkpinfo); 1018 log_msg(4, "Started reading from next tape."); 1019 skip_incoming_files_until_we_find_this_one(temp_fname); 1020 log_msg(4, "Skipped irrelevant files OK."); 1021 for (size = orig_size; size > where_I_was_before_tape_change; 1022 size -= bytes_to_write) { 1023 bytes_read = 1024 fread(datablock, 1, bytes_to_read, g_tape_stream); 1025 } 1026 log_msg(4, "'size' is now %lld (should be %lld)", size, 1027 where_I_was_before_tape_change); 1028 log_to_screen("Successfully re-sync'd tape"); 1029 had_to_resync = TRUE; 1030 bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream); 1031 } 1032 1033 (void) fwrite(datablock, 1, (size_t) bytes_to_write, fout); // for blocking reasons, bytes_successfully_read_in isn't necessarily the same as bytes_to_write 974 1034 975 1035 #ifdef EXTRA_TAPE_CHECKSUMS 976 for(i=0;i<(int)bytes_to_write;i++) 977 { 978 ch=datablock[i]; 979 crc16=updcrcr(crc16,(unsigned)ch); 980 crctt=updcrc(crctt,(unsigned)ch); 981 } 1036 for (i = 0; i < (int) bytes_to_write; i++) { 1037 ch = datablock[i]; 1038 crc16 = updcrcr(crc16, (unsigned) ch); 1039 crctt = updcrc(crctt, (unsigned) ch); 1040 } 982 1041 #endif 983 } 984 log_msg(6, "Total read from tape for this file = %lld", total_read_from_tape_for_this_file); 985 log_msg(6, ".......................... Should be %lld", orig_size); 986 g_tape_posK += total_read_from_tape_for_this_file/1024; 987 sprintf (actual_cksum, "%04x%04x", crc16, crctt); 988 if (foutstream) 989 { /*log_it("Finished writing to foutstream"); */ 990 } 991 else 992 { 993 paranoid_fclose (fout); 994 } 995 res = read_header_block_from_stream (&temp_size, temp_cksum, &ctrl_chr); 996 if (ctrl_chr != BLK_STOP_FILE) 997 { 998 wrong_marker (BLK_STOP_FILE, ctrl_chr); 1042 } 1043 log_msg(6, "Total read from tape for this file = %lld", 1044 total_read_from_tape_for_this_file); 1045 log_msg(6, ".......................... Should be %lld", orig_size); 1046 g_tape_posK += total_read_from_tape_for_this_file / 1024; 1047 sprintf(actual_cksum, "%04x%04x", crc16, crctt); 1048 if (foutstream) { /*log_it("Finished writing to foutstream"); */ 1049 } else { 1050 paranoid_fclose(fout); 1051 } 1052 res = read_header_block_from_stream(&temp_size, temp_cksum, &ctrl_chr); 1053 if (ctrl_chr != BLK_STOP_FILE) { 1054 wrong_marker(BLK_STOP_FILE, ctrl_chr); 999 1055 // fatal_error("Bad marker"); // return(1); 1000 } 1001 if (strcmp (temp_cksum, actual_cksum)) 1002 { 1003 sprintf (tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum, 1004 temp_cksum); 1005 log_to_screen (tmp); 1006 sprintf (tmp, "%s (%ld K) is corrupt on tape", temp_fname, 1007 (long) orig_size >> 10); 1008 log_to_screen (tmp); 1009 retval++; 1010 } 1011 else 1012 { 1013 sprintf (tmp, "%s is GOOD on tape", temp_fname); 1014 /* log_it(tmp); */ 1015 } 1016 paranoid_free(datablock); 1017 paranoid_free(tmp); 1018 paranoid_free(temp_fname); 1019 paranoid_free(temp_cksum); 1020 paranoid_free(actual_cksum); 1021 return (retval); 1056 } 1057 if (strcmp(temp_cksum, actual_cksum)) { 1058 sprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum, 1059 temp_cksum); 1060 log_to_screen(tmp); 1061 sprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname, 1062 (long) orig_size >> 10); 1063 log_to_screen(tmp); 1064 retval++; 1065 } else { 1066 sprintf(tmp, "%s is GOOD on tape", temp_fname); 1067 /* log_it(tmp); */ 1068 } 1069 paranoid_free(datablock); 1070 paranoid_free(tmp); 1071 paranoid_free(temp_fname); 1072 paranoid_free(temp_cksum); 1073 paranoid_free(actual_cksum); 1074 return (retval); 1022 1075 } 1023 1076 … … 1035 1088 */ 1036 1089 int 1037 read_header_block_from_stream 1038 1039 { 1040 1041 /*@ buffers ***************************************************** */1042 1043 1044 /*@ int ********************************************************* */1045 1046 1047 /*@ end vars *************************************************** */1048 1049 tempblock = (char*)malloc((size_t) TAPE_BLOCK_SIZE);1050 1051 for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) 1052 { 1053 tempblock[i] = 0; 1054 } 1055 while(!(*pcontrol_char = tempblock[7000])) 1056 { 1057 g_tape_posK += fread (tempblock, 1, (size_t) TAPE_BLOCK_SIZE,g_tape_stream) / 1024;1058 1090 read_header_block_from_stream(long long *plen, char *filename, 1091 int *pcontrol_char) 1092 { 1093 1094 /*@ buffers ***************************************************** */ 1095 char *tempblock; 1096 1097 /*@ int ********************************************************* */ 1098 int i, retval; 1099 1100 /*@ end vars *************************************************** */ 1101 1102 tempblock = (char *) malloc((size_t) TAPE_BLOCK_SIZE); 1103 1104 for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) { 1105 tempblock[i] = 0; 1106 } 1107 while (!(*pcontrol_char = tempblock[7000])) { 1108 g_tape_posK += 1109 fread(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, 1110 g_tape_stream) / 1024; 1111 } 1059 1112 /* memcpy((char*)plength_of_incoming_file,(char*)tempblock+7001,sizeof(long long)); */ 1060 1113 /* for(*plen=0,i=7;i>=0;i--) {*plen<<=8; *plen |= tempblock[7001+i];} */ 1061 memcpy ((char *) plen, tempblock + 7001, sizeof (long long)); 1062 if (strcmp (tempblock + 6000 + *pcontrol_char, "Mondolicious, baby")) 1063 { 1064 log_it ("Bad header block at %ld K", (long) g_tape_posK); 1065 } 1066 strcpy (filename, tempblock + 1000); 1114 memcpy((char *) plen, tempblock + 7001, sizeof(long long)); 1115 if (strcmp(tempblock + 6000 + *pcontrol_char, "Mondolicious, baby")) { 1116 log_it("Bad header block at %ld K", (long) g_tape_posK); 1117 } 1118 strcpy(filename, tempblock + 1000); 1067 1119 /* strcpy(cksum,tempblock+5555);*/ 1068 1120 /* log_it( "%s (reading) fname=%s, filesize=%ld K", … … 1070 1122 (long) ((*plen) >> 10)); 1071 1123 */ 1072 if (*pcontrol_char == BLK_ABORTED_BACKUP) 1073 { 1074 log_to_screen ("I can't verify an aborted backup."); 1075 retval=1; 1076 } 1077 else 1078 { retval=0; } 1079 for(i=1000; i<1020; i++) { if (tempblock[i]<32 || tempblock[i]>126) { tempblock[i]=' '; } } 1080 tempblock[i] = '\0'; 1081 log_msg(6, "%s (fname=%s, size=%ld K)", marker_to_string (*pcontrol_char), 1082 tempblock+1000, (long) (*plen) >> 10); 1083 paranoid_free(tempblock); 1084 return (retval); 1124 if (*pcontrol_char == BLK_ABORTED_BACKUP) { 1125 log_to_screen("I can't verify an aborted backup."); 1126 retval = 1; 1127 } else { 1128 retval = 0; 1129 } 1130 for (i = 1000; i < 1020; i++) { 1131 if (tempblock[i] < 32 || tempblock[i] > 126) { 1132 tempblock[i] = ' '; 1133 } 1134 } 1135 tempblock[i] = '\0'; 1136 log_msg(6, "%s (fname=%s, size=%ld K)", 1137 marker_to_string(*pcontrol_char), tempblock + 1000, 1138 (long) (*plen) >> 10); 1139 paranoid_free(tempblock); 1140 return (retval); 1085 1141 } 1086 1142 … … 1098 1154 * @return The index of the record we just added. 1099 1155 */ 1100 int register_in_tape_catalog(t_archtype type, int number, long aux, char*fn) 1101 { 1102 int last; 1103 char fname[MAX_TAPECAT_FNAME_LEN]; 1104 char *p; 1105 1106 p = strrchr(fn, '/'); 1107 if (p) { p++; } else { p = fn; } 1108 strncpy(fname, p, MAX_TAPECAT_FNAME_LEN); 1109 fname[MAX_TAPECAT_FNAME_LEN] = '\0'; 1110 last = g_tapecatalog->entries; 1111 if (last >= MAX_TAPECATALOG_ENTRIES) 1112 { 1113 log_it("Warning - can't log #%d in tape catalog - too many entries already", number); 1114 return(-1); 1115 } 1116 g_tapecatalog->el[last].type = type; 1117 g_tapecatalog->el[last].number = number; 1118 g_tapecatalog->el[last].aux = aux; 1119 g_tapecatalog->el[last].tape_posK = g_tape_posK; 1120 strcpy(g_tapecatalog->el[last].fname, fname); 1121 g_tapecatalog->entries ++; 1122 return(last); // returns the index of the record we've jsut added 1156 int register_in_tape_catalog(t_archtype type, int number, long aux, 1157 char *fn) 1158 { 1159 int last; 1160 char fname[MAX_TAPECAT_FNAME_LEN]; 1161 char *p; 1162 1163 p = strrchr(fn, '/'); 1164 if (p) { 1165 p++; 1166 } else { 1167 p = fn; 1168 } 1169 strncpy(fname, p, MAX_TAPECAT_FNAME_LEN); 1170 fname[MAX_TAPECAT_FNAME_LEN] = '\0'; 1171 last = g_tapecatalog->entries; 1172 if (last >= MAX_TAPECATALOG_ENTRIES) { 1173 log_it 1174 ("Warning - can't log #%d in tape catalog - too many entries already", 1175 number); 1176 return (-1); 1177 } 1178 g_tapecatalog->el[last].type = type; 1179 g_tapecatalog->el[last].number = number; 1180 g_tapecatalog->el[last].aux = aux; 1181 g_tapecatalog->el[last].tape_posK = g_tape_posK; 1182 strcpy(g_tapecatalog->el[last].fname, fname); 1183 g_tapecatalog->entries++; 1184 return (last); // returns the index of the record we've jsut added 1123 1185 } 1124 1186 … … 1135 1197 */ 1136 1198 bool 1137 should_we_write_to_next_tape (long mediasize, 1138 long long length_of_incoming_file) 1139 { 1140 /*@ bool's ******************************************************/ 1141 bool we_need_a_new_tape = FALSE; 1142 1143 /*@ end vars ****************************************************/ 1144 1145 if (mediasize==0) { return(FALSE); } 1146 if (mediasize>0 && (g_tape_posK >> 10 >= mediasize)) 1147 { 1148 log_it("mediasize = %ld", mediasize); 1149 we_need_a_new_tape = TRUE; 1150 log_to_screen ("Should have started a new tape/CD already"); 1151 } 1152 if ((g_tape_posK + length_of_incoming_file / 1024) >> 10 >= mediasize-(SLICE_SIZE*4/1024)) 1153 { 1154 log_it("g_tape_posK = %ld\nmediasize = %ld\n", g_tape_posK, mediasize); 1155 we_need_a_new_tape = TRUE; 1156 } 1157 return (we_need_a_new_tape); 1199 should_we_write_to_next_tape(long mediasize, 1200 long long length_of_incoming_file) 1201 { 1202 /*@ bool's ***************************************************** */ 1203 bool we_need_a_new_tape = FALSE; 1204 1205 /*@ end vars *************************************************** */ 1206 1207 if (mediasize == 0) { 1208 return (FALSE); 1209 } 1210 if (mediasize > 0 && (g_tape_posK >> 10 >= mediasize)) { 1211 log_it("mediasize = %ld", mediasize); 1212 we_need_a_new_tape = TRUE; 1213 log_to_screen("Should have started a new tape/CD already"); 1214 } 1215 if ((g_tape_posK + length_of_incoming_file / 1024) >> 10 >= 1216 mediasize - (SLICE_SIZE * 4 / 1024)) { 1217 log_it("g_tape_posK = %ld\nmediasize = %ld\n", g_tape_posK, 1218 mediasize); 1219 we_need_a_new_tape = TRUE; 1220 } 1221 return (we_need_a_new_tape); 1158 1222 } 1159 1223 … … 1166 1230 * @return 0 for success, nonzero for failure. 1167 1231 */ 1168 int skip_incoming_files_until_we_find_this_one(char*the_file_I_was_reading) 1169 { 1170 char*pA; 1171 char*pB; 1172 int res; 1173 int ctrl_chr; 1174 char *temp_fname; 1175 char *datablock; 1176 long long temp_size, size; 1177 long bytes_to_write; 1178 1179 datablock = malloc(TAPE_BLOCK_SIZE); 1180 malloc_string(temp_fname); 1181 pB = strrchr(the_file_I_was_reading, '/'); if (pB) { pB++; } else { pB = the_file_I_was_reading; } 1182 log_msg(1, "skip_incoming_..(%s)", pB); 1183 log_msg(2, "Looking for initial START_AN_AFIO_OR_SLICE"); 1184 ctrl_chr=-1; 1185 while(ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) 1186 { 1187 res=read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr); 1188 if (ctrl_chr == BLK_START_AN_AFIO_OR_SLICE) 1189 { break; } 1190 log_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr); 1191 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 1192 log_msg(3, "Still trying to re-sync w/ tape"); 1193 } 1194 while(ctrl_chr != BLK_START_FILE) 1195 { 1196 res=read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr); 1197 if (ctrl_chr == BLK_START_FILE) 1198 { break; } 1199 log_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr); 1200 wrong_marker(BLK_START_FILE, ctrl_chr); 1201 log_msg(3, "Still trying to re-sync w/ tape"); 1202 } 1203 pA = strrchr(temp_fname, '/'); if (pA) { pA++; } else { pA = temp_fname; } 1204 pB = strrchr(the_file_I_was_reading, '/'); if (pB) { pB++; } else { pB = the_file_I_was_reading; } 1205 while (strcmp(pA, pB)) 1206 { 1207 log_msg(6, "Skipping %s (it's not %s)", temp_fname, the_file_I_was_reading); 1208 for(size=temp_size; size>0; size-=bytes_to_write) 1209 { 1210 bytes_to_write = (size < TAPE_BLOCK_SIZE) ? (long)size : TAPE_BLOCK_SIZE; 1211 // FIXME - needs error-checking and -catching 1212 fread(datablock,1,(size_t) TAPE_BLOCK_SIZE, g_tape_stream); 1213 } 1214 res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr); 1215 if (ctrl_chr != BLK_STOP_FILE) { wrong_marker (BLK_STOP_FILE, ctrl_chr); } 1216 res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr); 1217 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); } 1218 res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr); 1219 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); } 1220 res = read_header_block_from_stream (&temp_size, temp_fname, &ctrl_chr); 1221 if (ctrl_chr != BLK_START_FILE) { wrong_marker(BLK_START_FILE, ctrl_chr); } 1222 pA = strrchr(temp_fname, '/'); if (pA) { pA++; } else { pA = temp_fname; } 1223 pB = strrchr(the_file_I_was_reading, '/'); if (pB) { pB++; } else { pB = the_file_I_was_reading; } 1224 } 1225 log_msg(2, "Reading %s (it matches %s)", temp_fname, the_file_I_was_reading); 1226 paranoid_free(temp_fname); 1227 paranoid_free(datablock); 1228 return(0); 1232 int skip_incoming_files_until_we_find_this_one(char 1233 *the_file_I_was_reading) 1234 { 1235 char *pA; 1236 char *pB; 1237 int res; 1238 int ctrl_chr; 1239 char *temp_fname; 1240 char *datablock; 1241 long long temp_size, size; 1242 long bytes_to_write; 1243 1244 datablock = malloc(TAPE_BLOCK_SIZE); 1245 malloc_string(temp_fname); 1246 pB = strrchr(the_file_I_was_reading, '/'); 1247 if (pB) { 1248 pB++; 1249 } else { 1250 pB = the_file_I_was_reading; 1251 } 1252 log_msg(1, "skip_incoming_..(%s)", pB); 1253 log_msg(2, "Looking for initial START_AN_AFIO_OR_SLICE"); 1254 ctrl_chr = -1; 1255 while (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 1256 res = 1257 read_header_block_from_stream(&temp_size, temp_fname, 1258 &ctrl_chr); 1259 if (ctrl_chr == BLK_START_AN_AFIO_OR_SLICE) { 1260 break; 1261 } 1262 log_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr); 1263 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 1264 log_msg(3, "Still trying to re-sync w/ tape"); 1265 } 1266 while (ctrl_chr != BLK_START_FILE) { 1267 res = 1268 read_header_block_from_stream(&temp_size, temp_fname, 1269 &ctrl_chr); 1270 if (ctrl_chr == BLK_START_FILE) { 1271 break; 1272 } 1273 log_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr); 1274 wrong_marker(BLK_START_FILE, ctrl_chr); 1275 log_msg(3, "Still trying to re-sync w/ tape"); 1276 } 1277 pA = strrchr(temp_fname, '/'); 1278 if (pA) { 1279 pA++; 1280 } else { 1281 pA = temp_fname; 1282 } 1283 pB = strrchr(the_file_I_was_reading, '/'); 1284 if (pB) { 1285 pB++; 1286 } else { 1287 pB = the_file_I_was_reading; 1288 } 1289 while (strcmp(pA, pB)) { 1290 log_msg(6, "Skipping %s (it's not %s)", temp_fname, 1291 the_file_I_was_reading); 1292 for (size = temp_size; size > 0; size -= bytes_to_write) { 1293 bytes_to_write = 1294 (size < TAPE_BLOCK_SIZE) ? (long) size : TAPE_BLOCK_SIZE; 1295 // FIXME - needs error-checking and -catching 1296 fread(datablock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream); 1297 } 1298 res = 1299 read_header_block_from_stream(&temp_size, temp_fname, 1300 &ctrl_chr); 1301 if (ctrl_chr != BLK_STOP_FILE) { 1302 wrong_marker(BLK_STOP_FILE, ctrl_chr); 1303 } 1304 res = 1305 read_header_block_from_stream(&temp_size, temp_fname, 1306 &ctrl_chr); 1307 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 1308 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 1309 } 1310 res = 1311 read_header_block_from_stream(&temp_size, temp_fname, 1312 &ctrl_chr); 1313 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 1314 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 1315 } 1316 res = 1317 read_header_block_from_stream(&temp_size, temp_fname, 1318 &ctrl_chr); 1319 if (ctrl_chr != BLK_START_FILE) { 1320 wrong_marker(BLK_START_FILE, ctrl_chr); 1321 } 1322 pA = strrchr(temp_fname, '/'); 1323 if (pA) { 1324 pA++; 1325 } else { 1326 pA = temp_fname; 1327 } 1328 pB = strrchr(the_file_I_was_reading, '/'); 1329 if (pB) { 1330 pB++; 1331 } else { 1332 pB = the_file_I_was_reading; 1333 } 1334 } 1335 log_msg(2, "Reading %s (it matches %s)", temp_fname, 1336 the_file_I_was_reading); 1337 paranoid_free(temp_fname); 1338 paranoid_free(datablock); 1339 return (0); 1229 1340 } 1230 1341 … … 1235 1346 * @return 0 for success, nonzero for failure. 1236 1347 */ 1237 int 1238 start_to_read_from_next_tape (struct s_bkpinfo *bkpinfo) 1239 { 1240 /*@ int **********************************************************/ 1241 int res = 0; 1242 char *sz_msg; 1243 int ctrlchr; 1244 long long temp_size; 1245 malloc_string(sz_msg); 1246 /*@ end vars ****************************************************/ 1247 1248 paranoid_pclose(g_tape_stream); 1249 system("sync");system("sync");system("sync"); 1250 log_it ("Next tape requested."); 1251 insist_on_this_tape_number(g_current_media_number+1); // will increment it, too 1252 log_it ("Opening IN the next tape"); 1253 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) { log_OS_error(g_tape_fifo); log_to_screen ("Cannot openin stream device"); return(1); } 1254 g_tape_posK = 0; 1255 g_sigpipe = FALSE; 1256 res+=read_header_block_from_stream (&temp_size, sz_msg, &ctrlchr); /* just in case */ 1257 if (ctrlchr != BLK_START_OF_TAPE) { wrong_marker (BLK_START_OF_TAPE, ctrlchr); } 1258 res+=read_header_block_from_stream (&temp_size, sz_msg, &ctrlchr); /* just in case */ 1259 if (ctrlchr != BLK_START_OF_BACKUP) { wrong_marker (BLK_START_OF_BACKUP, ctrlchr); } 1260 else { log_msg(3, "Next tape opened OK. Whoopee!"); } 1261 paranoid_free(sz_msg); 1262 return (res); 1348 int start_to_read_from_next_tape(struct s_bkpinfo *bkpinfo) 1349 { 1350 /*@ int ********************************************************* */ 1351 int res = 0; 1352 char *sz_msg; 1353 int ctrlchr; 1354 long long temp_size; 1355 malloc_string(sz_msg); 1356 /*@ end vars *************************************************** */ 1357 1358 paranoid_pclose(g_tape_stream); 1359 system("sync"); 1360 system("sync"); 1361 system("sync"); 1362 log_it("Next tape requested."); 1363 insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too 1364 log_it("Opening IN the next tape"); 1365 if (! 1366 (g_tape_stream = 1367 open_device_via_buffer(bkpinfo->media_device, 'r', 1368 bkpinfo->internal_tape_block_size))) { 1369 log_OS_error(g_tape_fifo); 1370 log_to_screen("Cannot openin stream device"); 1371 return (1); 1372 } 1373 g_tape_posK = 0; 1374 g_sigpipe = FALSE; 1375 res += read_header_block_from_stream(&temp_size, sz_msg, &ctrlchr); /* just in case */ 1376 if (ctrlchr != BLK_START_OF_TAPE) { 1377 wrong_marker(BLK_START_OF_TAPE, ctrlchr); 1378 } 1379 res += read_header_block_from_stream(&temp_size, sz_msg, &ctrlchr); /* just in case */ 1380 if (ctrlchr != BLK_START_OF_BACKUP) { 1381 wrong_marker(BLK_START_OF_BACKUP, ctrlchr); 1382 } else { 1383 log_msg(3, "Next tape opened OK. Whoopee!"); 1384 } 1385 paranoid_free(sz_msg); 1386 return (res); 1263 1387 } 1264 1388 … … 1270 1394 * @return 0 for success, nonzero for failure. 1271 1395 */ 1272 int 1273 start_to_write_to_next_tape (struct s_bkpinfo *bkpinfo) 1274 { 1275 int res=0; 1276 char command[MAX_STR_LEN*2]; 1277 paranoid_pclose(g_tape_stream); 1278 system("sync");system("sync");system("sync"); 1279 log_it ("New tape requested."); 1280 insist_on_this_tape_number(g_current_media_number+1); // will increment g_current_media, too 1281 if (g_current_media_number > MAX_NOOF_MEDIA) { res++; log_to_screen("Too many tapes. Man, you need to use nfs!"); } 1282 if (bkpinfo->backup_media_type == cdstream) 1283 { 1284 sprintf (command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, MONDO_LOGFILE); 1285 log_it ("Opening OUT to next CD with the command"); 1286 log_it (command); 1287 log_it ("Let's see what happens, shall we?"); 1288 g_tape_stream = popen (command, "w"); 1289 if (!g_tape_stream) 1290 { 1291 log_to_screen ("Failed to openout to cdstream (fifo)"); 1292 return (1); 1293 } 1294 } 1295 else 1296 { 1297 log_it ("Opening OUT to next tape"); 1298 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) 1299 { 1300 log_OS_error(g_tape_fifo); 1301 log_to_screen ("Cannot openin stream device"); 1302 return(1); 1303 } 1304 } 1305 g_tape_posK = 0; 1306 g_sigpipe = FALSE; 1307 res+=write_header_block_to_stream (0, "start-of-tape", BLK_START_OF_TAPE); /* just in case */ 1308 res+=write_header_block_to_stream (0, "start-of-backup", BLK_START_OF_BACKUP); /* just in case */ 1309 return (res); 1396 int start_to_write_to_next_tape(struct s_bkpinfo *bkpinfo) 1397 { 1398 int res = 0; 1399 char command[MAX_STR_LEN * 2]; 1400 paranoid_pclose(g_tape_stream); 1401 system("sync"); 1402 system("sync"); 1403 system("sync"); 1404 log_it("New tape requested."); 1405 insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too 1406 if (g_current_media_number > MAX_NOOF_MEDIA) { 1407 res++; 1408 log_to_screen("Too many tapes. Man, you need to use nfs!"); 1409 } 1410 if (bkpinfo->backup_media_type == cdstream) { 1411 sprintf(command, 1412 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", 1413 bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, 1414 MONDO_LOGFILE); 1415 log_it("Opening OUT to next CD with the command"); 1416 log_it(command); 1417 log_it("Let's see what happens, shall we?"); 1418 g_tape_stream = popen(command, "w"); 1419 if (!g_tape_stream) { 1420 log_to_screen("Failed to openout to cdstream (fifo)"); 1421 return (1); 1422 } 1423 } else { 1424 log_it("Opening OUT to next tape"); 1425 if (! 1426 (g_tape_stream = 1427 open_device_via_buffer(bkpinfo->media_device, 'w', 1428 bkpinfo->internal_tape_block_size))) { 1429 log_OS_error(g_tape_fifo); 1430 log_to_screen("Cannot openin stream device"); 1431 return (1); 1432 } 1433 } 1434 g_tape_posK = 0; 1435 g_sigpipe = FALSE; 1436 res += write_header_block_to_stream(0, "start-of-tape", BLK_START_OF_TAPE); /* just in case */ 1437 res += write_header_block_to_stream(0, "start-of-backup", BLK_START_OF_BACKUP); /* just in case */ 1438 return (res); 1310 1439 } 1311 1440 … … 1325 1454 * @return 0 for success, nonzero for failure. 1326 1455 */ 1327 int write_backcatalog_to_tape (struct s_bkpinfo *bkpinfo) 1328 { 1329 int i, last, res=0; 1330 char *fname; 1331 1332 log_msg(2, "I am now writing back catalog to tape"); 1333 malloc_string(fname); 1334 last = g_tapecatalog->entries-1; 1335 for(i=0; i<=last; i++) 1336 { 1337 sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir, g_tapecatalog->el[i].fname); 1338 if (!does_file_exist(fname)) 1339 { log_msg(6, "Can't write %s - it doesn't exist.", fname); } 1340 else 1341 { 1342 write_header_block_to_stream (length_of_file(fname), "start-backcatalog-afio-or-slice", BLK_START_AN_AFIO_OR_SLICE); 1343 log_msg(2, "Writing %s", fname); 1344 if (write_file_to_stream_from_file(bkpinfo, fname)) 1345 { res++; log_msg(2, "%s failed", fname); } 1346 if (i!=last) 1347 { write_header_block_to_stream (0, "stop-backcatalog-afio-or-slice", BLK_STOP_AN_AFIO_OR_SLICE); } 1348 } 1349 } 1350 paranoid_free(fname); 1351 log_msg(2, "Finished writing back catalog to tape"); 1352 return(res); 1456 int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo) 1457 { 1458 int i, last, res = 0; 1459 char *fname; 1460 1461 log_msg(2, "I am now writing back catalog to tape"); 1462 malloc_string(fname); 1463 last = g_tapecatalog->entries - 1; 1464 for (i = 0; i <= last; i++) { 1465 sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir, 1466 g_tapecatalog->el[i].fname); 1467 if (!does_file_exist(fname)) { 1468 log_msg(6, "Can't write %s - it doesn't exist.", fname); 1469 } else { 1470 write_header_block_to_stream(length_of_file(fname), 1471 "start-backcatalog-afio-or-slice", 1472 BLK_START_AN_AFIO_OR_SLICE); 1473 log_msg(2, "Writing %s", fname); 1474 if (write_file_to_stream_from_file(bkpinfo, fname)) { 1475 res++; 1476 log_msg(2, "%s failed", fname); 1477 } 1478 if (i != last) { 1479 write_header_block_to_stream(0, 1480 "stop-backcatalog-afio-or-slice", 1481 BLK_STOP_AN_AFIO_OR_SLICE); 1482 } 1483 } 1484 } 1485 paranoid_free(fname); 1486 log_msg(2, "Finished writing back catalog to tape"); 1487 return (res); 1353 1488 } 1354 1489 … … 1360 1495 * @return 0 for success, nonzero for failure. 1361 1496 */ 1362 int 1363 write_data_disks_to_stream (char *fname) 1364 { 1365 /*@ pointers ****************************************************/ 1366 FILE *fin; 1367 char tmp[MAX_STR_LEN]; 1368 1369 /*@ long ********************************************************/ 1370 long m = -1; 1371 long templong; 1372 1373 /*@ int *********************************************************/ 1374 int i,j; 1375 1376 /*@ buffers *****************************************************/ 1377 char tempblock[256 * 1024]; 1378 1379 /*@ end vars ****************************************************/ 1380 1381 open_evalcall_form ("Writing data disks to tape"); 1382 log_to_screen ("Writing data disks to tape"); 1383 log_it ("Data disks = %s", fname); 1384 if (!does_file_exist (fname)) 1385 { 1386 sprintf (tmp, "Cannot find %s", fname); 1387 log_to_screen (tmp); 1388 return(1); 1389 } 1390 if (!(fin = fopen (fname, "r"))) 1391 { 1392 log_OS_error (fname); 1393 fatal_error ("Cannot openin the data disk"); 1394 } 1395 for (i = 0; i < 32; i++) /* 32MB */ 1396 { 1397 for (j = 0; j < 4; j++) /* 256K x 4 = 1MB (1024K) */ 1398 { 1399 if (!feof (fin)) 1400 { 1401 m = (long) fread (tempblock, 1, 256 * 1024, fin); 1402 } 1403 else 1404 { 1405 m = 0; 1406 } 1407 for (; m < 256 * 1024; m++) 1408 { 1409 tempblock[m] = '\0'; 1410 } 1411 g_tape_posK += 1412 fwrite (tempblock, 1, 256 * 1024, g_tape_stream) / 1024; 1413 } 1414 if (i>g_tape_buffer_size_MB) // otherwise, 'buffer' distorts calculations 1415 { 1416 templong = ((i-8) * 4 + j) * 100 / (128-8*4); 1417 update_evalcall_form ((int)(templong)); 1418 } 1419 } 1420 paranoid_fclose (fin); 1421 close_evalcall_form (); 1422 return (0); 1497 int write_data_disks_to_stream(char *fname) 1498 { 1499 /*@ pointers *************************************************** */ 1500 FILE *fin; 1501 char tmp[MAX_STR_LEN]; 1502 1503 /*@ long ******************************************************* */ 1504 long m = -1; 1505 long templong; 1506 1507 /*@ int ******************************************************** */ 1508 int i, j; 1509 1510 /*@ buffers **************************************************** */ 1511 char tempblock[256 * 1024]; 1512 1513 /*@ end vars *************************************************** */ 1514 1515 open_evalcall_form("Writing data disks to tape"); 1516 log_to_screen("Writing data disks to tape"); 1517 log_it("Data disks = %s", fname); 1518 if (!does_file_exist(fname)) { 1519 sprintf(tmp, "Cannot find %s", fname); 1520 log_to_screen(tmp); 1521 return (1); 1522 } 1523 if (!(fin = fopen(fname, "r"))) { 1524 log_OS_error(fname); 1525 fatal_error("Cannot openin the data disk"); 1526 } 1527 for (i = 0; i < 32; i++) { /* 32MB */ 1528 for (j = 0; j < 4; j++) { /* 256K x 4 = 1MB (1024K) */ 1529 if (!feof(fin)) { 1530 m = (long) fread(tempblock, 1, 256 * 1024, fin); 1531 } else { 1532 m = 0; 1533 } 1534 for (; m < 256 * 1024; m++) { 1535 tempblock[m] = '\0'; 1536 } 1537 g_tape_posK += 1538 fwrite(tempblock, 1, 256 * 1024, g_tape_stream) / 1024; 1539 } 1540 if (i > g_tape_buffer_size_MB) // otherwise, 'buffer' distorts calculations 1541 { 1542 templong = ((i - 8) * 4 + j) * 100 / (128 - 8 * 4); 1543 update_evalcall_form((int) (templong)); 1544 } 1545 } 1546 paranoid_fclose(fin); 1547 close_evalcall_form(); 1548 return (0); 1423 1549 } 1424 1550 … … 1432 1558 * @return 0 for success, nonzero for failure. 1433 1559 */ 1434 int 1435 write_file_to_stream_from_file (struct s_bkpinfo *bkpinfo, char *infile) 1436 { 1437 /*@ buffers *****************************************************/ 1438 char tmp[MAX_STR_LEN]; 1439 char datablock[TAPE_BLOCK_SIZE]; 1440 char checksum[MAX_STR_LEN]; 1441 char *infile_basename; 1442 1443 /*@ int *********************************************************/ 1444 int retval = 0; 1445 int noof_blocks; 1446 1447 /* unsigned int ch; */ 1448 unsigned int crc16; 1449 unsigned int crctt; 1450 1451 /*@ pointers ****************************************************/ 1452 FILE *fin; 1453 char *p; 1454 1455 /*@ long ********************************************************/ 1456 long bytes_to_read = 0; 1457 long i; 1458 1459 /*@ long long ***************************************************/ 1460 long long filesize; 1560 int write_file_to_stream_from_file(struct s_bkpinfo *bkpinfo, char *infile) 1561 { 1562 /*@ buffers **************************************************** */ 1563 char tmp[MAX_STR_LEN]; 1564 char datablock[TAPE_BLOCK_SIZE]; 1565 char checksum[MAX_STR_LEN]; 1566 char *infile_basename; 1567 1568 /*@ int ******************************************************** */ 1569 int retval = 0; 1570 int noof_blocks; 1571 1572 /* unsigned int ch; */ 1573 unsigned int crc16; 1574 unsigned int crctt; 1575 1576 /*@ pointers *************************************************** */ 1577 FILE *fin; 1578 char *p; 1579 1580 /*@ long ******************************************************* */ 1581 long bytes_to_read = 0; 1582 long i; 1583 1584 /*@ long long ************************************************** */ 1585 long long filesize; 1461 1586 1462 1587 #ifdef EXTRA_TAPE_CHECKSUMS 1463 1588 int ch; 1464 1589 #endif 1465 1590 1466 /*@ initialize *************************************************/ 1467 crc16 = 0; 1468 crctt = 0; 1469 1470 1471 1472 /*@ end vars ****************************************************/ 1473 1474 infile_basename = strrchr(infile, '/'); 1475 if (infile_basename) { infile_basename++; } else { infile_basename=infile; } 1476 filesize = length_of_file (infile); 1477 if (should_we_write_to_next_tape (bkpinfo->media_size[g_current_media_number], filesize)) 1478 { 1479 start_to_write_to_next_tape (bkpinfo); 1480 write_backcatalog_to_tape (bkpinfo); 1481 } 1482 p = strrchr (infile, '/'); 1483 if (!p) 1484 { 1485 p = infile; 1486 } 1487 else 1488 { 1489 p++; 1490 } 1491 sprintf (tmp, "Writing file '%s' to tape (%ld KB)", p, 1492 (long) filesize >> 10); 1493 log_it (tmp); 1494 write_header_block_to_stream (filesize, infile_basename, BLK_START_FILE); 1591 /*@ initialize ************************************************ */ 1592 crc16 = 0; 1593 crctt = 0; 1594 1595 1596 1597 /*@ end vars *************************************************** */ 1598 1599 infile_basename = strrchr(infile, '/'); 1600 if (infile_basename) { 1601 infile_basename++; 1602 } else { 1603 infile_basename = infile; 1604 } 1605 filesize = length_of_file(infile); 1606 if (should_we_write_to_next_tape 1607 (bkpinfo->media_size[g_current_media_number], filesize)) { 1608 start_to_write_to_next_tape(bkpinfo); 1609 write_backcatalog_to_tape(bkpinfo); 1610 } 1611 p = strrchr(infile, '/'); 1612 if (!p) { 1613 p = infile; 1614 } else { 1615 p++; 1616 } 1617 sprintf(tmp, "Writing file '%s' to tape (%ld KB)", p, 1618 (long) filesize >> 10); 1619 log_it(tmp); 1620 write_header_block_to_stream(filesize, infile_basename, 1621 BLK_START_FILE); 1495 1622 //go_here_to_restart_saving_of_file: 1496 if (!(fin = fopen (infile, "r"))) { log_OS_error(infile); return(1); } 1497 for (noof_blocks = 0; filesize > 0; 1498 noof_blocks++, filesize -= bytes_to_read) 1499 { 1500 if (filesize < TAPE_BLOCK_SIZE) 1501 { 1502 bytes_to_read = (long) filesize; 1503 for (i = 0; i < TAPE_BLOCK_SIZE; i++) 1504 { 1505 datablock[i] = '\0'; 1506 } 1507 } 1508 else 1509 { 1510 bytes_to_read = TAPE_BLOCK_SIZE; 1511 } 1512 (void) fread (datablock, 1, (size_t) bytes_to_read, fin); 1513 g_tape_posK += fwrite (datablock, 1, /*bytes_to_read */ (size_t) TAPE_BLOCK_SIZE, 1514 g_tape_stream) / 1024; 1515 if (g_sigpipe) 1516 { 1517 iamhere("Sigpipe occurred recently. I'll start a new tape."); 1518 fclose(fin); 1519 g_sigpipe = FALSE; 1520 start_to_write_to_next_tape (bkpinfo); 1521 write_backcatalog_to_tape (bkpinfo); // kinda-sorta recursive :) 1522 return(0); 1523 } 1623 if (!(fin = fopen(infile, "r"))) { 1624 log_OS_error(infile); 1625 return (1); 1626 } 1627 for (noof_blocks = 0; filesize > 0; 1628 noof_blocks++, filesize -= bytes_to_read) { 1629 if (filesize < TAPE_BLOCK_SIZE) { 1630 bytes_to_read = (long) filesize; 1631 for (i = 0; i < TAPE_BLOCK_SIZE; i++) { 1632 datablock[i] = '\0'; 1633 } 1634 } else { 1635 bytes_to_read = TAPE_BLOCK_SIZE; 1636 } 1637 (void) fread(datablock, 1, (size_t) bytes_to_read, fin); 1638 g_tape_posK += 1639 fwrite(datablock, 1, /*bytes_to_read */ 1640 (size_t) TAPE_BLOCK_SIZE, 1641 g_tape_stream) / 1024; 1642 if (g_sigpipe) { 1643 iamhere("Sigpipe occurred recently. I'll start a new tape."); 1644 fclose(fin); 1645 g_sigpipe = FALSE; 1646 start_to_write_to_next_tape(bkpinfo); 1647 write_backcatalog_to_tape(bkpinfo); // kinda-sorta recursive :) 1648 return (0); 1649 } 1524 1650 #ifdef EXTRA_TAPE_CHECKSUMS 1525 for(i=0;i<bytes_to_read;i++) 1526 { 1527 ch=datablock[i]; 1528 crc16=updcrcr(crc16,(unsigned)ch); 1529 crctt=updcrc(crctt,(unsigned)ch); 1530 } 1651 for (i = 0; i < bytes_to_read; i++) { 1652 ch = datablock[i]; 1653 crc16 = updcrcr(crc16, (unsigned) ch); 1654 crctt = updcrc(crctt, (unsigned) ch); 1655 } 1531 1656 #endif 1532 1533 paranoid_fclose(fin);1534 sprintf(checksum, "%04x%04x", crc16, crctt);1535 write_header_block_to_stream(g_current_media_number, checksum,1536 1657 } 1658 paranoid_fclose(fin); 1659 sprintf(checksum, "%04x%04x", crc16, crctt); 1660 write_header_block_to_stream(g_current_media_number, checksum, 1661 BLK_STOP_FILE); 1537 1662 // log_it("File '%s' written to tape.", infile); 1538 1663 return (retval); 1539 1664 } 1540 1665 … … 1555 1680 */ 1556 1681 int 1557 write_header_block_to_stream (long long length_of_incoming_file, char *filename, 1558 int control_char) 1559 { 1560 /*@ buffers *****************************************************/ 1561 char tempblock[TAPE_BLOCK_SIZE]; 1562 char tmp[MAX_STR_LEN]; 1563 char *p; 1564 1565 /*@ int *********************************************************/ 1566 int i; 1567 1568 /*@ long long ***************************************************/ 1569 long long olen; 1570 1571 /*@ end vars ****************************************************/ 1572 1573 1574 olen = length_of_incoming_file; 1575 p = strrchr (filename, '/'); /* Make 'em go, "Unnnh!" Oh wait, that was _Master_ P... */ 1576 if (!p) 1577 { 1578 p = filename; 1579 } 1580 else 1581 { 1582 p++; 1583 } 1584 if (!g_tape_stream) 1585 { 1586 log_to_screen 1587 ("You're not backing up to tape. Why write a tape header?"); 1588 return(1); 1589 } 1590 for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) 1591 { 1592 tempblock[i] = 0; 1593 } 1594 sprintf (tempblock + 6000 + control_char, "Mondolicious, baby"); 1595 tempblock[7000] = control_char; 1682 write_header_block_to_stream(long long length_of_incoming_file, 1683 char *filename, int control_char) 1684 { 1685 /*@ buffers **************************************************** */ 1686 char tempblock[TAPE_BLOCK_SIZE]; 1687 char tmp[MAX_STR_LEN]; 1688 char *p; 1689 1690 /*@ int ******************************************************** */ 1691 int i; 1692 1693 /*@ long long ************************************************** */ 1694 long long olen; 1695 1696 /*@ end vars *************************************************** */ 1697 1698 1699 olen = length_of_incoming_file; 1700 p = strrchr(filename, '/'); /* Make 'em go, "Unnnh!" Oh wait, that was _Master_ P... */ 1701 if (!p) { 1702 p = filename; 1703 } else { 1704 p++; 1705 } 1706 if (!g_tape_stream) { 1707 log_to_screen 1708 ("You're not backing up to tape. Why write a tape header?"); 1709 return (1); 1710 } 1711 for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) { 1712 tempblock[i] = 0; 1713 } 1714 sprintf(tempblock + 6000 + control_char, "Mondolicious, baby"); 1715 tempblock[7000] = control_char; 1596 1716 /* for(i=0;i<8;i++) {tempblock[7001+i]=olen&0xff; olen>>=8;} */ 1597 memcpy (tempblock + 7001, (char *) &olen, sizeof(long long));1717 memcpy(tempblock + 7001, (char *) &olen, sizeof(long long)); 1598 1718 /* if (length_of_incoming_file) {memcpy(tempblock+7001,(char*)&length_of_incoming_file,sizeof(long long));} */ 1599 strcpy(tempblock + 1000, filename);1719 strcpy(tempblock + 1000, filename); 1600 1720 /* strcpy(tempblock+5555,cksum); */ 1601 g_tape_posK += fwrite (tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024; 1602 sprintf (tmp, "%s (fname=%s, size=%ld K)", marker_to_string (control_char), 1603 p, (long) length_of_incoming_file >> 10); 1604 log_msg(6, tmp); 1721 g_tape_posK += 1722 fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, 1723 g_tape_stream) / 1024; 1724 sprintf(tmp, "%s (fname=%s, size=%ld K)", 1725 marker_to_string(control_char), p, 1726 (long) length_of_incoming_file >> 10); 1727 log_msg(6, tmp); 1605 1728 /* log_tape_pos(); */ 1606 1729 return (0); 1607 1730 } 1608 1731 … … 1621 1744 * @param it_is What we got. 1622 1745 */ 1623 void 1624 wrong_marker (int should_be, int it_is) 1625 { 1626 /*@ buffer ******************************************************/ 1627 char tmp[MAX_STR_LEN]; 1628 1629 1630 /*@ end vars ****************************************************/ 1631 sprintf (tmp, "Wrong marker! (Should be %s, ", 1632 marker_to_string (should_be)); 1633 sprintf (tmp + strlen (tmp), "is actually %s)", marker_to_string (it_is)); 1634 log_to_screen (tmp); 1746 void wrong_marker(int should_be, int it_is) 1747 { 1748 /*@ buffer ***************************************************** */ 1749 char tmp[MAX_STR_LEN]; 1750 1751 1752 /*@ end vars *************************************************** */ 1753 sprintf(tmp, "Wrong marker! (Should be %s, ", 1754 marker_to_string(should_be)); 1755 sprintf(tmp + strlen(tmp), "is actually %s)", marker_to_string(it_is)); 1756 log_to_screen(tmp); 1635 1757 } 1636 1758 -
trunk/mondo/mondo/common/libmondo-stream.h
r30 r58 1 1 /* libmondo-stream.h 2 * $Id : libmondo-stream.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 -
trunk/mondo/mondo/common/libmondo-string.c
r57 r58 122 122 { 123 123 char *pos_w_commas; 124 char *output;124 static char output[MAX_STR_LEN]; 125 125 char *tmp; 126 126 int j; … … 145 145 asprintf(&pos_w_commas, "%s", tmp); 146 146 } 147 asprintf(&output, "%s", pos_w_commas);147 strcpy(output, pos_w_commas); 148 148 paranoid_free(pos_w_commas); 149 149 paranoid_free(tmp); … … 250 250 assert(width > 2); 251 251 252 asprintf( &output, "%s", incoming);252 asprintf(output, "%s", incoming); 253 253 for (i = (int) strlen(output); i < width; i++) { 254 254 output[i] = ' '; … … 707 707 /*@ buffers ***************************************************** */ 708 708 char *tmp; 709 char *tmp1; 709 710 710 711 /*@ pointers **************************************************** */ … … 738 739 in_out[i++] = ' '; 739 740 } else if (in_out[i] == '\r') { 740 paranoid_free(tmp);741 asprintf(&tmp, "%s", in_out + i);742 strcpy(in_out, tmp);741 asprintf(&tmp1, "%s", in_out + i); 742 strcpy(in_out, tmp1); 743 paranoid_free(tmp1); 743 744 i = -1; 744 745 continue; -
trunk/mondo/mondo/common/libmondo-tools.c
r49 r58 1 /* libmondo-tools.c misc tools 2 $Id$ 3 . 4 5 6 06/28 7 - abort if RAID partitions found but /etc/raidtab not found 8 9 06/25 10 - don't insist on ms-sys; recommend it 11 - don't fatal_error if can't open log file 12 13 06/14 14 - call mindi -V before calling mindi --makemountlist 15 16 04/09 17 - lots of malloc'd char*'s instead of char[]'s in post_param_config'n 18 19 04/02 20 - better sanity-checking, re: /etc/modules.conf 21 22 02/15 23 - abort if Windows dir but no ms-sys or parted 24 25 02/08 26 - missing ramdisk/initrd support is nonfatal now (but stupid) 27 28 01/16 29 - added g_kernel_version and get_kernel_version() 30 31 01/08/2004 32 - fixed /boot mounter thingy 33 34 11/14/2003 35 - if <50MB free in /root, softlink /root/images/mindi to 36 /home/root/images/mindi as a workaround 37 38 10/23 39 - streaming backups now generate 4MB sets; CDs, 8MB sets 40 41 10/21 42 - better at finding your /boot in order to mount it, if nec. 43 - link /etc/modules.conf to /etc/conf.modules if former 44 is missing but latter is not 45 - changed "/mnt/cdrom" to MNT_CDROM 46 - changed "/mnt/floppy" to MNT_FLOPPY 47 48 10/13 49 - added stop_magicdev_if_necessary() 50 - added restart_magicdev_if_necessary() 51 52 10/02 53 - don't eject if bkpinfo->please_dont_eject is TRUE 54 55 09/28 56 - fixed segfault in mount_..._necessary 57 58 09/26 59 - ask for cmp (or create workaround if possible) 60 61 09/25 62 - add DVD support 63 64 09/24 65 - don't overwrite existing media-dev value in bkpinfo IF it's 66 a tape device AND it's already populated by /dev/{something} 67 ...This helps w/ weird tape drives 68 69 09/23 70 - malloc/free global strings in new subroutines - malloc_libmondo_global_strings() 71 and free_libmondo_global_strings() - which are in libmondo-tools.c 72 73 09/18 74 - added stop_autofs_if_necessary() and restart_autofs_if_necessary() 75 76 09/13 77 - added log_debug_msg() 78 - turned log_it() into a macro 79 80 09/10 81 - reduced PPCFG_RAMDISK to 150m (was 200m) 82 - max set size is now 8MB (was 6) 83 - added 'buffer' to requisite tools 84 85 08/29 86 - typical set size is now 5MB 87 88 07/22 89 - increased PPCFG* to 200m 90 91 05/07 92 - changed grep -m1 to grep | head -n1 for Debian users 93 - pre_param_...() also mkdir -p /mnt/cdrom, just in case 94 95 05/05 96 - cleaner logging of call to dd if=<tape> of=/dev/null 97 - added Joshua Oreman's FreeBSD patches 98 99 05/04 100 - added Herman Kuster's multi-level bkp patch 101 102 05/02 103 - log_it() --- "Message repeated N times" (if it was) 104 105 04/24 106 - added lots of assert()'s and log_OS_error()'s 107 - reset_bkpinfop() --- reset all media_size[] array 108 - increased tmpfs ramdisk to size=100m 109 110 04/22 111 - post_param_configuration() --- store iso-dev and isodir 112 113 04/05 114 - re-enable tmpfs ramdisk/mountpt _but_ make sure size=80m 115 - in post_param_configuration(), use cdrecord in preference 116 to dvdrecord now 117 118 03/27 119 - disabled tmpfs ramdisk/mountpt 120 121 01/02/2003 122 - bkpinfo->makefilelist = TRUE 123 124 12/10/2002 125 - added g_loglevel 126 - fixed minor bug in clean_up_KDE_desktop_if_necessary() 127 - log versions of newt, slang, ncurses 128 - isodir defaults to / if disaster recovery 129 130 11/28 131 - unmount all CD devices at start 132 - added clean_up_KDE_desktop_if_necessary() 133 134 11/20 135 - don't use lilo.conf.anaconda; abort instead 136 - mount/unmount /boot partition for Gentoo 1.2 users 137 138 11/13 139 - call mindi --makemountlist as part of testing sanity of distro 140 141 11/08 142 - added a couple of chmod 700's (one for scratchdir, one for tmpdir) 143 to post_param_configuration() 144 145 10/01 - 10/31 146 - added checking of / and /root's free space to some_basic_sanity_checks() 147 - moved some subroutines here from common/libmondo-archive 148 149 09/01 - 09/30 150 - don't write log_it()'s string to stdout, even if text mode 151 - tell user the kernel is bad if it has no ramdisk support but allow 152 it if they want to use the failsafe kernel for booting 153 - run_program_and_log_output() now takes boolean operator to specify 154 whether it will log its activities in the event of _success_ 155 - if mkfs.vfat not found but mkfs.msdos found then create a softlink 156 from the former to the latter 157 158 08/01 - 08/31 159 - if /etc/lilo.conf not found not /etc/lilo.conf.anaconda found 160 then create a softlink from the former to the latter, to work 161 around RH7.3's b0rken LILO support 162 - handle unknown media size 163 164 07/27 165 - created 1 /* $Id$ 2 misc tools 166 3 */ 167 168 4 169 5 /** -
trunk/mondo/mondo/common/mondostructures.h
r30 r58 5 5 copyright : (C) 2002 by Stan Benoit 6 6 email : troff@nakedsoul.org 7 cvsid : $Id : mondostructures.h,v 1.3 2004/06/17 08:49:06 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 -
trunk/mondo/mondo/common/newt-specific.c
r56 r58 475 475 vasprintf(&output, fmt, args); 476 476 log_msg(0, output); 477 if (strlen(output > 80)) {477 if (strlen(output) > 80) { 478 478 output[80] = '\0'; 479 479 }
Note:
See TracChangeset
for help on using the changeset viewer.