Changeset 3377 in MondoRescue for branches/3.2/mondo


Ignore:
Timestamp:
May 6, 2015, 1:10:17 PM (9 years ago)
Author:
Bruno Cornec
Message:
  • Rename mr_parted2fdisk to mr-parted2fdisk for consistency with all other new mr-* commands
  • Adds functions mr_center_string and mr_popup_and_get_string with dynamic allocation to solve a memory allocation issue reported on the ML
  • Fix mr_boot_type to detect correctly a UEFI based system
Location:
branches/3.2/mondo/src
Files:
8 edited

Legend:

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

    r3375 r3377  
    327327#else
    328328    return
    329         !system("mr_parted2fdisk -l 2>/dev/null | grep '^/dev/' | grep -Eqv '(MS|DOS|EFI|FAT|NTFS)'");
     329        !system("mr-parted2fdisk -l 2>/dev/null | grep '^/dev/' | grep -Eqv '(MS|DOS|EFI|FAT|NTFS)'");
    330330#endif
    331331}
     
    364364#endif
    365365
    366     mr_asprintf(program, "mr_parted2fdisk -l %s 2> /dev/null", drive);
     366    mr_asprintf(program, "mr-parted2fdisk -l %s 2> /dev/null", drive);
    367367    fin = popen(program, "r");
    368368    if (!fin) {
     
    17291729    * Either way, it's an error.
    17301730    ********/
    1731     mr_asprintf(command, "mr_parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
     1731    mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
    17321732    log_msg(5, "Executing: %s", command);
    17331733    mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command));
     
    17951795        log_msg(4, "Processing partition: %s", partitions[i]);
    17961796        /* See if it's swap. If it is, ignore it. */
    1797         mr_asprintf(command, "mr_parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]);
     1797        mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]);
    17981798        log_msg(5, "  Running: %s", command);
    17991799        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     
    21102110
    21112111    t_boot ret = BIOS;
    2112     FILE *fd = NULL;
     2112    DIR *fd = NULL;
    21132113
    21142114#ifdef __IA64__
     
    21162116#endif
    21172117    /* Try to detect whether we are in fact in UEFI mode */
    2118     /* TODO: find the right trigger */
    2119     fd = fopen("/sys/module/efi", "r");
     2118    fd = opendir("/sys/firmware/efi", "r");
    21202119    if (fd != NULL) {
    21212120        ret = UEFI;
     2121        closedir(fd);
    21222122    }
    21232123    return(ret);
     
    23652365        mr_free(tmp);
    23662366
    2367         if (!popup_and_get_string("Tape block size?", "What is the block size of your tape streamer?", sz_size, 15)) {
     2367        mr_asprintf(sz_size,"%s",bkpinfo->internal_tape_block_size);
     2368        tmp = mr_popup_and_get_string("Tape block size?", "What is the block size of your tape streamer?", sz_size);
     2369        if (tmp == NULL) {
    23682370            log_to_screen("User has chosen not to backup the PC");
    23692371            finish(1);
    23702372        }
    2371         bkpinfo->internal_tape_block_size = atol(sz_size);
     2373        bkpinfo->internal_tape_block_size = atol(tmp);
     2374        mr_free(sz_size);
     2375        mr_free(tmp);
     2376
    23722377        if (bkpinfo->internal_tape_block_size <= 0) {
    23732378            log_to_screen("User has chosen not to backup the PC");
     
    26822687        mr_free(tmp);
    26832688// NTFS
    2684         strcpy(tmp1, call_program_and_get_last_line_of_output("mr_parted2fdisk -l 2>/dev/null | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
     2689        strcpy(tmp1, call_program_and_get_last_line_of_output("mr-parted2fdisk -l 2>/dev/null | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
    26852690        if (strlen(tmp1) > 2) {
    26862691            if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp1, MAX_STR_LEN / 4)) {
     
    31003105    assert(which_device != NULL);
    31013106
    3102     mr_asprintf(list_drives_cmd, "mr_parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted());
     3107    mr_asprintf(list_drives_cmd, "mr-parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted());
    31033108    log_it("list_drives_cmd = %s", list_drives_cmd);
    31043109
     
    31423147    } else {
    31433148        // We need to look on each partition then
    3144         mr_asprintf(list_drives_cmd, "mr_parted2fdisk -l 2>/dev/null | grep -E \"^/dev/\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/");
     3149        mr_asprintf(list_drives_cmd, "mr-parted2fdisk -l 2>/dev/null | grep -E \"^/dev/\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/");
    31453150        log_it("list_drives_cmd = %s", list_drives_cmd);
    31463151
     
    32903295    struct stat buf;
    32913296#endif
    3292     mr_asprintf(command, "mr_parted2fdisk -l %s 2>/dev/null | grep 'EFI GPT'", drive);
     3297    mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null | grep 'EFI GPT'", drive);
    32933298    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    32943299    mr_free(command);
  • branches/3.2/mondo/src/common/libmondo-string.c

    r3290 r3377  
    6969}
    7070
     71
     72/**
     73 * Pad a string on both sides so it appears centered.
     74 * @param in_out The string to be center-padded (modified).
     75 * @param width The width of the final result.
     76 */
     77char *mr_center_string(char *in, int width)
     78{
     79    char *scratch = NULL;
     80    char *out = NULL;
     81    int i;                      /* purpose */
     82    int len;                    /* purpose */
     83    int mid;                    /* purpose */
     84    int x;                      /* purpose */
     85
     86    assert(in != NULL);
     87    assert(width > 2);
     88
     89    if (strlen(in) == 0) {
     90        return(NULL);
     91    }
     92    /*  skip initial spaces */
     93    mr_asprintf(scratch, "%s", in);
     94    mr_strip_spaces(scratch);
     95    len = (int)strlen(scratch);
     96    mid = width / 2;
     97    x = mid - len / 2;
     98    for (i = 0; i < x; i++) {
     99        mr_strcat(out,' ');
     100    }
     101    mr_strcat(out, scratch);
     102    mr_free(scratch);
     103    for (i = x + len ; i < width - 1; i++) {
     104            mr_strcat(out,' ');
     105        }
     106    return(out);
     107}
    71108
    72109/**
  • branches/3.2/mondo/src/common/libmondo-tools.c

    r3375 r3377  
    993993    mr_free(tmp);
    994994
    995     if (!run_program_and_log_output("mr_parted2fdisk -l 2>/dev/null | grep -i raid", 1) && !does_file_exist("/etc/raidtab")) {
     995    if (!run_program_and_log_output("mr-parted2fdisk -l 2>/dev/null | grep -i raid", 1) && !does_file_exist("/etc/raidtab")) {
    996996        log_to_screen("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
    997997        create_raidtab_from_mdstat(MDSTAT_FILE,"/etc/raidtab");
  • branches/3.2/mondo/src/common/newt-specific.c

    r3292 r3377  
    717717        }
    718718    }
     719
     720/**
     721 * Ask the user to enter a value.
     722 * @param title The title of the dialog box.
     723 * @param b The blurb (e.g. what you want the user to enter).
     724 * @param input The string to initialize the user's answer with.
     725 * @return value needs to be freed up by caller
     726 */
     727char *mr_popup_and_get_string(char *title, char *b, char *input) {
     728
     729    /*@ newt ************************************************************ */
     730    newtComponent myForm;
     731    newtComponent b_1;
     732    newtComponent b_2;
     733    newtComponent b_res;
     734    newtComponent text;
     735    newtComponent type_here;
     736
     737    char *entry_value = NULL;
     738    char *blurb = NULL;
     739    char *out = NULL;
     740
     741    assert_string_is_neither_NULL_nor_zerolength(title);
     742    assert(b != NULL);
     743
     744    if (g_text_mode) {
     745        printf("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n-->  ", title, b);
     746        mr_getline(out, stdin);
     747        if (out[strlen(out) - 1] == '\n')
     748            out[strlen(out) - 1] = '\0';
     749        return(out);
     750    }
     751
     752    assert(input != NULL);
     753    text = newtTextboxReflowed(2, 1, b, 48, 5, 5, 0);
     754    type_here = newtEntry(2, newtTextboxGetNumLines(text) + 2, input, 50, (void *) &entry_value, NEWT_FLAG_RETURNEXIT);
     755    b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, "  OK  ");
     756    b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel");
     757    newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
     758    myForm = newtForm(NULL, NULL, 0);
     759    newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL);
     760    blurb = mr_center_string(b, 80);
     761    newtPushHelpLine(blurb);
     762    b_res = newtRunForm(myForm);
     763
     764    newtPopHelpLine();
     765    newtFormDestroy(myForm);
     766    newtPopWindow();
     767    mr_free(blurb);
     768
     769    if (b_res != b_2) {
     770        out = entry_value;
     771    }
     772    return(out);
     773}
    719774
    720775/**
  • branches/3.2/mondo/src/mondorestore/mondo-prep.c

    r3371 r3377  
    13471347#else
    13481348make_hole_for_file(FDISK_LOG);
    1349 mr_asprintf(tmp, "mr_parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
     1349mr_asprintf(tmp, "mr-parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
    13501350pout_to_fdisk = popen(tmp, "w");
    13511351if (!pout_to_fdisk) {
    1352     log_to_screen("Cannot call mr_parted2fdisk to configure %s", drivename);
     1352    log_to_screen("Cannot call mr-parted2fdisk to configure %s", drivename);
    13531353    mr_free(tmp);
    13541354    return (1);
     
    15871587
    15881588
    1589 mr_asprintf(program, "mr_parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
     1589mr_asprintf(program, "mr-parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
    15901590
    15911591/* BERLIOS: should not be called each time */
     
    19061906    } else {
    19071907        mr_asprintf(output, "t\n%d\n%s\nw\n", partno, partcode);
    1908         mr_asprintf(command, "mr_parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
     1908        mr_asprintf(command, "mr-parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
    19091909        log_msg(5, "output = '%s'", output);
    19101910        log_msg(5, "partno=%d; partcode=%s", partno, partcode);
  • branches/3.2/mondo/src/restore-scripts/mondo/format-and-kludge-vfat

    r3371 r3377  
    2828    device=$1
    2929    drive=$2
    30     ftype=`mr_parted2fdisk -l $drive 2>/dev/null | grep $device | tr '*' ' ' | tr -s '\t' ' ' | cut -d' ' -f5`
     30    ftype=`mr-parted2fdisk -l $drive 2>/dev/null | grep $device | tr '*' ' ' | tr -s '\t' ' ' | cut -d' ' -f5`
    3131    case $ftype in
    3232#   "b" | "c")
  • branches/3.2/mondo/src/restore-scripts/mondo/grub-MR

    r3371 r3377  
    169169    line=`grep $base /proc/mdstat | head -n1`
    170170    echo "mbrdev was $mbrdev" 2>&1 | tee -a $LOGFILE
    171     mbrdev=`mr_parted2fdisk -l 2>/dev/null | grep /dev/ | head -n1 | tr ':' ' ' | cut -d' ' -f2`
     171    mbrdev=`mr-parted2fdisk -l 2>/dev/null | grep /dev/ | head -n1 | tr ':' ' ' | cut -d' ' -f2`
    172172    echo "mbrdev is $mbrdev" 2>&1 | tee -a $LOGFILE
    173173    partno="0"; # cheating - FIXME   
  • branches/3.2/mondo/src/restore-scripts/mondo/make-me-bootable

    r3371 r3377  
    1717dummy="$3"
    1818
    19 activepart=`mr_parted2fdisk -l $drivetouse 2>/dev/null | tr -s '\t' ' ' | grep "$drivetouse" | grep '*' | cut -d' ' -f1`
     19activepart=`mr-parted2fdisk -l $drivetouse 2>/dev/null | tr -s '\t' ' ' | grep "$drivetouse" | grep '*' | cut -d' ' -f1`
    2020
    2121for i in `cat $1 | tr -s '\t' ' ' | cut -d' ' -f1 | grep -vE "/dev/fd|none|#"` ; do
     
    6666        echo "Would activate $partno on $drive" >> $LOGFILE
    6767    else
    68         echo -en "${cmd}a\n$partno\np\nw\n" | mr_parted2fdisk $drive >> $LOGFILE 2>> $LOGFILE
     68        echo -en "${cmd}a\n$partno\np\nw\n" | mr-parted2fdisk $drive >> $LOGFILE 2>> $LOGFILE
    6969    fi
    7070fi
Note: See TracChangeset for help on using the changeset viewer.