Changeset 3875 in MondoRescue
- Timestamp:
- Mar 8, 2024, 3:19:14 AM (7 weeks ago)
- Location:
- branches/3.3/mondo/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mondo/src/common/libmondo-archive.c
r3874 r3875 2466 2466 2467 2467 mr_asprintf(bkp, "%s", cd_dev); 2468 if ((cd_dev = find_ dvd_device()) != NULL) {2468 if ((cd_dev = find_optical_device()) != NULL) { 2469 2469 if (!system("which cdrecord > /dev/null 2> /dev/null")) { 2470 2470 mr_asprintf(cdrecord, "cdrecord dev=%s -atip", cd_dev); … … 2536 2536 ok_go_ahead_burn_it = TRUE; 2537 2537 mr_free(cdrom_dev); 2538 if ((cdrom_dev = find_ cdrom_device()) != NULL) {2538 if ((cdrom_dev = find_optical_device()) != NULL) { 2539 2539 /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird 2540 2540 log_msg(2, "paafcd: Retracting CD-ROM drive if possible" ); … … 3096 3096 if (g_current_media_number == 1 && !res 3097 3097 && (bkpinfo->backup_media_type == cdr)) { 3098 if ((tmp = find_ cdrom_device()) == NULL) { // make sure find_cdrom_device() finds, records CD-R's loc3098 if ((tmp = find_optical_device()) == NULL) { // make sure find_optical_device() finds, records CD-R's loc 3099 3099 log_msg(3, "*Sigh* Mike, I hate your computer."); 3100 3100 // if it can't be found then force pausing … … 3208 3208 if (bkpinfo->backup_media_type != iso) { 3209 3209 mr_free(bkpinfo->media_device); 3210 bkpinfo->media_device = find_ cdrom_device(); // replace 0,0,0 with /dev/cdrom3210 bkpinfo->media_device = find_optical_device(); // replace 0,0,0 with /dev/cdrom 3211 3211 } 3212 3212 if (chdir("/")) { -
branches/3.3/mondo/src/common/libmondo-cli.c
r3874 r3875 349 349 } 350 350 if (!flag_set['d']) { 351 if ((bkpinfo->media_device = find_ dvd_device()) != NULL) {351 if ((bkpinfo->media_device = find_optical_device()) != NULL) { 352 352 flag_set['d'] = TRUE; 353 353 log_to_screen("I guess DVD drive is at %s", bkpinfo->media_device); -
branches/3.3/mondo/src/common/libmondo-devices-EXT.h
r3874 r3875 2 2 * $Id$ 3 3 */ 4 /* Reviewed */ 5 extern char *find_optical_device(void); 4 6 7 /* TBC */ 5 8 extern bool am_I_in_disaster_recovery_mode(void); 6 9 extern bool does_device_exist(char *device); 7 10 extern int does_partition_exist(const char *drive, int partno); 8 11 extern bool does_string_exist_in_boot_block(char *dev, char *str); 9 extern int find_and_mount_actual_cd( 10 char *mountpoint); 11 extern int find_cdrom_device(char *output, bool try_to_mount); 12 extern char *find_dvd_device(void); 12 extern int find_and_mount_actual_cd(char *mountpoint); 13 13 extern long get_phys_size_of_drive(char *drive); 14 14 extern bool is_this_a_valid_disk_format(char *format); … … 16 16 extern int find_device_in_mountlist(struct mountlist_itself *mountlist, 17 17 char *device); 18 extern int mount_CDROM_here(char *device, const char *mountpoint);19 18 extern long long size_of_specific_device_in_mountlist(struct 20 19 mountlist_itself -
branches/3.3/mondo/src/common/libmondo-devices.c
r3874 r3875 447 447 448 448 449 450 /** 451 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has 452 * not been specified, call find_cdrom_device() to find it. 449 /** 450 * Try to mount CD/DVD at @p mountpoint. If the CD/DVD is not found or has 451 * not been specified, call find_optical_device() to find it. 453 452 * @param mountpoint Where to mount the CD-ROM. 454 * @return 0 for success, nonzerofor failure.455 * @see mount_ CDROM_here456 */ 457 intfind_and_mount_actual_cd(char *mountpoint) {453 * @return TRUE for success, FALSE for failure. 454 * @see mount_media 455 */ 456 bool find_and_mount_actual_cd(char *mountpoint) { 458 457 459 458 /*@ buffers ***************************************************** */ 460 459 461 460 /*@ int's ****************************************************** */ 462 intres;461 bool res; 463 462 464 463 /*@ end vars **************************************************** */ … … 467 466 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 468 467 469 if (g_backup_media_type == dvd) { 470 if (bkpinfo->media_device == NULL) { 471 bkpinfo->media_device = find_dvd_device(); 472 } 473 } else { 474 if (bkpinfo->media_device == NULL) { 475 bkpinfo->media_device = find_cdrom_device(); 476 } 468 if (bkpinfo->media_device == NULL) { 469 bkpinfo->media_device = find_optical_device(); 477 470 } 478 471 … … 481 474 } 482 475 483 if ((bkpinfo->media_device == NULL) || (res = mount_ CDROM_here(bkpinfo->media_device,mountpoint))) {476 if ((bkpinfo->media_device == NULL) || (res = mount_media(mountpoint))) { 484 477 mr_free(bkpinfo->media_device); 485 478 if ((bkpinfo->media_device = mr_popup_and_get_string("CD-ROM device", "Please enter your CD-ROM's /dev device", "/dev/cdrom")) == NULL) { 486 res = 1;479 res = TRUE; 487 480 } else { 488 res = mount_ CDROM_here(bkpinfo->media_device,mountpoint);481 res = mount_media(mountpoint); 489 482 } 490 483 } … … 496 489 return (res); 497 490 } 498 499 500 /** 501 * Attempt to locate a CD-ROM device's /dev entry. 502 * Several different methods may be used to find the device, including 503 * calling @c cdrecord, searching @c dmesg, and trial-and-error. 504 * @param output Where to put the located /dev entry. 505 * @param try_to_mount Whether to mount the CD as part of the test; if mount 506 * fails then return failure. 507 * @return 0 for success, nonzero for failure. 508 */ 509 int find_cdrom_device(char *output, bool try_to_mount) 510 { 511 /*@ pointers **************************************************** */ 512 FILE *fin; 513 char *p; 514 char *q; 515 char *r; 516 int retval = 0; 517 518 /*@ bool's ****************************************************** */ 519 bool found_it = FALSE; 520 521 /*@ buffers ***************************************************** */ 522 char *tmp = NULL; 491 /* 492 * This function tries to find a USB media device 493 * and return it's device file to the caller that needs to free it 494 */ 495 char *find_usb_device(void) 496 { 497 char *dev = NULL; 523 498 char *tmp1 = NULL; 524 char *cdr_exe = NULL;525 char *phrase_one;526 char *phrase_two = NULL;527 499 char *command = NULL; 528 #ifndef __FreeBSD__ 529 char *dvd_last_resort = NULL; 530 #endif 531 char *mountpoint = NULL; 532 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 533 534 assert_string_is_neither_NULL_nor_zerolength(output); 535 output[0] = '\0'; 536 537 if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) { 538 strcpy(output, g_cdrom_drive_is_here); 539 log_msg(3, "Been there, done that. Returning %s", output); 540 return(0); 541 } 542 if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) { 543 strcpy(output, the_last_place_i_found_it); 544 log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output); 545 return(0); 546 } 547 548 if ((cdr_exe = find_home_of_exe("cdrecord")) == NULL) { 549 if ((cdr_exe = find_home_of_exe("wodim")) == NULL) { 550 cdr_exe = find_home_of_exe("dvdrecord"); 551 } 552 } 553 554 if (cdr_exe == NULL) { 555 strcpy(output, "/dev/cdrom"); 556 log_msg(4, "Can't find cdrecord; assuming %s", output); 557 if (!does_device_exist(output)) { 558 log_msg(4, "That didn't work. Sorry."); 559 return(1); 560 } else { 561 return(0); 562 } 563 } 564 565 mr_asprintf(command, "%s -scanbus 2> /dev/null", cdr_exe); 566 fin = popen(command, "r"); 567 if (!fin) { 568 log_msg(4, "command=%s", command); 569 log_OS_error("Cannot popen command"); 570 mr_free(cdr_exe); 500 501 log_to_screen("I am looking for your USB key. Please wait."); 502 503 if (bkpinfo->media_device != NULL) { 504 log_msg(3, "Been there, done that. Returning %s", bkpinfo->media_device); 505 return (bkpinfo->media_device); 506 } 507 508 tmp1 = find_home_of_exe("lsscsi"); 509 if (tmp1 != NULL) { 510 mr_asprintf(command, "%s | grep ' disk' | grep USB | awk '{print $NF}' | head -1", tmp1); 511 dev = call_program_and_get_last_line_of_output(command); 571 512 mr_free(command); 572 return(1); 573 } 574 mr_free(command); 575 576 /*@ intialize *************************************************** */ 577 malloc_string(tmp); 578 malloc_string(phrase_one); 579 580 phrase_one[0] = '\0'; 581 tmp[0] = '\0'; 582 583 /*@ end vars **************************************************** */ 584 585 586 for (tmp1 = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (tmp1 != NULL); 587 tmp1 = fgets(tmp, MAX_STR_LEN, fin)) { 588 p = strchr(tmp, '\''); 589 if (p) { 590 q = strchr(++p, '\''); 591 if (q) { 592 for (r = q; *(r - 1) == ' '; r--); 593 *r = '\0'; 594 strcpy(phrase_one, p); 595 p = strchr(++q, '\''); 596 if (p) { 597 q = strchr(++p, '\''); 598 if (q) { 599 while (*(q - 1) == ' ') { 600 q--; 601 } 602 *q = '\0'; 603 mr_asprintf(phrase_two, "%s", p); 604 } 605 } 606 } 607 } 608 } 609 paranoid_pclose(fin); 610 611 #ifndef __FreeBSD__ 612 if (!phrase_two || strlen(phrase_two) == 0) { 613 log_msg(4, "Not running phase two. String is empty."); 513 } 514 mr_free(tmp1); 515 516 if ((dev == NULL) || !does_file_exist(dev)) { 517 tmp1 = find_home_of_exe("lsblk"); 518 if (tmp1 != NULL) { 519 mr_asprintf(command, "%s --noheadings --raw --output rm,tran,type,path --sort path | awk '/^1 usb disk/ {d=$4} END {print d}'", tmp1); 520 dev = call_program_and_get_last_line_of_output(command); 521 mr_free(command); 522 } 523 mr_free(tmp1); 524 log_it("Unable to find a tape device on this system"); 525 } 526 if (dev != NULL) { 527 log_it("find_usb_device found %s manually", dev); 528 } 529 530 if ((dev != NULL) && does_file_exist(dev)) { 531 log_it("find_usb_device returns %s", dev); 614 532 } else { 615 mr_asprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 616 fin = popen(command, "r"); 617 mr_free(command); 618 619 if (!fin) { 620 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); 621 } else { 622 for (tmp1 = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (tmp1 != NULL); 623 tmp1 = fgets(tmp, MAX_STR_LEN, fin)) { 624 log_msg(5, "--> '%s'", tmp); 625 if (tmp[0] != ' ' && tmp[1] != ' ') { 626 p = strchr(tmp, ':'); 627 if (p) { 628 *p = '\0'; 629 if (strstr(tmp, "DVD")) { 630 mr_free(dvd_last_resort); 631 mr_asprintf(dvd_last_resort, "/dev/%s", tmp); 632 log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp); 633 } else { 634 sprintf(output, "/dev/%s", tmp); 635 found_it = TRUE; 636 } 637 } 638 } 639 } 640 paranoid_pclose(fin); 641 } 642 } 643 644 #endif 645 #ifdef __FreeBSD__ 646 if (!found_it) { 647 log_msg(4, "OK, approach 2"); 648 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) { 649 if (! 650 (found_it = 651 set_dev_to_this_if_rx_OK(output, "/dev/cdrom1"))) { 652 if (! 653 (found_it = 654 set_dev_to_this_if_rx_OK(output, "/dev/dvd"))) { 655 if (! 656 (found_it = 657 set_dev_to_this_if_rx_OK(output, "/dev/acd0"))) { 658 if (! 659 (found_it = 660 set_dev_to_this_if_rx_OK(output, 661 "/dev/cd01"))) { 662 if (! 663 (found_it = 664 set_dev_to_this_if_rx_OK(output, 665 "/dev/acd1"))) { 666 if (! 667 (found_it = 668 set_dev_to_this_if_rx_OK(output, 669 "/dev/cd1"))) 670 { 671 retval = 1; 672 goto end_of_find_cdrom_device; 673 } 674 } 675 } 676 } 677 } 678 } 679 } 680 } 681 #else 682 if (!found_it && strlen(dvd_last_resort) > 0) { 683 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort); 684 strcpy(output, dvd_last_resort); 685 found_it = TRUE; 686 } 687 if (found_it) { 688 sprintf(tmp, "grep \"%s=ide-scsi\" "CMDLINE" &> /dev/null", strrchr(output, '/') + 1); 689 if (system(tmp) == 0) { 690 log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output); 691 found_it = FALSE; 692 output[0] = '\0'; 693 } 694 } 695 696 if (found_it) { 697 log_msg(4, "(find_cdrom_device) --> '%s'", output); 698 if (!does_device_exist(output)) { 699 found_it = FALSE; 700 log_msg(4, "OK, I was wrong, I haven't found it... yet."); 701 } 702 } 703 704 if (!found_it) { 705 log_msg(4, "OK, approach 2"); 706 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0"))) { 707 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0"))) { 708 if (! 709 (found_it = 710 set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) { 711 if (! 712 (found_it = 713 set_dev_to_this_if_rx_OK(output, 714 "/dev/cdrom0"))) { 715 if (! 716 (found_it = 717 set_dev_to_this_if_rx_OK(output, 718 "/dev/cdrom1"))) { 719 if (! 720 (found_it = 721 set_dev_to_this_if_rx_OK(output, 722 "/dev/sr1"))) { 723 if (! 724 (found_it = 725 set_dev_to_this_if_rx_OK(output, 726 "/dev/dvd"))) 727 { 728 if (! 729 (found_it = 730 set_dev_to_this_if_rx_OK(output, 731 g_cd_drive_is_here))) 732 { 733 retval = 1; 734 goto end_of_find_cdrom_device; 735 } 736 } 737 } 738 } 739 } 740 } 741 } 742 } 743 } 744 #endif 745 746 mr_asprintf(mountpoint, "%s/cd.mnt", bkpinfo->tmpdir); 747 make_hole_for_dir(mountpoint); 748 749 if (found_it && try_to_mount) { 750 if (mount_CDROM_here(output, mountpoint)) { 751 log_msg(4, "[Cardigans] I've changed my mind"); 752 found_it = FALSE; 753 } else { 754 sprintf(tmp, "%s/archives", mountpoint); 755 if (!does_file_exist(tmp)) { 756 log_msg(4, "[Cardigans] I'll take it back"); 757 found_it = FALSE; 758 } else { 759 mr_asprintf(command, "umount %s", output); 760 paranoid_system(command); 761 mr_free(command); 762 763 log_msg(4, "I'm confident the Mondo CD is in %s", output); 764 } 765 } 766 } 767 unlink(mountpoint); 768 mr_free(mountpoint); 769 770 if (found_it) { 771 if (!does_file_exist(output)) { 772 log_msg(3, "I still haven't found it."); 773 return (1); 774 } 775 log_msg(3, "(find_cdrom_device) --> '%s'", output); 776 strcpy(the_last_place_i_found_it, output); 777 strcpy(g_cdrom_drive_is_here, output); 778 retval = 0; 779 goto end_of_find_cdrom_device; 780 } 781 782 mr_asprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cd_drive_is_here); 783 784 log_msg(1, "command=%s", command); 785 tmp1 = call_program_and_get_last_line_of_output(command); 786 mr_free(command); 787 788 if (strlen(tmp1) > 0) { 789 strcpy(output, tmp1); 790 log_msg(4, "Finally found it at %s", output); 791 retval = 0; 792 } else { 793 log_msg(4, "Still couldn't find it."); 794 retval = 1; 795 } 796 mr_free(tmp1); 797 798 end_of_find_cdrom_device: 799 mr_free(cdr_exe); 800 mr_free(phrase_two); 801 mr_free(dvd_last_resort); 802 803 paranoid_free(tmp); 804 paranoid_free(phrase_one); 805 return (retval); 806 } 533 mr_free(dev); 534 log_it("find_usb_device found no USB key on your system returning NULL"); 535 } 536 return(dev); 537 } 538 807 539 808 540 /* … … 810 542 * and return it's device file to the caller that needs to free it 811 543 */ 812 char *find_ dvd_device(void)544 char *find_optical_device(void) 813 545 { 814 546 char *dev = NULL; … … 828 560 829 561 if ((dev != NULL) && does_file_exist(dev)) { 830 log_msg(2, "find_ dvd_device found %s automatically", dev);562 log_msg(2, "find_optical_device found %s automatically", dev); 831 563 } else { 832 564 mr_free(dev); … … 845 577 mr_asprintf(dev, "%s", ALT_CDROM); 846 578 if (!does_file_exist(dev)) { 847 log_it("Unable to find a tape device on this system"); 579 mr_asprintf(dev, "%s", "/dev/cdrom"); 580 if (!does_file_exist(dev)) { 581 mr_asprintf(dev, "%s", "/dev/dvd"); 582 if (!does_file_exist(dev)) { 583 log_it("Unable to find a tape device on this system"); 848 584 } 849 585 } 850 586 } 851 587 if (dev != NULL) { 852 log_it("find_ dvd_device found %s manually", dev);588 log_it("find_optical_device found %s manually", dev); 853 589 } 854 590 } 855 591 856 592 if ((dev != NULL) && does_file_exist(dev)) { 857 log_it("find_ dvd_device returns %s", dev);593 log_it("find_optical_device returns %s", dev); 858 594 } else { 859 595 mr_free(dev); 860 log_it("find_ dvd_device found no optical burner on your system returning NULL");596 log_it("find_optical_device found no optical burner on your system returning NULL"); 861 597 } 862 598 return(dev); 863 599 } 600 601 /* Generic fund to find a media 602 * Return a dynamically allocted string that caller needs to free 603 * @media_type is the type of media to look for 604 */ 605 606 char *find_device(t_bkptype media_type) { 607 608 if (media_type == usb) { 609 return(find_usb_device()); 610 } else if (media_type == tape) { 611 return(find_tape_device()); 612 } else if ((media_type == dvd) || (media_type == cdr)) { 613 return(find_optical_device()); 614 } else { 615 return(NULL); 616 } 617 } 618 619 864 620 865 621 … … 1215 971 1216 972 /** 1217 * Mount the CD-ROM at @p mountpoint.1218 * @param device The device (or file if g_ISO_restore_mode) to mount.1219 * @param mountpoint The place to mount it.1220 * @return 0 for success, nonzero for failure.1221 */1222 int mount_CDROM_here(char *device, const char *mountpoint)1223 {1224 /*@ buffer ****************************************************** */1225 char *command = NULL;1226 int retval;1227 #ifdef __FreeBSD__1228 char *dev = NULL;1229 #else1230 char *options = NULL;1231 #endif1232 1233 assert_string_is_neither_NULL_nor_zerolength(device);1234 assert_string_is_neither_NULL_nor_zerolength(mountpoint);1235 1236 make_hole_for_dir(mountpoint);1237 1238 if (isdigit(device[0])) {1239 find_cdrom_device(device, FALSE);1240 }1241 #ifndef __FreeBSD__1242 mr_asprintf(options, "ro");1243 #endif1244 1245 if (g_ISO_restore_mode) {1246 1247 #ifdef __FreeBSD__1248 mr_asprintf(dev, "%s", make_vn(device));1249 if (!dev) {1250 mr_asprintf(command, "Unable to mount ISO (make_vn(%s) failed)", device);1251 fatal_error(command);1252 }1253 strcpy(device, dev);1254 paranoid_free(dev);1255 #else1256 mr_strcat(options, ",loop");1257 #endif1258 1259 }1260 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint);1261 /*@ end vars *************************************************** */1262 1263 #ifdef __FreeBSD__1264 mr_asprintf(command, "mount_cd9660 -r %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE);1265 1266 #else1267 mr_asprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s", device, options, mountpoint, MONDO_LOGFILE);1268 paranoid_free(options);1269 #endif1270 1271 log_msg(4, command);1272 if (strncmp(device, "/dev/", 5) == 0) {1273 retract_CD_tray_and_defeat_autorun();1274 }1275 retval = system(command);1276 log_msg(1, "system(%s) returned %d", command, retval);1277 mr_free(command);1278 1279 return (retval);1280 }1281 1282 1283 /**1284 973 * Mount the CD-ROM or USB device at /mnt/cdrom. 1285 974 * @param bkpinfo The backup information structure. Fields used: … … 1288 977 * - @c bkpinfo->isodir 1289 978 * - @c bkpinfo->media_device 1290 * @return 0 for success, nonzerofor failure.979 * @return TRUE for success, FALSE for failure. 1291 980 */ 1292 int mount_media() 1293 { 1294 char *mount_cmd = NULL; 1295 char *mountdir = NULL; 1296 int i, res; 981 bool mount_media(const char *mountpoint) { 982 983 char *mount_cmd = NULL; 984 char *mountdir = NULL; 985 char *tmp = NULL; 986 int i = 0, res = 0; 1297 987 #ifdef __FreeBSD__ 1298 988 char mdd[32]; 1299 989 char *mddev = mdd; 990 char *dev; 1300 991 #endif 1301 992 1302 993 if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) { 1303 994 log_msg(8, "Tape/udev. Therefore, no need to mount a media."); 1304 return 0; 1305 } 1306 1307 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) { 995 return(TRUE); 996 } 997 998 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 999 1000 mr_asprintf(tmp, "mount | grep -F %s", mountpoint); 1001 if (!run_program_and_log_output(tmp, FALSE)) { 1308 1002 log_msg(2, "mount_media() - media already mounted. Fair enough."); 1309 return (0); 1310 } 1003 mr_free(tmp); 1004 return (TRUE); 1005 } 1006 mr_free(tmp); 1007 1008 make_hole_for_dir(mountpoint); 1311 1009 1312 1010 if (bkpinfo->backup_media_type == netfs) { … … 1328 1026 mr_free(mount_cmd); 1329 1027 1330 mr_asprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);1028 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, mountpoint); 1331 1029 #else 1332 1030 if (bkpinfo->netfs_remote_dir != NULL) { 1333 1031 // NETFS 1334 mr_asprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);1032 mr_asprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number, mountpoint); 1335 1033 } else { 1336 1034 // ISO 1337 mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);1035 mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, mountpoint); 1338 1036 } 1339 1037 #endif … … 1350 1048 mr_free(mount_cmd); 1351 1049 1352 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);1050 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, mountpoint); 1353 1051 #else 1354 mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);1052 mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, mountpoint); 1355 1053 #endif 1356 1054 mr_free(mountdir); 1357 1055 } else if (bkpinfo->backup_media_type == usb) { 1358 mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM); 1359 } else if (strstr(bkpinfo->media_device, "/dev/")) { 1360 #ifdef __FreeBSD__ 1361 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 1362 #else 1363 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 1364 #endif 1365 } else { 1056 mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, mountpoint); 1057 } else { // optical 1366 1058 if (bkpinfo->disaster_recovery 1367 1059 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 1368 1060 mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE")); 1369 1061 } else { 1370 find_cdrom_device(bkpinfo->media_device, TRUE); 1062 if (bkpinfo->media_device == NULL) { 1063 bkpinfo->media_device = find_optical_device(); 1064 } 1371 1065 } 1372 1066 1373 1067 #ifdef __FreeBSD__ 1374 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 1068 if (g_ISO_restore_mode) { 1069 mr_asprintf(dev, "%s", make_vn(bkpinfo->media_device)); 1070 if (!dev) { 1071 mr_asprintf(command, "Unable to mount ISO (make_vn(%s) failed)", bkpinfo->media_device); 1072 fatal_error(command); 1073 } 1074 mr_free(bkpinfo->media_device); 1075 bkpinfo->media_device = dev 1076 } 1077 1078 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s 2>> %s", bkpinfo->media_device, mountpoint, MONDO_LOGFILE); 1375 1079 #else 1376 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 1377 #endif 1378 } 1379 1380 log_msg(2, "(mount_media) --- command = %s", mount_cmd); 1080 mr_asprintf(mount_cmd, "mount %s -o loop,ro -t iso9660 %s 2>> %s", bkpinfo->media_device, mountpoint, MONDO_LOGFILE); 1081 #endif 1082 log_msg(2, "(mount_media) --- command = %s", mount_cmd); 1083 // usefull ?? 1084 if (strncmp(device, "/dev/", 5) == 0) { 1085 retract_CD_tray_and_defeat_autorun(); 1086 } 1087 } 1088 1381 1089 for (i = 0; i < 2; i++) { 1382 1090 res = run_program_and_log_output(mount_cmd, FALSE); … … 1393 1101 if (res) { 1394 1102 log_msg(2, "Failed, despite %d attempts", i); 1103 return(FALSE); 1395 1104 } else { 1396 1105 log_msg(2, "Mounted media drive OK"); 1397 }1398 return (res);1106 return(TRUE); 1107 } 1399 1108 } 1400 1109 /************************************************************************** 1401 *END_MOUNT_ CDROM*1110 *END_MOUNT_MEDIA * 1402 1111 **************************************************************************/ 1403 1112 … … 2157 1866 finish(1); 2158 1867 } 1868 log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 1869 2159 1870 /* Why asking to remove the media with tape ? 2160 1871 if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) { … … 2163 1874 */ 2164 1875 if (archiving_to_media) { 1876 // TODO: Should be common ? 2165 1877 setup_tmpdir(NULL); 2166 1878 /* … … 2182 1894 setup_scratchdir(tmp); 2183 1895 mr_free(tmp); 2184 } 2185 log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 2186 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 2187 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 2188 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 1896 1897 if ((compression_type = which_compression_type()) == NULL) { 1898 log_to_screen("User has chosen not to backup the machine"); 1899 finish(1); 1900 } 1901 1902 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 1903 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 1904 log_to_screen("User has chosen not to backup the machine"); 1905 finish(1); 1906 } 1907 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 1908 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 1909 } 2189 1910 mvaddstr_and_log_it(2, 0, " "); 2190 1911 … … 2198 1919 bkpinfo->please_dont_eject = TRUE; 2199 1920 } 1921 mds = media_descriptor_string(bkpinfo->backup_media_type); 1922 if (bkpinfo->backup_media_type != usb) { 1923 if (ask_me_yes_or_no("Is your computer a laptop type (manual insert of MondoRescue media)?")) { 1924 bkpinfo->manual_cd_tray = TRUE; 1925 } 1926 } 1927 1928 if (bkpinfo->media_device == NULL) { 1929 bkpinfo->media_device = find_device(bkpinfo->backup_media_type); 1930 if (bkpinfo->media_device != NULL) { 1931 log_msg(1, "MondoRescue device found automatically for your %s is %s", mds, bkpinfo->media_device); 1932 } else { 1933 log_msg(1, "No MondoRescue device found yet for your %s", mds); 1934 } 1935 } 1936 2200 1937 if (archiving_to_media) { 2201 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {2202 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) {2203 bkpinfo->manual_cd_tray = TRUE;2204 }2205 }2206 if ((compression_type = which_compression_type()) == NULL) {2207 log_to_screen("User has chosen not to backup the machine");2208 finish(1);2209 }2210 2211 if ((bkpinfo->compression_level = which_compression_level()) == -1) {2212 log_to_screen("User has chosen not to backup the machine");2213 finish(1);2214 }2215 mds = media_descriptor_string(bkpinfo->backup_media_type);2216 mr_asprintf(comment, "What speed is your %s (re)writer?", mds);2217 1938 if (bkpinfo->backup_media_type == dvd) { 2218 bkpinfo->media_device = find_dvd_device();2219 if (bkpinfo->media_device == NULL) {2220 log_msg(1, "No backup device found for your DVD");2221 }2222 1939 strcpy(tmp1, "1"); 2223 1940 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2224 1941 log_msg(1, "Setting to DVD defaults"); 2225 1942 } else { 2226 mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_CDROM);2227 1943 strcpy(tmp1, "4"); 2228 1944 mr_asprintf(sz_size, "%d", 650); 2229 1945 log_msg(1, "Setting to CD defaults"); 2230 1946 } 1947 1948 mr_asprintf(comment, "What speed is your %s writer?", mds); 2231 1949 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) { 2232 1950 if (!popup_and_get_string("Speed", comment, tmp1, 4)) { … … 2241 1959 strcpy(tmp1, sz_size); 2242 1960 mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds); 2243 mr_free(mds);2244 1961 if (!popup_and_get_string("Size", comment, tmp1, 5)) { 2245 1962 log_to_screen("User has chosen not to backup the machine"); … … 2256 1973 /* No break because we continue even for usb */ 2257 1974 case cdstream: 2258 mds = media_descriptor_string(bkpinfo->backup_media_type); 2259 2260 if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) { 2261 mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); 2262 log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device); 2263 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) || bkpinfo->backup_media_type == dvd) { 2264 if (bkpinfo->media_device == NULL) { 2265 mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); 2266 } // just for the heck of it :) 2267 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device); 2268 if (bkpinfo->backup_media_type == dvd || find_cdrom_device(bkpinfo->media_device, FALSE)) { 2269 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device); 2270 mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds); 2271 tmp2 = mr_popup_and_get_string("Device?", comment, bkpinfo->media_device); 2272 if (!tmp2) { 2273 log_to_screen("User has chosen not to backup the machine"); 2274 finish(1); 2275 } else { 2276 mr_free(bkpinfo->media_device); 2277 bkpinfo->media_device = tmp2; 2278 } 2279 } 2280 log_msg(2, "%s device found at %s", mds, bkpinfo->media_device); 2281 } else { 2282 if ((find_cdrom_device(bkpinfo->media_device)) && (bkpinfo->backup_media_type != usb)) { 1975 1976 // If media_device not found ask 1977 if (bkpinfo->media_device == NULL) { 1978 mr_asprintf(comment, "Please specify your Mondorescue %s media /dev entry", mds); 1979 tmp2 = mr_popup_and_get_string("/dev entry?", comment, bkpinfo->media_device); 1980 if (!tmp2) { 1981 log_to_screen("User has chosen not to backup the machine"); 1982 finish(1); 1983 } else { 2283 1984 mr_free(bkpinfo->media_device); 2284 } 2285 if (bkpinfo->media_device != NULL) { 2286 if (bkpinfo->backup_media_type == usb) { 2287 mr_asprintf(tmp, "I think your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device); 2288 } else { 2289 mr_asprintf(tmp, "I think I've found your %s burner at SCSI node %s. Is this correct? (Say no if you have an IDE burner and you are running a 2.6 kernel. You will then be prompted for further details.)", mds, bkpinfo->media_device); 2290 } 2291 if (!ask_me_yes_or_no(tmp)) { 2292 mr_free(bkpinfo->media_device); 2293 } 2294 mr_free(tmp); 2295 } 2296 if (bkpinfo->media_device != NULL) { 2297 if (bkpinfo->backup_media_type == usb) { 2298 tmp2 = mr_popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", bkpinfo->media_device); 2299 } else { 2300 if (g_kernel_version < 2.6) { 2301 tmp2 = mr_popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device); 2302 } else { 2303 tmp2 = mr_popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device); 2304 } 2305 } 2306 if (tmp2 == NULL) { 2307 log_to_screen("User has chosen not to backup the machine"); 2308 finish(1); 2309 } else { 2310 mr_free(bkpinfo->media_device); 2311 bkpinfo->media_device = tmp2; 2312 } 1985 bkpinfo->media_device = tmp2; 1986 } 1987 } 1988 log_msg(2, "%s device found at %s", mds, bkpinfo->media_device); 1989 mr_asprintf(tmp, "MondoRescue thinks your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device); 1990 if (!ask_me_yes_or_no(tmp)) { 1991 mr_free(bkpinfo->media_device); 1992 } 1993 mr_free(tmp); 1994 1995 if (bkpinfo->media_device == NULL) { 1996 mr_asprintf(tmp, "Please then specify your Mondorescue %s media /dev entry", mds); 1997 tmp2 = mr_popup_and_get_string("/dev entry?", tmp, bkpinfo->media_device); 1998 mr_free(tmp); 1999 if (tmp2 == NULL) { 2000 log_to_screen("User has chosen not to backup the machine"); 2001 finish(1); 2002 } else { 2003 mr_free(bkpinfo->media_device); 2004 bkpinfo->media_device = tmp2; 2313 2005 } 2314 2006 } … … 2338 2030 } 2339 2031 if (bkpinfo->media_device != NULL) { 2340 mr_asprintf(tmp, " I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);2032 mr_asprintf(tmp, "Mondorescue thinks your tape streamer at %s; is that correct?", bkpinfo->media_device); 2341 2033 if (!ask_me_yes_or_no(tmp)) { 2342 2034 mr_free(bkpinfo->media_device); … … 2381 2073 log_msg(4, "media_size = %ld", bkpinfo->media_size); 2382 2074 2383 bkpinfo->use_obdr = ask_me_yes_or_no("Do you want to activate OBDR support for your tapes ?");2384 if (bkpinfo->use_obdr) {2385 log_msg(4, "obdr mode = TRUE");2386 } else {2387 log_msg(4, "obdr mode = FALSE");2388 }2389 2075 if (archiving_to_media) { 2390 if ((compression_type = which_compression_type()) == NULL) { 2391 log_to_screen("User has chosen not to backup the machine"); 2392 finish(1); 2393 } 2394 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2395 log_to_screen("User has chosen not to backup the machine"); 2396 finish(1); 2076 bkpinfo->use_obdr = ask_me_yes_or_no("Do you want to activate OBDR support for your tapes ?"); 2077 if (bkpinfo->use_obdr) { 2078 log_msg(4, "obdr mode = TRUE"); 2079 } else { 2080 log_msg(4, "obdr mode = FALSE"); 2397 2081 } 2398 2082 } 2399 2083 break; 2400 2401 2402 2084 2403 2085 case netfs: … … 2427 2109 // surrounding spaces and trailing '/' for this 2428 2110 bkpinfo->netfs_mount = mr_strip_spaces(p); 2429 if (!bkpinfo->restore_data) {2430 if ((compression_type = which_compression_type()) == NULL) {2431 log_to_screen("User has chosen not to backup the machine");2432 finish(1);2433 }2434 2435 if ((bkpinfo->compression_level = which_compression_level()) == -1) {2436 log_to_screen("User has chosen not to backup the machine");2437 finish(1);2438 }2439 }2440 2111 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/') 2441 2112 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0'; … … 2597 2268 } 2598 2269 if (archiving_to_media) { 2599 if ((compression_type = which_compression_type()) == NULL) {2600 log_to_screen("User has chosen not to backup the machine");2601 finish(1);2602 }2603 if ((bkpinfo->compression_level = which_compression_level()) == -1) {2604 log_to_screen("User has chosen not to backup the machine");2605 finish(1);2606 }2607 2270 sprintf(tmp1, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2608 2271 if (!popup_and_get_string("ISO size.", "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s (700) or DVD's (4480) you plan to backup to.", tmp1, 16)) { … … 2791 2454 mr_free(bkpinfo->zip_suffix); 2792 2455 } 2456 mr_free(compression_type); 2457 2793 2458 #if __FreeBSD__ == 5 2794 2459 mr_asprintf(bkpinfo->kernel_path, "%s", "/boot/kernel/kernel"); … … 2816 2481 bkpinfo->restore_data = TRUE; // probably... 2817 2482 } 2818 mr_free(compression_type);2819 2483 2820 2484 if (bkpinfo->backup_media_type == iso … … 2977 2641 * (and remain mounted after this function returns). 2978 2642 */ 2979 int what_number_cd_is_this( )2980 { 2643 int what_number_cd_is_this(void) { 2644 2981 2645 int cd_number = -1; 2982 2646 char *mountdev = NULL; … … 2991 2655 cd_number = atoi(last_line_of_file(mountdev)); 2992 2656 mr_free(mountdev); 2993 2994 2657 return (cd_number); 2995 2658 } 2996 2659 2997 if (bkpinfo->media_device == NULL) { 2998 log_it("ERROR: bkpinfo->media_device shoulnd't be empty here\n"); 2999 return(0); 3000 } 3001 mr_asprintf(mountdev, "%s", bkpinfo->media_device); 3002 if (!mountdev[0]) { 3003 log_it("(what_number_cd_is_this) Warning - media_device unknown. Finding out..."); 3004 find_cdrom_device(bkpinfo->media_device, FALSE); 3005 } 3006 if (!is_this_device_mounted(MNT_CDROM)) { 3007 if (bkpinfo->backup_media_type == usb) { 3008 mount_USB_here(mountdev, MNT_CDROM); 3009 } else { 3010 mount_CDROM_here(mountdev, MNT_CDROM); 3011 } 3012 } 3013 mr_free(mountdev); 2660 if ((bkpinfo->media_device == NULL) || !does_file_exist(bkpinfo->media_device)) { 2661 log_it("ERROR: bkpinfo->media_device shoulnd't be unaccessible here\n"); 2662 /* trying again ! */ 2663 bkpinfo->media_device = find_optical_device(); 2664 } 2665 if ((bkpinfo->media_device == NULL) || !does_file_exist(bkpinfo->media_device)) { 2666 fatal_error("ERROR: bkpinfo->media_device shoulnd't really be unaccessible here\n"); 2667 } 2668 if (!is_this_device_mounted(bkpinfo->media_device, MNT_CDROM)) { 2669 mount_media(MNT_CDROM); 2670 } 3014 2671 3015 2672 cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER")); 3016 return 2673 return(cd_number); 3017 2674 } 3018 2675 -
branches/3.3/mondo/src/common/mondostructures.h
r3874 r3875 174 174 cdr, ///< Back up to recordable CDs (do not erase them). 175 175 dvd, ///< Back up to DVD+R[W] or DVD-R[W] disks. 176 // To be removed 176 177 cdstream, ///< Back up to recordable CDs but treat them like a tape streamer. 177 178 netfs, ///< Back up to an NETFS mount on the local subnet. -
branches/3.3/mondo/src/mondoarchive/mondoarchive.c
r3874 r3875 281 281 g_loglevel = 10; 282 282 setup_newt_stuff(); 283 if ((tmp = find_ cdrom_device()) == NULL) {284 printf("Failed to find CDR-RWdrive\n");285 } else { 286 printf(" CD-RWis at %s\n", tmp);283 if ((tmp = find_optical_device()) == NULL) { 284 printf("Failed to find optical drive\n"); 285 } else { 286 printf("Optical drive is at %s\n", tmp); 287 287 } 288 288 mr_free(tmp); … … 293 293 g_loglevel = 10; 294 294 setup_newt_stuff(); 295 if (tmp = find_ dvd_device()) {295 if (tmp = find_optical_device()) { 296 296 printf("Failed to find DVD drive\n"); 297 297 } else { -
branches/3.3/mondo/src/mondorestore/mondo-rstr-compare.c
r3866 r3875 655 655 mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE")); 656 656 } else { 657 find_cdrom_device(bkpinfo->media_device, FALSE);657 bkpinfo->media_device = find_optical_device(); 658 658 } 659 659 res = verify_tape_backups();
Note:
See TracChangeset
for help on using the changeset viewer.