Changeset 3377


Ignore:
Timestamp:
May 6, 2015, 1:10:17 PM (4 years ago)
Author:
bruno
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
Files:
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi/README.ia64

    r3371 r3377  
    33Linux distributions on ia64 uses a different file table format than on i386, called GPT instead of MBR. The fdisk command used by mindi/mondo to determine all aspects related to the disc hasn't been adapted yet to handle GPT. Only the parted command is able to do it.
    44
    5 So a perl script called mr_parted2fdisk was written that will take as input all the order that mindi/mondo pass to fdisk, translate them to be given to parted and print the result in fdisk format. So this is a filter allowing fdisk replacement. It's only used on ia64. On other archs, mr_parted2fdisk is a link to fdisk.
     5So a perl script called mr-parted2fdisk was written that will take as input all the order that mindi/mondo pass to fdisk, translate them to be given to parted and print the result in fdisk format. So this is a filter allowing fdisk replacement. It's only used on ia64. On other archs, mr-parted2fdisk is a link to fdisk.
    66
    7 Thus mindi/mondorestore commands launched by root will pass all their call to mr_parted2fdisk on ia64 instead of the real fdisk, and be able to support the GPT format. It will call fdisk and parted for its work.  (Note again that on ia32 parte2fdisk is in fact a link to fdisk to avoid any compatibility issue)
     7Thus mindi/mondorestore commands launched by root will pass all their call to mr-parted2fdisk on ia64 instead of the real fdisk, and be able to support the GPT format. It will call fdisk and parted for its work.  (Note again that on ia32 parte2fdisk is in fact a link to fdisk to avoid any compatibility issue)
    88
    99The install.sh script will setup everything correctly for you.
    1010
    11 Note that mr_parted2fdisk supports currently only the -l and -s options as well as the commands p,n,d,w,t,a,q
     11Note that mr-parted2fdisk supports currently only the -l and -s options as well as the commands p,n,d,w,t,a,q
    1212
    1313On Itanium systems you won't generally find an installed isolinux.bin file which is required by mindi to create the bootable images. You'll generally have to take an i386 package for your distribution and install it on your itanium system so that you provide the required missing file.
     
    1818Bruno.
    1919
    20 2015-03-21 tool renamed to mr_parted2fdisk
     202015-03-21 tool renamed to mr-parted2fdisk
    21212013-06-08 no binary made anymore, only perl scripts
    22222005-12-12 parted2fdisk used everywhere
  • branches/3.2/mindi/install.sh

    r3371 r3377  
    9595
    9696# Manage perl script man pages
    97 for s in mindi-bkphw mindi-get-perl-modules mr_parted2fdisk; do
     97for s in mindi-bkphw mindi-get-perl-modules mr-parted2fdisk; do
    9898    install -m 755 $s $SBINDIR
    9999    pod2man -c "$s a MondoRescue tool" --section=8 --release="$VERSTR" $SBINDIR/$s > $s.8
     
    109109fi
    110110
    111 # Managing mr_parted2fdisk
    112 (cd $SBINDIR && install -m 755 mr_parted2fdisk $locallib/mindi/rootfs/usr/sbin/mr_parted2fdisk)
     111# Managing mr-parted2fdisk
     112(cd $SBINDIR && install -m 755 mr-parted2fdisk $locallib/mindi/rootfs/usr/sbin/mr-parted2fdisk)
    113113
    114114if [ "$PKGBUILDMINDI" != "true" ]; then
    115115    chown -R root:root $locallib/mindi $conf # $DOCDIR
    116     chown root:root $SBINDIR/mindi $MANDIR/mindi.8 $locallib/mindi/analyze-my-lvm $SBINDIR/mr_parted2fdisk
     116    chown root:root $SBINDIR/mindi $MANDIR/mindi.8 $locallib/mindi/analyze-my-lvm $SBINDIR/mr-parted2fdisk
    117117fi
    118118
  • branches/3.2/mindi/mindi

    r3372 r3377  
    100100\n0eF107-Main | Boot Parameters 0eF207-1/2 | 0eF307-2/2 | 0eF407-PXE\n\
    101101"
    102 FDISK=$MINDI_SBIN/mr_parted2fdisk
     102FDISK=$MINDI_SBIN/mr-parted2fdisk
    103103
    104104# Using a config file allow to overwrite some values
  • branches/3.2/mindi/mr-parted2fdisk

    r3376 r3377  
    33# $Id$
    44#
    5 # mr_parted2fdisk: fdisk like interface for parted
     5# mr-parted2fdisk: fdisk like interface for parted
    66# [developed for mindi/mondo http://www.mondorescue.org]
    77#
     
    2727=head1 NAME
    2828
    29 mr_parted2fdisk is a fdisk like command using parted internally for analysing GPT labelled disks
     29mr-parted2fdisk is a fdisk like command using parted internally for analysing GPT labelled disks
    3030
    3131=head1 DESCRIPTION
    3232
    33 mr_parted2fdisk behaves like the fdisk command, but dialog internally with parted in order to manipulate partition tables, which allow it to support GPT partition format as well as MBR, contrary to fdisk. It aims at providing compatible external interface with fdisk. Developed initialy for ia64 Linux, it is also useful now on x86 systems using GPT partition format (for large HDDs).
     33mr-parted2fdisk behaves like the fdisk command, but dialog internally with parted in order to manipulate partition tables, which allow it to support GPT partition format as well as MBR, contrary to fdisk. It aims at providing compatible external interface with fdisk. Developed initialy for ia64 Linux, it is also useful now on x86 systems using GPT partition format (for large HDDs).
    3434
    3535=head1 SYNOPSIS
    3636
    37 mr_parted2fdisk -s partition
    38 
    39 mr_parted2fdisk -l [device]
    40 
    41 mr_parted2fdisk [-n] device
     37mr-parted2fdisk -s partition
     38
     39mr-parted2fdisk -l [device]
     40
     41mr-parted2fdisk [-n] device
    4242
    4343=head1 OPTIONS
     
    5656
    5757Fake mode. Doesn't pass the commands just simulate.
     58
     59=item B<-v>
     60
     61Verbose mode. Used to help debugging issues.
    5862
    5963=item B<no option>
     
    102106
    103107# Log
    104 my $flog = "/var/log/mr_parted2fdisk.log";
     108my $flog = "/var/log/mr-parted2fdisk.log";
    105109open(FLOG, "> $flog") || die "Unable to open $flog";
    106110
     
    133137my $device;
    134138my $endmax = "";
    135 my $appname = "mr_parted2fdisk";
     139my $appname = "mr-parted2fdisk";
    136140my ($mrver,$mrrev) = mr_version_init();
    137141
  • 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.