Changeset 1977 in MondoRescue for branches/stable/mondo/src/common/libmondo-stream.c
- Timestamp:
- Jun 2, 2008, 10:49:01 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-stream.c
r1939 r1977 2 2 3 3 ...tools for talking to tapes, Monitas streams, etc. 4 4 5 */ 5 6 … … 364 365 int res = 0; 365 366 char *fname = (char *)&res; /* Should NOT be NULL */ 367 char *tmp = NULL; 366 368 367 369 // xattr … … 371 373 wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr); 372 374 } 373 if (!strstr(fname, "xattr")) { 374 fatal_error("Wrong order for xattr, sunshine."); 375 if (strstr(fname, "xattr") == NULL) { 376 asprintf(&tmp,"Wrong order expected xattr, got %s, sunshine.", fname); 377 fatal_error(tmp); 375 378 } 376 379 read_file_from_stream_to_file(xattr_fname, *ptmp_size); 377 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);380 res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr); 378 381 if (*pctrl_chr != BLK_STOP_EXAT_FILE) { 379 382 wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr); 380 383 } 381 384 mr_msg(1, "Got xattr"); 382 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);385 res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr); 383 386 if (*pctrl_chr != BLK_STOP_EXTENDED_ATTRIBUTES) { 384 387 wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES, *pctrl_chr); 385 388 } 386 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);387 if ( pctrl_chr == BLK_START_AN_AFIO_OR_SLICE) {389 res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr); 390 if (*pctrl_chr == BLK_START_AN_AFIO_OR_SLICE) { 388 391 log_msg(1, "No acl attributes found, skipping to afio files"); 389 392 return(0); 390 393 } else { 391 if ( pctrl_chr != BLK_START_EXTENDED_ATTRIBUTES) {394 if (*pctrl_chr != BLK_START_EXTENDED_ATTRIBUTES) { 392 395 wrong_marker(BLK_START_EXTENDED_ATTRIBUTES, *pctrl_chr); 393 396 } … … 397 400 if (g_getfacl) { 398 401 res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr); 399 if (!strstr(fname, "acl")) {400 fatal_error("Wrong order for acl, sunshine.");401 }402 402 if (*pctrl_chr != BLK_START_EXAT_FILE) { 403 403 wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr); 404 404 } 405 if (strstr(fname, "acl") == NULL) { 406 asprintf(&tmp,"Wrong order expected acl, got %s, sunshine.", fname); 407 fatal_error(tmp); 408 } 405 409 read_file_from_stream_to_file(acl_fname, *ptmp_size); 406 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);410 res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr); 407 411 if (*pctrl_chr != BLK_STOP_EXAT_FILE) { 408 412 wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr); 409 413 } 410 res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);414 res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr); 411 415 if (*pctrl_chr != BLK_STOP_EXTENDED_ATTRIBUTES) { 412 416 wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES, *pctrl_chr); … … 595 599 596 600 597 int set_tape_block_size_with_mt(char *tapedev, 598 long internal_tape_block_size) 601 int set_tape_block_size_with_mt(long internal_tape_block_size) 599 602 { 600 603 char *tmp; 601 604 int res; 602 605 603 if (strncmp( tapedev, "/dev/", 5)) {606 if (strncmp(bkpinfo->media_device, "/dev/", 5)) { 604 607 mr_msg(1, 605 608 "Not using 'mt setblk'. This isn't an actual /dev entry."); 606 609 return (0); 607 610 } 608 mr_asprintf(&tmp, "mt -f %s setblk %ld", tapedev, 609 internal_tape_block_size); 611 mr_asprintf(&tmp, "mt -f %s setblk %ld",bkpinfo->media_device,internal_tape_block_size); 610 612 res = run_program_and_log_output(tmp, 3); 611 613 mr_free(tmp); 612 614 return (res); 615 } 616 617 /** 618 * Return the non-rewinding device when passed the normal one 619 * @param tapedev The tape device to open for writing. 620 * @note the caller needs to free the string returned 621 */ 622 char *get_non_rewind_dev(char *tapedev) 623 { 624 625 char *ntapedev = NULL; 626 char *p = NULL; 627 char *q = NULL; 628 char *r = NULL; 629 630 ntapedev = (char *)malloc(strlen(tapedev)+sizeof(char)); 631 p = strrchr(tapedev,'/'); 632 if (p == NULL) { 633 log_it("Didn't find a '/' in %s",tapedev); 634 return(NULL); 635 } 636 637 /* Copy tapedev content up to the last / */ 638 q = tapedev; 639 r = ntapedev; 640 while (q != p) { 641 *r = *q; 642 r++; 643 q++; 644 } 645 /* Copy the '/' */ 646 *r = *q; 647 r++; 648 q++; 649 /* Adds a 'n' - non-rewinding */ 650 *r = 'n'; 651 r++; 652 /* Copy the rest of tapedev */ 653 while (*q != '\0') { 654 *r = *q; 655 r++; 656 q++; 657 } 658 *r = '\0'; 659 if (mt_says_tape_exists(ntapedev)) { 660 log_it("Non-rewinding tape device is %s",ntapedev); 661 } else { 662 log_it("Unable to find non-rewinding tape device."); 663 ntapedev = NULL; 664 } 665 return(ntapedev); 666 } 667 668 669 670 /** 671 * Handle OBDR if we were asked to do so 672 * @param tapedev The tape device to open for reading. 673 */ 674 int skip_obdr(void) 675 { 676 char *command = NULL; 677 int res = 0; 678 679 log_it("Skipping OBDR headers"); 680 asprintf(&command, "mt -f %s rewind",bkpinfo->media_device); 681 res = run_program_and_log_output(command, 1); 682 paranoid_free(command); 683 684 asprintf(&command, "mt -f %s fsf 2",bkpinfo->media_device); 685 res = run_program_and_log_output(command, 1); 686 paranoid_free(command); 687 688 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size); 689 return(res); 690 } 691 692 /** 693 * Handle OBDR if we were asked to do so 694 * @param tapedev The tape device to open for writing. 695 * @return 0 for success, nonzero for failure. 696 * @note This should be called ONLY from backup processes. It will OVERWRITE ANY 697 * EXISTING DATA on the tape! 698 */ 699 int create_obdr(void) 700 { 701 702 char *command = NULL; 703 int res = 0; 704 705 log_it("Creating OBDR headers"); 706 /* OBDR: First block 10 kB of zero bs = 512 */ 707 asprintf(&command, "mt -f %s compression off",bkpinfo->media_device); 708 res = run_program_and_log_output(command, 1); 709 paranoid_free(command); 710 711 asprintf(&command, "mt -f %s rewind",bkpinfo->media_device); 712 res += run_program_and_log_output(command, 1); 713 paranoid_free(command); 714 715 set_tape_block_size_with_mt(512); 716 717 asprintf(&command, "dd if=/dev/zero of=%s bs=512 count=20",bkpinfo->media_device); 718 res += run_program_and_log_output(command, 1); 719 paranoid_free(command); 720 721 /* OBDR: then ISO boot image bs = 2048 */ 722 set_tape_block_size_with_mt(2048); 723 724 asprintf(&command, "dd if=%s of=%s bs=2048",MINDI_CACHE"/mondorescue.iso",bkpinfo->media_device); 725 res += run_program_and_log_output(command, 1); 726 paranoid_free(command); 727 728 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size); 729 return(res); 613 730 } 614 731 … … 633 750 int i; 634 751 int j; 635 int res ;752 int res = 0; 636 753 long length, templong; 637 754 size_t k; … … 654 771 return (0); 655 772 } 773 774 // mondoarchive should have configured everything to give the right non-rew device 775 if ((bkpinfo->use_obdr) && (bkpinfo->media_device != NULL)) { 776 res = skip_obdr(); 777 if (res != 0) { 778 log_it("Not able to skip OBDR - Restore will have to be done manually"); 779 } 780 } else { 781 if (bkpinfo->media_device == NULL) { 782 log_it("Not able to skip OBDR - Restore will have to be done manually"); 783 } 784 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size); 785 } 786 656 787 insist_on_this_tape_number(1); 657 788 mr_asprintf(&outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir); 658 789 make_hole_for_file(outfname); 659 660 set_tape_block_size_with_mt(bkpinfo->media_device,661 bkpinfo->internal_tape_block_size);662 790 663 791 log_it("Opening IN tape"); … … 762 890 /** 763 891 * Start writing to a tape device for the backup. 892 * Handle OBDR if we were asked to do so 764 893 * @param tapedev The tape device to open for writing. 765 894 * @return 0 for success, nonzero for failure. … … 767 896 * EXISTING DATA on the tape! 768 897 */ 769 int openout_tape( char *tapedev, long internal_tape_block_size)770 { 898 int openout_tape() { 899 771 900 g_current_media_number = 1; 772 901 if (g_tape_stream) { … … 777 906 g_tape_posK = 0; 778 907 779 set_tape_block_size_with_mt(tapedev, internal_tape_block_size); 908 if (bkpinfo->use_obdr) { 909 create_obdr(); 910 } else { 911 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size); 912 } 780 913 log_it("Opening OUT tape"); 781 914 if (! 782 915 (g_tape_stream = 783 open_device_via_buffer( tapedev, 'w', internal_tape_block_size))) {916 open_device_via_buffer(bkpinfo->media_device, 'w', internal_tape_block_size))) { 784 917 log_to_screen(_("Cannot openin stream device")); 785 918 return (1);
Note:
See TracChangeset
for help on using the changeset viewer.