Changeset 3870 in MondoRescue


Ignore:
Timestamp:
Mar 7, 2024, 6:05:50 PM (4 months ago)
Author:
Bruno Cornec
Message:

Rewrite find_tape_device ans start for other find_*dev functions

Location:
branches/3.3/mondo/src/common
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/mondo/src/common/libmondo-archive.c

    r3868 r3870  
    2727#include "libmondo-tools-EXT.h"
    2828#include "libmondo-verify-EXT.h"
    29 #include "lib-common-externs.h"
     29
    3030#include <sys/sem.h>
    3131#include <sys/types.h>
     
    25272527    char *mds = NULL;
    25282528
    2529     malloc_string(cdrom_dev);
    25302529    malloc_string(cdrw_dev);
    25312530
     
    25422541  gotos_make_me_puke:
    25432542    ok_go_ahead_burn_it = TRUE;
    2544     if (!find_cdrom_device(cdrom_dev, FALSE)) {
     2543    mr_free(cdrom_dev);
     2544    if ((cdrom_dev = find_cdrom_device()) != NULL) {
    25452545        /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
    25462546        log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
     
    26322632    mr_free(mds);
    26332633
    2634     paranoid_free(cdrom_dev);
     2634    mr_free(cdrom_dev);
    26352635    paranoid_free(cdrw_dev);
    26362636    mr_free(mtpt);
     
    30443044    int res = 0;
    30453045
    3046     malloc_string(tmp);
    3047 
    30483046    assert(bkpinfo != NULL);
    30493047    orig_vfy_flag_val = bkpinfo->verify_data;
     
    31053103            && (bkpinfo->backup_media_type == cdr
    31063104                || bkpinfo->backup_media_type == cdrw)) {
    3107             if (find_cdrom_device(tmp, FALSE))  // make sure find_cdrom_device() finds, records CD-R's loc
    3108             {
     3105            if ((tmp = find_cdrom_device()) == NULL) {  // make sure find_cdrom_device() finds, records CD-R's loc
    31093106                log_msg(3, "*Sigh* Mike, I hate your computer.");
    31103107                // if it can't be found then force pausing
     
    31133110                log_msg(3, "Great. Found Mike's CD-ROM drive.");
    31143111            }
     3112            mr_free(tmp);
    31153113        }
    31163114        if (bkpinfo->verify_data && !res) {
     
    31673165
    31683166    bkpinfo->verify_data = orig_vfy_flag_val;
    3169     paranoid_free(tmp);
    31703167    return (0);
    31713168}
     
    32173214        g_current_media_number = cdno;
    32183215        if (bkpinfo->backup_media_type != iso) {
    3219             find_cdrom_device(bkpinfo->media_device, FALSE);    // replace 0,0,0 with /dev/cdrom
     3216            mr_free(bkpinfo->media_device);
     3217            bkpinfo->media_device = find_cdrom_device();    // replace 0,0,0 with /dev/cdrom
    32203218        }
    32213219        if (chdir("/")) {
  • branches/3.3/mondo/src/common/libmondo-cli.c

    r3866 r3870  
    1616#include "mondostructures.h"
    1717#include "libmondo-cli-EXT.h"
     18#include "libmondo-newt-specific-EXT.h"
    1819#include "libmondo.h"
    1920
     
    4546extern pid_t g_main_pid;
    4647extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
    47 extern char *mr_popup_and_get_string(const char *, const char *, const char *);
    4848extern char *call_program_and_get_last_line_of_output(const char *);
    4949
     
    294294
    295295    if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) {
    296         if (!flag_set['r'] && g_kernel_version <= 2.5 && strstr(flag_val['d'], "/dev/")) {
    297             fatal_error("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
    298         }
    299         if (flag_set['r'] && g_kernel_version <= 2.5 && !strstr(flag_val['d'], "/dev/")) {
    300             fatal_error("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
    301         }
    302         if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
    303             log_to_screen("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
    304         }
    305 
    306296        if (system("which cdrecord > /dev/null 2> /dev/null") && system("which dvdrecord > /dev/null 2> /dev/null")) {
    307297            fatal_error("Please install dvdrecord/cdrecord and try again.");
     
    336326    if ((flag_set['t'] && !flag_set['d']) && (! bkpinfo->restore_data)) {
    337327        log_it("Hmm! No tape drive specified. Let's see what we can do.");
    338         if (find_tape_device(flag_val['d'])) {
    339             fatal_error("Tape device not specified. I couldn't find it either.");
     328        if ((bkpinfo->media_device = find_tape_device()) == NULL) {
     329            fatal_error("Tape device not specified and I couldn't find it either. Please use option -d");
    340330        }
    341331        flag_set['d'] = TRUE;
    342         log_to_screen("You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']);
     332        log_to_screen("You didn't specify a tape streamer device. I'm assuming %s", bkpinfo->media_device);
    343333    }
    344334
     
    359349        }
    360350        if (!flag_set['d']) {
    361             if (!find_dvd_device(flag_val['d'])) {
     351            if ((bkpinfo->media_device = find_dvd_device()) != NULL) {
    362352                flag_set['d'] = TRUE;
    363                 log_to_screen("I guess DVD drive is at %s", flag_val['d']);
    364             }
    365         }
    366         if (strchr(flag_val['d'], ',')) {
     353                log_to_screen("I guess DVD drive is at %s", bkpinfo->media_device);
     354            }
     355        }
     356        if (strchr(bkpinfo->media_device, ',')) {
    367357            fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
    368358        }
     
    686676    if (flag_set['d']) {        /* backup directory (if ISO/NETFS) */
    687677        if (flag_set['i']) {
     678            // what is flag_val['d'] is NULL/undefined
    688679            mr_asprintf(bkpinfo->isodir, "%s", flag_val['d']);
    689680            mr_asprintf(tmp1, "ls -l %s", bkpinfo->isodir);
     
    695686        } else if (flag_set['n']) {
    696687            mr_free(bkpinfo->netfs_remote_dir);
     688            // what is flag_val['d'] is NULL/undefined
    697689            mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']);
    698690        } else {                /* backup device (if tape/CD-R/CD-RW) */
    699             mr_asprintf(bkpinfo->media_device, "%s", flag_val['d']);
     691            /* bkpinfo-> media_device already setup upper */
    700692        }
    701693    }
     
    720712
    721713    if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
    722         if (g_kernel_version >= 2.6) {
    723714            tmp1 = mr_popup_and_get_string("Device", "Please specify the device", bkpinfo->media_device);
    724715            if (tmp1 == NULL) {
     
    729720                bkpinfo->media_device = tmp1;
    730721            }
    731         } else if (find_cdrw_device(bkpinfo->media_device)) {
    732             retval++;
    733             log_to_screen("Tried and failed to find CD-R[W] drive automatically.\n");
    734722        } else {
    735             flag_set['d'] = TRUE;
    736             strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
    737         }
    738723    }
    739724
  • branches/3.3/mondo/src/common/libmondo-devices.c

    r3867 r3870  
    1515#include "mr_str.h"
    1616#include "mondostructures.h"
    17 #include "lib-common-externs.h"
     17
    1818#include "libmondo-files-EXT.h"
    1919#include "libmondo-string-EXT.h"
     
    2222#include "libmondo-fork-EXT.h"
    2323#include "libmondo-stream-EXT.h"
     24#include "libmondo-newt-specific-EXT.h"
    2425
    2526#ifdef __FreeBSD__
     
    5253extern void setup_tmpdir(char *path);
    5354extern void setup_scratchdir(char *path);
    54 extern char *mr_popup_and_get_string(const char *title, const char *b, const char *input);
    5555extern char *call_program_and_get_last_line_of_output(const char *);
    5656
     
    467467    /*@ int's  ****************************************************** */
    468468    int res;
    469     char *dev = NULL;
    470469
    471470    /*@ end vars **************************************************** */
    472471
    473     malloc_string(dev);
    474472    assert(bkpinfo != NULL);
    475473    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    476474
    477475    if (g_backup_media_type == dvd) {
    478         strcpy(dev, g_dvd_drive_is_here);
    479         if (!dev[0]) {
    480             find_dvd_device(dev);
     476        if (bkpinfo->media_device == NULL) {
     477            bkpinfo->media_device = find_dvd_device();
    481478        }
    482479    } else {
    483         strcpy(dev, g_cdrom_drive_is_here);
    484         if (!dev[0]) {
    485             find_cdrom_device(dev, FALSE);
     480        if (bkpinfo->media_device == NULL) {
     481            bkpinfo->media_device = find_cdrom_device();
    486482        }
    487483    }
     
    491487    }
    492488
    493     if (!dev[0] || (res = mount_CDROM_here(dev, mountpoint))) {
    494         if (!popup_and_get_string("CD-ROM device", "Please enter your CD-ROM's /dev device", dev,(MAX_STR_LEN / 4)-1)) {
     489    if ((bkpinfo->media_device == NULL) || (res = mount_CDROM_here(bkpinfo->media_device, mountpoint))) {
     490        mr_free(bkpinfo->media_device);
     491        if ((bkpinfo->media_device = mr_popup_and_get_string("CD-ROM device", "Please enter your CD-ROM's /dev device", "/dev/cdrom")) == NULL) {
    495492            res = 1;
    496493        } else {
    497             res = mount_CDROM_here(dev, mountpoint);
     494            res = mount_CDROM_here(bkpinfo->media_device, mountpoint);
    498495        }
    499496    }
     
    501498        log_msg(1, "mount failed");
    502499    } else {
    503         log_msg(1, "mount succeeded with %s", dev);
    504     }
    505     paranoid_free(dev);
     500        log_msg(1, "mount succeeded with %s", bkpinfo->media_device);
     501    }
    506502    return (res);
    507503}
     
    867863}
    868864
    869 
    870 int find_dvd_device(char *output)
     865/*
     866 * This function tries to find an optical media device
     867 * and return it's device file to the caller that needs to free it
     868 */
     869char *find_dvd_device()
    871870{
    872871    char *tmp = NULL;
     
    874873    int retval = 0, devno = -1;
    875874
    876     if (g_dvd_drive_is_here[0]) {
    877         strcpy(output, g_dvd_drive_is_here);
    878         log_msg(3, "Been there, done that. Returning %s", output);
    879         return (0);
    880     }
    881 
    882     mr_asprintf(tmp1, "cdrecord -inq dev=%s 2> /dev/null | grep -E 'Device seems to be'  | cut -d':' -f2", output);
     875    if (bkpinfo->media_device != NULL) {
     876        log_msg(3, "Been there, done that. Returning %s", bkpinfo->media_device);
     877        return (bkpinfo->media_device);
     878    }
     879
     880    mr_asprintf(tmp1, "cdrecord -inq 2> /dev/null | grep -E '^Detected '  | cut -d':' -f2");
    883881    tmp = call_program_and_get_last_line_of_output(tmp1);
    884882    mr_free(tmp1);
    885     log_msg(5, "cdrecord tmp = '%s'", tmp);
    886     mr_free(tmp);
     883    log_msg(5, "find_dvd_device found device '%s'", tmp);
    887884
    888885    if (tmp != NULL) {
    889         strcpy(g_dvd_drive_is_here, output);
    890         log_msg(2, "I think DVD is at %s", output);
     886        log_msg(2, "I think DVD is at %s", bkpinfo->media_device);
    891887    } else {
    892888        log_msg(2, "I cannot find DVD");
    893         retval = 1;
    894     }
    895     return(retval);
     889    }
     890    bkpinfo->media_device = tmp;
     891    return(bkpinfo->media_device);
    896892}
    897893
     
    23582354    case tape:
    23592355
    2360         if ((!bkpinfo->restore_mode) && (find_tape_device(bkpinfo->media_device))) {
    2361             log_msg(3, "Ok, using vanilla scsi tape.");
    2362             mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_TAPE);
    2363             if ((fin = fopen(bkpinfo->media_device, "r"))) {
    2364                 paranoid_fclose(fin);
    2365             } else {
    2366                 mr_asprintf(bkpinfo->media_device, "%s", "/dev/osst0");
    2367             }
    2368         }
     2356        bkpinfo->media_device = find_tape_device();
    23692357        if (bkpinfo->media_device != NULL) {
    23702358            if ((fin = fopen(bkpinfo->media_device, "r"))) {
     
    23842372        }
    23852373        if (bkpinfo->media_device == NULL) {
    2386             tmp2 = mr_popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device);
     2374            tmp2 = mr_popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", "");
    23872375            if (tmp2 == NULL) {
    23882376                log_to_screen("User has chosen not to backup the machine");
    23892377                finish(1);
    23902378            } else {
    2391                 mr_free(bkpinfo->media_device);
    23922379                bkpinfo->media_device = tmp2;
    23932380            }
     
    24212408        log_msg(4, "media_size = %ld", bkpinfo->media_size);
    24222409
    2423         bkpinfo->use_obdr = ask_me_yes_or_no
    2424             ("Do you want to activate OBDR support for your tapes ?");
     2410        bkpinfo->use_obdr = ask_me_yes_or_no("Do you want to activate OBDR support for your tapes ?");
    24252411        if (bkpinfo->use_obdr) {
    24262412            log_msg(4, "obdr mode = TRUE");
  • branches/3.3/mondo/src/common/libmondo-stream-EXT.h

    r3860 r3870  
    55extern int closein_tape();
    66extern int closeout_tape();
    7 extern int find_tape_device(char *dev);
     7extern char *find_tape_device(void);
    88extern void insist_on_this_tape_number(int tapeno);
    99extern void log_tape_pos(void);
  • branches/3.3/mondo/src/common/libmondo-stream.c

    r3868 r3870  
    1616#include "mr_file.h"
    1717#include "mondostructures.h"
    18 #include "lib-common-externs.h"
     18
    1919#include "libmondo-string-EXT.h"
    2020#include "libmondo-files-EXT.h"
     
    299299
    300300/**
    301  * Determine the name and size of the tape device. Tries the SCSI tape for
    302  * this platform, then the IDE tape, then "/dev/st0", then "/dev/osst0".
    303  * @param dev Where to put the found tape device. Allocated dynamically by caller or reallocated here
    304  * @param siz Where to put the tape size (a string like "4GB")
    305  * @return 0 if success, nonzero if failure (in which @p dev and @p siz are undefined).
    306  */
    307 int find_tape_device(char *dev) {
     301 * Determine the name of the tape device. Tries the SCSI tape for
     302 * this platform, then "/dev/st0", then "/dev/ht0" and "/dev/osst0".
     303 * @return the value of the tape device or NULL if not found. Allocated dynamically must be freed by caller.
     304 */
     305char *find_tape_device(void) {
    308306    char *tmp = NULL;
     307    char *dev = NULL;
    309308    char *command = NULL;
    310     char *cdr_exe = NULL;
    311     int res;
    312309
    313310    log_to_screen("I am looking for your tape streamer. Please wait.");
    314     mr_free(dev);
    315     if ((cdr_exe = find_home_of_exe("cdrecord")) != NULL) {
    316         if ((cdr_exe = find_home_of_exe("wodim")) != NULL) {
    317             cdr_exe = find_home_of_exe("dvdrecord");
    318         }
    319     }
    320     mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", cdr_exe);
    321     tmp = call_program_and_get_last_line_of_output(command);
    322     mr_free(command);
    323 
    324     if (atoi(tmp) != 1) {
    325         log_it("Either too few or too many tape streamers for me to detect...");
     311
     312    tmp = find_home_of_exe("lsscsi");
     313    if (tmp != NULL) {
     314        mr_asprintf(command, "%s | grep ' tape' | awk '{print $NF}' | head -1", tmp);
     315        dev = call_program_and_get_last_line_of_output(command);
     316        mr_free(command);
     317    }
     318    mr_free(tmp);
     319
     320    if (dev != NULL) && does_file_exist(dev) {
     321        if (mt_says_tape_exists(dev)) {
     322            log_it("find_tape_device found %s automatically", dev);
     323        }
     324    } else {
     325        /* trying something else then */
    326326        mr_asprintf(dev, "%s", VANILLA_SCSI_TAPE);
    327         mr_free(tmp);
    328         mr_free(cdr_exe);
    329         return 1;
    330     }
    331     mr_free(tmp);
    332 
    333     mr_asprintf(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);
    334     tmp = call_program_and_get_last_line_of_output(command);
    335     mr_free(command);
    336 
    337     if (strlen(tmp) < 2) {
    338         log_it("Could not find tape device");
    339         mr_free(cdr_exe);
    340         mr_free(tmp);
    341         return 1;
    342     }
    343     mr_asprintf(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);
    344     mr_free(cdr_exe);
    345 
    346     tmp = call_program_and_get_last_line_of_output(command);
    347     mr_free(command);
    348 
    349     mr_asprintf(dev, "%s", VANILLA_SCSI_TAPE);
    350     dev[strlen(dev) - 1] = '\0';
    351     mr_strcat(dev, tmp);            // e.g. '/dev/st0' becomes '/dev/stN'
    352     mr_free(tmp);
    353 
    354     res = 0;
    355     if (!mt_says_tape_exists(dev)) {
    356         mr_asprintf(dev, "%s", ALT_TAPE);
    357327        if (!mt_says_tape_exists(dev)) {
    358             log_it("Cannot openin %s", dev);
    359             mr_asprintf(dev, "%s", "/dev/st0");
     328            mr_asprintf(dev, "%s", ALT_TAPE);
    360329            if (!mt_says_tape_exists(dev)) {
    361                 log_it("Cannot openin %s", dev);
    362330                mr_asprintf(dev, "%s", "/dev/osst0");
    363331                if (!mt_says_tape_exists(dev)) {
    364                     res++;
    365                 } else {
    366                     res = 0;
     332                    log_it("Unable to find a tape device on this system");
    367333                }
    368334            }
    369335        }
    370     }
    371 
    372     if (dev) {
    373         log_it("At this point, dev = %s and res = %d", dev, res);
    374     } else {
    375         log_it("At this point, dev is NULL and res = %d", res);
    376     }
    377 
    378     if (mt_says_tape_exists(dev)) {
    379         res = 0;
    380     } else {
    381         log_it("Turning %s", dev);
    382         mr_free(tmp);
    383         mr_asprintf(tmp, "%s", (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
    384         mr_asprintf(dev, "/dev/os%s", tmp);
    385         log_it("...into %s", dev);
    386         if (mt_says_tape_exists(dev)) {
    387             res = 0;
    388         } else {
    389             res++;
    390         }
    391     }
    392     log_it("res=%d; dev=%s", res, dev);
    393     return (res);
     336        log_it("find_tape_device found %s manually", dev);
     337    }
     338
     339    if (dev != NULL) {
     340        log_it("find_tape_device returns %s", dev);
     341    } else {
     342        log_it("find_tape_device found no tape on your system returning NULL");
     343    }
     344    return (dev);
    394345}
    395346
Note: See TracChangeset for help on using the changeset viewer.