Ignore:
Timestamp:
Jun 19, 2013, 8:34:46 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • First pass on svn merge -r 2935:3146 ../3.0
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.1/mondo/src/mondorestore/mondo-prep.c

    r2937 r3147  
    110110            popup_and_OK
    111111                ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.");
    112             system("reboot");
     112            paranoid_system("reboot");
    113113        }
    114114    }
     
    171171
    172172int do_my_funky_lvm_stuff(bool just_erase_existing_volumes,
    173                           bool vacuum_pack)
     173                            bool vacuum_pack)
    174174{
    175     /**  buffers **********************************************/
     175    /** buffers **********************************************/
    176176    char *tmp = NULL;
    177177    char *tmp1 = NULL;
     
    188188    char *p;
    189189    char *q;
     190    char *r;
    190191
    191192    /** int ***************************************************/
     
    442443    /** pointers *********************************************************/
    443444    char *p;
     445    char *q;
    444446
    445447    /** init *************************************************************/
     
    503505        } else {
    504506            strcpy(new_mountlist->el[new_mountlist->entries].device,
    505                   old_mountlist->el[lino].device);
     507                    old_mountlist->el[lino].device);
    506508            strcpy(new_mountlist->el[new_mountlist->entries].mountpoint,
    507                   old_mountlist->el[lino].mountpoint);
     509                    old_mountlist->el[lino].mountpoint);
    508510            strcpy(new_mountlist->el[new_mountlist->entries].format,
    509                   old_mountlist->el[lino].format);
     511                    old_mountlist->el[lino].format);
    510512            new_mountlist->el[new_mountlist->entries].size =
    511513                old_mountlist->el[lino].size;
     
    527529 * @return 0 for success, nonzero for failure.
    528530 */
    529 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device)
    530 {
    531   /** int **************************************************************/
    532   int i   = 0;
    533   int j   = 0;
    534   int res = 0;
    535  
    536   /** buffers ***********************************************************/
    537   char *devices = NULL;
    538   char *strtmp  = NULL;
    539   char *level   = NULL;
    540   char *program = NULL;
    541   char *tmp = NULL;
    542   char *oldmd = NULL;
    543   char *bootdevice;
    544   char *name;
     531int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device, bool test) {
     532    /** int **************************************************************/
     533    int i   = 0;
     534    int j   = 0;
     535    int v   = 0;
     536    int res = 0;
     537   
     538    /** buffers ***********************************************************/
     539    char *devices = NULL;
     540    char *level   = NULL;
     541    char *program = NULL;
    545542
    546543  malloc_string(bootdevice);
     
    735732            /* format raid partition */
    736733            mr_asprintf(program, "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes", basename(device));
    737             system(program);
     734            paranoid_system(program);
    738735            if (g_fprep) {
    739736                fprintf(g_fprep, "%s\n", program);
     
    752749
    753750                mr_asprintf(tmp, "vinum init %s", line);
    754                 system(tmp);
     751                paranoid_system(tmp);
    755752                mr_free(tmp);
    756753
     
    781778        log_to_screen("Initializing RAID device %s", device);
    782779
    783 // Shouldn't be necessary.
     780        // Shouldn't be necessary.
    784781        log_to_screen("Stopping %s", device);
    785782        stop_raid_device(device);
     
    789786        log_msg(1, "Making %s", device);
    790787        // use mkraid if it exists, otherwise use mdadm
    791         if (run_program_and_log_output("which mkraid", FALSE)) {
    792             res = create_raid_device_via_mdadm(raidlist, device);
    793             log_msg(1, "Creating RAID device %s via mdadm returned %d", device, res);
     788            if (run_program_and_log_output("which mkraid", FALSE)) {
     789                res = create_raid_device_via_mdadm(raidlist, device, TRUE);
     790                log_msg(1, "Creating RAID device %s via mdadm returned %d", device, res);
    794791        } else {
    795792            mr_asprintf(program, "mkraid --really-force %s", device);
     
    884881 */
    885882int format_everything(struct mountlist_itself *mountlist, bool interactively,
    886                           struct raidlist_itself *raidlist)
     883                            struct raidlist_itself *raidlist)
    887884{
    888885    /** int **************************************************************/
     
    907904    log_it("format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false");
    908905
    909     mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions     ");
     906    mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions      ");
    910907    open_progress_form("Formatting partitions",
    911                       "I am now formatting your hard disk partitions.",
    912                       "This may take up to five minutes.", "",
    913                       mountlist->entries + 1);
     908                        "I am now formatting your hard disk partitions.",
     909                        "This may take up to five minutes.", "",
     910                        mountlist->entries + 1);
    914911
    915912    progress_step =
     
    949946    sleep(2);
    950947// This last step is probably necessary
    951 //  log_to_screen("Re-starting software RAIDs...");
    952 //  start_all_raid_devices(mountlist);
    953 //  system("sync"); system("sync"); system("sync");
    954 //  sleep(5);
     948//  log_to_screen("Re-starting software RAIDs...");
     949//  start_all_raid_devices(mountlist);
     950//  paranoid_system("sync"); paranoid_system("sync"); paranoid_system("sync");
     951//  sleep(5);
    955952// do LVMs now
    956953    log_msg(1, "Creating LVMs");
     
    992989            continue;
    993990        } else if (!does_file_exist(me->device)
    994                   && strncmp(me->device, "/dev/hd", 7)
    995                   && strncmp(me->device, "/dev/sd", 7)) {
     991                    && strncmp(me->device, "/dev/hd", 7)
     992                    && strncmp(me->device, "/dev/sd", 7)) {
    996993            log_it("Not formatting %s yet - doesn't exist - probably an LVM", me->device);
    997994            continue;
     
    10491046    }
    10501047    newtSuspend();
    1051     system("clear");
     1048    paranoid_system("clear");
    10521049    newtResume();
    10531050    return (retval);
     
    10641061 */
    10651062int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename,
    1066                           int devno_we_must_allow_for)
     1063                            int devno_we_must_allow_for)
    10671064{
    10681065    /** int **************************************************************/
     
    11781175    fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions);
    11791176    fprintf(f,
    1180             "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
     1177            "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
    11811178    pp = lp->d_partitions;
    11821179    for (i = 0; i < lp->d_npartitions; i++, pp++) {
    11831180        if (pp->p_size) {
    1184             fprintf(f, "  %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size,
     1181            fprintf(f, "    %c: %8lu %8lu  ", 'a' + i, (u_long) pp->p_size,
    11851182                    (u_long) pp->p_offset);
    11861183            if (pp->p_fstype < FSMAXTYPES)
     
    11911188
    11921189            case FS_UNUSED: /* XXX */
    1193                 fprintf(f, "    %5lu %5lu %5.5s ", (u_long) pp->p_fsize,
     1190                fprintf(f, "      %5lu %5lu %5.5s ", (u_long) pp->p_fsize,
    11941191                        (u_long) (pp->p_fsize * pp->p_frag), "");
    11951192                break;
    11961193
    11971194            case FS_BSDFFS:
    1198                 fprintf(f, "    %5lu %5lu %5u ", (u_long) pp->p_fsize,
     1195                fprintf(f, "      %5lu %5lu %5u ", (u_long) pp->p_fsize,
    11991196                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    12001197                break;
    12011198
    12021199            case FS_BSDLFS:
    1203                 fprintf(f, "    %5lu %5lu %5d", (u_long) pp->p_fsize,
     1200                fprintf(f, "      %5lu %5lu %5d", (u_long) pp->p_fsize,
    12041201                        (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg);
    12051202                break;
     
    12171214            fprintf(f, "- %lu",
    12181215                    (u_long) ((pp->p_offset + pp->p_size +
    1219                               lp->d_secpercyl - 1) / lp->d_secpercyl -
    1220                               1));
     1216                                lp->d_secpercyl - 1) / lp->d_secpercyl -
     1217                                1));
    12211218            if (pp->p_size % lp->d_secpercyl)
    12221219                putc('*', f);
     
    12561253    /*
    12571254     * Nobody in these enligthened days uses the CHS geometry for
    1258      * anything, but nontheless try to get it right.  If we fail
     1255     * anything, but nontheless try to get it right.    If we fail
    12591256     * to get any good ideas from the device, construct something
    12601257     * which is IBM-PC friendly.
     
    13401337                lp->d_partitions[c - 'a'].p_cpg = 64;
    13411338            } else if (!strcasecmp(mountlist->el[idx].format, "raid")
    1342                       || !strcasecmp(mountlist->el[idx].format, "vinum")) {
     1339                        || !strcasecmp(mountlist->el[idx].format, "vinum")) {
    13431340                lp->d_partitions[c - 'a'].p_fstype = FS_VINUM;
    13441341            } else if (!strcmp(mountlist->el[idx].format, "swap")) {
     
    14221419    char *format = NULL;
    14231420    char *tmp = NULL;
     1421    char *tmp1 = NULL;
    14241422    char *tmp1 = NULL;
    14251423
     
    15111509
    15121510        /* OK, we've found partition /dev/hdxN in mountlist; let's prep it */
    1513         /* For FreeBSD, that is      /dev/adXsY */
     1511        /* For FreeBSD, that is     /dev/adXsY */
    15141512
    15151513        log_it("Found partition %s in mountlist", device_str);
     
    15401538                previous_devno =
    15411539                    make_dummy_partitions(pout_to_fdisk, drivename,
    1542                                           current_devno);
     1540                                            current_devno);
    15431541            }
    15441542        }
     
    15951593        sync();
    15961594        paranoid_pclose(pout_to_fdisk);
    1597         log_msg(0,
    1598                 "------------------- fdisk.log looks like this ------------------");
     1595        paranoid_system("sync");
     1596        log_msg(0,"------------------- fdisk.log looks like this ------------------");
    15991597        mr_asprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    16001598        system(tmp);
     
    16251623 * Create partition number @p partno on @p drive with @p fdisk.
    16261624 * @param drive The drive to create the partition on.
    1627 //  * @param partno The partition number of the new partition (1-4 are primary, >=5 is logical).
     1625//  * @param partno The partition number of the new partition (1-4 are primary, >=5 is logical).
    16281626 * @param prev_partno The partition number of the most recently prepped partition.
    16291627 * @param format The filesystem type of this partition (used to set the type).
     
    16561654
    16571655    log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting",
    1658           drive, partno, prev_partno, format, partsize);
     1656            drive, partno, prev_partno, format, partsize);
    16591657
    16601658    if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
     
    17431741            retval =
    17441742                set_partition_type(pout_to_fdisk, drive, partno, format,
    1745                                   partsize);
     1743                                    partsize);
    17461744            if (retval) {
    17471745                log_msg(1, "Failed. Trying again...");
    17481746                retval =
    17491747                    set_partition_type(pout_to_fdisk, drive, partno,
    1750                                       format, partsize);
     1748                                        format, partsize);
    17511749            }
    17521750        }
     
    17831781            retval =
    17841782                set_partition_type(pout_to_fdisk, drive, partno, format,
    1785                                   partsize);
     1783                                    partsize);
    17861784            if (retval) {
    17871785                log_it("Partitioned %s but failed to set its type", partition_name);
     
    18321830    /** buffer *********************************************************/
    18331831    struct list_of_disks *drivelist;
    1834     /*  struct mountlist_itself new_mtlist, *mountlist; */
     1832    /*  struct mountlist_itself new_mtlist, *mountlist; */
    18351833
    18361834    /** end ************************************************************/
     
    18401838
    18411839    log_it("partition_everything() --- starting");
    1842     mvaddstr_and_log_it(g_currentY, 0, "Partitioning hard drives      ");
    1843     /*  mountlist=orig_mtlist; */
     1840    mvaddstr_and_log_it(g_currentY, 0, "Partitioning hard drives        ");
     1841    /*  mountlist=orig_mtlist; */
    18441842    if (mountlist_contains_raid_devices(mountlist)) {
    1845         /*      mountlist=&new_mtlist; */
    1846         /*      extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */
     1843        /*      mountlist=&new_mtlist; */
     1844        /*      extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */
    18471845        log_msg(0,
    18481846                "Mountlist, including the partitions incorporated in RAID devices:-");
     
    18651863
    18661864    open_progress_form("Partitioning devices",
    1867                       "I am now going to partition all your drives.",
    1868                       "This should not take more than five minutes.", "",
    1869                       mountlist->entries);
     1865                        "I am now going to partition all your drives.",
     1866                        "This should not take more than five minutes.", "",
     1867                        mountlist->entries);
    18701868
    18711869    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    18851883    }
    18861884    newtSuspend();
    1887     system("clear");
     1885    paranoid_system("clear");
    18881886    newtResume();
    18891887    paranoid_free(drivelist);
     
    19061904 */
    19071905int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno,
    1908                       const char *format, long long partsize)
     1906                        const char *format, long long partsize)
    19091907{
    19101908    /** buffers *********************************************************/
     
    19391937        }
    19401938    } else if (strcmp(format, "ext2") == 0
    1941                || strcmp(format, "reiserfs") == 0
    1942                || strcmp(format, "ext3") == 0
    1943                || strcmp(format, "ext4") == 0
    1944                || strcmp(format, "xfs") == 0
    1945                || strcmp(format, "jfs") == 0) {
     1939                 || strcmp(format, "reiserfs") == 0
     1940                 || strcmp(format, "ext3") == 0
     1941                 || strcmp(format, "ext4") == 0
     1942                 || strcmp(format, "xfs") == 0
     1943                 || strcmp(format, "jfs") == 0
     1944                     || strcmp(format, "btrfs") == 0) {
    19461945        mr_asprintf(partcode, "83");
    19471946    } else if (strcmp(format, "minix") == 0) {
     
    19561955        mr_asprintf(partcode, "7");
    19571956    } else if ((strcmp(format, "ufs") == 0)
    1958               || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
     1957                || (strcmp(format, "ffs") == 0)) { /* raid autodetect */
    19591958        mr_asprintf(partcode, "a5");
    19601959    } else if (strcmp(format, "lvm") == 0) {
     
    21082107    mr_asprintf(program, "vinum stop -f %s", raid_device);
    21092108#else
    2110     // use raidstop if it exists, otherwise use mdadm
    2111     if (run_program_and_log_output("which raidstop", FALSE)) {
     2109        // use raidstop if it exists, otherwise use mdadm
     2110        if (run_program_and_log_output("which raidstop", FALSE)) {
    21122111        mr_asprintf(program, "mdadm -S %s", raid_device);
    21132112    } else {
     
    21742173    /** pointers ********************************************************/
    21752174    FILE *fin;
     2175    char *q;
    21762176    int i;
    21772177
     
    22032203                for (p = dev; *p > 32; p++);
    22042204                *p = '\0';
    2205                 res = stop_raid_device(dev);
     2205                retval += stop_raid_device(dev);
    22062206                mr_free(dev);
    22072207            }
     
    22612261    } else if (strcmp(format, "ext4") == 0) {
    22622262        mr_asprintf(program, "mkfs -t ext4 -F -q");
     2263    } else if (strcmp(format, "btrfs") == 0) {
     2264              strcpy(program, "mkfs.btrfs");
    22632265    } else if (strcmp(format, "minix") == 0) {
    22642266        mr_asprintf(program, "mkfs.minix");
     
    22972299 * There are a few problems with this function:
    22982300 * - It won't work if there was any unallocated space on the user's hard drive
    2299  *  when it was backed up.
     2301 *  when it was backed up.
    23002302 * - It won't work if the user's hard drive lies about its size (more common
    2301  *  than you'd think).
     2303 *  than you'd think).
    23022304 *
    23032305 * @param mountlist The mountlist to use for resizing @p drive_name.
     
    23112313    /** int *************************************************************/
    23122314    int partno, lastpart;
    2313                /** remove driveno, noof_drives stan benoit apr 2002**/
    23142315
    23152316    /** float ***********************************************************/
Note: See TracChangeset for help on using the changeset viewer.