Changeset 2682 in MondoRescue


Ignore:
Timestamp:
Sep 10, 2010, 12:13:40 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • mount-media function is now placed in libmondo-devices.c as used by more programs.
  • Avoids calling mount_media when it's not mandatory (change the way mondorestore was working up to now but could solve some bugs reported)
Location:
branches/2.2.9/mondo/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/libmondo-devices.c

    r2636 r2682  
    13431343
    13441344
     1345/**
     1346* Mount the CD-ROM or USB device at /mnt/cdrom.
     1347* @param bkpinfo The backup information structure. Fields used:
     1348* - @c bkpinfo->backup_media_type
     1349* - @c bkpinfo->disaster_recovery
     1350* - @c bkpinfo->isodir
     1351* - @c bkpinfo->media_device
     1352* @return 0 for success, nonzero for failure.
     1353*/
     1354int mount_media()
     1355{
     1356char *mount_cmd;
     1357int i, res;
     1358#ifdef __FreeBSD__
     1359char mdd[32];
     1360char *mddev = mdd;
     1361#endif
     1362
     1363malloc_string(mount_cmd);
     1364assert(bkpinfo != NULL);
     1365
     1366    if (bkpinfo->backup_media_type == tape
     1367        || bkpinfo->backup_media_type == udev) {
     1368        log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
     1369        paranoid_free(mount_cmd);
     1370        return 0;
     1371    }
     1372
     1373    if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
     1374        log_msg(2, "mount_media() - media already mounted. Fair enough.");
     1375        paranoid_free(mount_cmd);
     1376        return (0);
     1377    }
     1378
     1379    if (bkpinfo->backup_media_type == netfs) {
     1380        log_msg(2, "Mounting for Network thingy");
     1381        log_msg(2, "isodir = %s", bkpinfo->isodir);
     1382        if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
     1383            && am_I_in_disaster_recovery_mode()) {
     1384            strcpy(bkpinfo->isodir, "/tmp/isodir");
     1385            log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
     1386        }
     1387#ifdef __FreeBSD__
     1388        sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
     1389            bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
     1390        mddev = make_vn(mount_cmd);
     1391        sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
     1392#else
     1393        sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
     1394            bkpinfo->isodir, bkpinfo->netfs_remote_dir,
     1395            bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     1396#endif
     1397
     1398    } else if (bkpinfo->backup_media_type == iso) {
     1399#ifdef __FreeBSD__
     1400        sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
     1401            bkpinfo->prefix, g_current_media_number);
     1402        mddev = make_vn(mount_cmd);
     1403        sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
     1404#else
     1405        sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
     1406            bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     1407#endif
     1408    } else if (bkpinfo->backup_media_type == usb) {
     1409        sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
     1410    } else if (strstr(bkpinfo->media_device, "/dev/")) {
     1411#ifdef __FreeBSD__
     1412        sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     1413        MNT_CDROM);
     1414#else
     1415        sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     1416        bkpinfo->media_device, MNT_CDROM);
     1417#endif
     1418    } else {
     1419        if (bkpinfo->disaster_recovery
     1420            && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
     1421            strcpy(bkpinfo->media_device,
     1422                last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     1423        } else {
     1424            find_cdrom_device(bkpinfo->media_device, TRUE);
     1425        }
     1426
     1427#ifdef __FreeBSD__
     1428    sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     1429        MNT_CDROM);
     1430#else
     1431    sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     1432        bkpinfo->media_device, MNT_CDROM);
     1433#endif
     1434    }
     1435
     1436    log_msg(2, "(mount_media) --- command = %s", mount_cmd);
     1437    for (i = 0; i < 2; i++) {
     1438        res = run_program_and_log_output(mount_cmd, FALSE);
     1439        if (!res) {
     1440            break;
     1441        } else {
     1442            log_msg(2, "Failed to mount device.");
     1443            sleep(5);
     1444            run_program_and_log_output("sync", FALSE);
     1445        }
     1446    }
     1447
     1448    if (res) {
     1449        log_msg(2, "Failed, despite %d attempts", i);
     1450    } else {
     1451        log_msg(2, "Mounted media drive OK");
     1452    }
     1453    paranoid_free(mount_cmd);
     1454    return (res);
     1455}
     1456/**************************************************************************
     1457*END_MOUNT_CDROM                                                         *
     1458**************************************************************************/
    13451459
    13461460
     
    13871501    if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso
    13881502        || bkpinfo->backup_media_type == netfs) {
    1389         log_msg(3, "Remounting CD");
    13901503        g_ISO_restore_mode = TRUE;
    1391 // FIXME --- I'm tempted to do something about this...
    1392 // Why unmount and remount again and again?
    1393         if (is_this_device_mounted(MNT_CDROM)) {
    1394             run_program_and_log_output("umount " MNT_CDROM, 5);
    1395         }
    1396         sprintf(tmp, "mkdir -p %s/isodir &> /dev/null", bkpinfo->tmpdir);
    1397         (void)system(tmp);
    1398         sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir,
    1399                 bkpinfo->netfs_remote_dir, bkpinfo->prefix,
    1400                 cd_number_i_want);
    1401         if (!does_file_exist(tmp)) {
    1402             sprintf(tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir,
    1403                     bkpinfo->netfs_remote_dir, bkpinfo->prefix,
    1404                     cd_number_i_want);
    1405             if (does_file_exist(tmp)) {
    1406                 log_msg(1,
    1407                         "FIXME - hacking bkpinfo->isodir from '%s' to %s/isodir",
    1408                         bkpinfo->isodir, bkpinfo->tmpdir);
    1409                 sprintf(bkpinfo->isodir, "%s/isodir", bkpinfo->tmpdir);
    1410             }
    1411         }
    1412         log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM);
    1413         if (mount_CDROM_here(tmp, MNT_CDROM)) {
    1414             fatal_error("Mommy!");
    1415         }
    1416 //    g_current_media_number = cd_number_i_want;
    1417 //    return;
     1504        if (!is_this_device_mounted(MNT_CDROM)) {
     1505            log_msg(3, "Mounting media");
     1506            g_current_media_number = cd_number_i_want;
     1507            mount_media();
     1508        }
    14181509    }
    14191510    if ((res = what_number_cd_is_this()) != cd_number_i_want) {
     
    26552746    log_it("isodir = %s", bkpinfo->isodir);
    26562747    log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
    2657     log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
     2748    if (bkpinfo->netfs_proto) {
     2749        log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
     2750    }
    26582751    if (bkpinfo->netfs_user) {
    26592752        log_it("netfs_user = '%s'", bkpinfo->netfs_user);
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools-EXT.h

    r2049 r2682  
    88extern int iso_fiddly_bits(bool nuke_me_please);
    99extern void kill_petris(void);
    10 extern int mount_media();
    1110extern int mount_all_devices(struct mountlist_itself *, bool);
    1211extern void protect_against_braindead_sysadmins(void);
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools.c

    r2449 r2682  
    7474extern void kill_anything_like_this(char *str);
    7575extern int skip_obdr(void);
     76extern int mount_media();
    7677extern int set_tape_block_size_with_mt(long internal_tape_block_size);
    7778
     
    579580**************************************************************************/
    580581
    581 
    582 /**
    583 * Mount the CD-ROM or USB device at /mnt/cdrom.
    584 * @param bkpinfo The backup information structure. Fields used:
    585 * - @c bkpinfo->backup_media_type
    586 * - @c bkpinfo->disaster_recovery
    587 * - @c bkpinfo->isodir
    588 * - @c bkpinfo->media_device
    589 * @return 0 for success, nonzero for failure.
    590 */
    591 int mount_media()
    592 {
    593 char *mount_cmd;
    594 int i, res;
    595 #ifdef __FreeBSD__
    596 char mdd[32];
    597 char *mddev = mdd;
    598 #endif
    599 
    600 malloc_string(mount_cmd);
    601 assert(bkpinfo != NULL);
    602 
    603     if (bkpinfo->backup_media_type == tape
    604         || bkpinfo->backup_media_type == udev) {
    605         log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
    606         paranoid_free(mount_cmd);
    607         return 0;
    608     }
    609 
    610     if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
    611         log_msg(2, "mount_media() - media already mounted. Fair enough.");
    612         paranoid_free(mount_cmd);
    613         return (0);
    614     }
    615 
    616     if (bkpinfo->backup_media_type == netfs) {
    617         log_msg(2, "Mounting for Network thingy");
    618         log_msg(2, "isodir = %s", bkpinfo->isodir);
    619         if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
    620             && am_I_in_disaster_recovery_mode()) {
    621             strcpy(bkpinfo->isodir, "/tmp/isodir");
    622             log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
    623         }
    624 #ifdef __FreeBSD__
    625         sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
    626             bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
    627         mddev = make_vn(mount_cmd);
    628         sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
    629 #else
    630         sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
    631             bkpinfo->isodir, bkpinfo->netfs_remote_dir,
    632             bkpinfo->prefix, g_current_media_number, MNT_CDROM);
    633 #endif
    634 
    635     } else if (bkpinfo->backup_media_type == iso) {
    636 #ifdef __FreeBSD__
    637         sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
    638             bkpinfo->prefix, g_current_media_number);
    639         mddev = make_vn(mount_cmd);
    640         sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
    641 #else
    642         sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
    643             bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
    644 #endif
    645     } else if (bkpinfo->backup_media_type == usb) {
    646         sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
    647     } else if (strstr(bkpinfo->media_device, "/dev/")) {
    648 #ifdef __FreeBSD__
    649         sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    650         MNT_CDROM);
    651 #else
    652         sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
    653         bkpinfo->media_device, MNT_CDROM);
    654 #endif
    655     } else {
    656         if (bkpinfo->disaster_recovery
    657             && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    658             strcpy(bkpinfo->media_device,
    659                 last_line_of_file("/tmp/CDROM-LIVES-HERE"));
    660         } else {
    661             find_cdrom_device(bkpinfo->media_device, TRUE);
    662         }
    663 
    664 #ifdef __FreeBSD__
    665     sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    666         MNT_CDROM);
    667 #else
    668     sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
    669         bkpinfo->media_device, MNT_CDROM);
    670 #endif
    671     }
    672 
    673     log_msg(2, "(mount_media) --- command = %s", mount_cmd);
    674     for (i = 0; i < 2; i++) {
    675         res = run_program_and_log_output(mount_cmd, FALSE);
    676         if (!res) {
    677             break;
    678         } else {
    679             log_msg(2, "Failed to mount device.");
    680             sleep(5);
    681             run_program_and_log_output("sync", FALSE);
    682         }
    683     }
    684 
    685     if (res) {
    686         log_msg(2, "Failed, despite %d attempts", i);
    687     } else {
    688         log_msg(2, "Mounted media drive OK");
    689     }
    690     paranoid_free(mount_cmd);
    691     return (res);
    692 }
    693 /**************************************************************************
    694 *END_MOUNT_CDROM                                                         *
    695 **************************************************************************/
    696582
    697583
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools.h

    r1736 r2682  
    88int iso_fiddly_bits(bool nuke_me_please);
    99void kill_petris(void);
    10 int mount_media();
    1110int mount_device(char *, char *, char *, bool);
    1211int mount_all_devices(struct mountlist_itself *, bool);
  • branches/2.2.9/mondo/src/mondorestore/mondorestore.c

    r2394 r2682  
    5050extern int partition_everything(struct mountlist_itself *mountlist);
    5151extern int handle_incoming_parameters(int argc, char *argv[]);
     52extern int mount_media();
    5253
    5354/**
     
    27202721    }
    27212722    mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
     2723    mount_media();
    27222724    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    2723         mount_media();
    27242725        mvaddstr_and_log_it(g_currentY++, 0,
    27252726                            "Restoring OS and data from streaming media");
     
    27402741        mvaddstr_and_log_it(g_currentY++, 0,
    27412742                            "Restoring OS and data from CD/USB   ");
    2742         mount_media();
    27432743        resA = restore_all_tarballs_from_CD(filelist);
    27442744        resB = restore_all_biggiefiles_from_CD(filelist);
Note: See TracChangeset for help on using the changeset viewer.