Changeset 783 in MondoRescue for trunk/mondo/mondo/mondorestore/mondo-prep.c


Ignore:
Timestamp:
Aug 31, 2006, 5:09:20 PM (18 years ago)
Author:
Bruno Cornec
Message:
  • Massive rewrite continues for memory management.
  • main structure should now have all parameters allocated dynamically
  • new lib libmr.a + dir + build process reviewed to support it.
  • new include subdir to host external definitions of the new lib
  • code now compiles. Still one remaining link issues for mondorestore. This should allow for some tests soon.

(goal is to separate completely reviewed code and functions and provide clean interfaces)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/mondorestore/mondo-prep.c

    r764 r783  
    99
    1010
    11 #include "../common/my-stuff.h"
     11#include "my-stuff.h"
    1212#include "../common/mondostructures.h"
    1313#include "mondoprep.h"
     
    5353    char *command;
    5454    int lino;
    55     int i;
    5655    FILE *fout;
    5756    char *buf;
    58     const int blocksize = 512;
    5957    struct list_of_disks *drivelist = NULL;
    6058// If LVMs are present and a zero-and-reboot wasn't recently undertaken
    6159// then zero & insist on reboot.
    62     buf = malloc(blocksize);
    6360    if (does_file_exist("/tmp/i-want-my-lvm"))  // FIXME - cheating :)
    6461    {
     
    8986            log_to_screen("Please hit 'Enter' to reboot.");
    9087            for (lino = 0; lino < drivelist->entries; lino++) {
    91                 for (i = 0; i < blocksize; i++) {
    92                     buf[i] = 0;
    93                 }
    94                 sprintf(buf, "%s\n", MONDO_WAS_HERE);
     88                asprintf(&buf, "%s\n", MONDO_WAS_HERE);
    9589                fout = fopen(drivelist->el[lino].device, "w+");
    9690                if (!fout) {
     
    9892                            drivelist->el[lino].device);
    9993                } else {
    100                     if (1 != fwrite(buf, blocksize, 1, fout)) {
     94                    if (1 != fwrite(buf, strlen(buf)+1, 1, fout)) {
    10195                        log_msg(1, "Failed to wipe %s",
    10296                                drivelist->el[lino].device);
     
    107101                    fclose(fout);
    108102                }
     103                paranoid_free(buf);
    109104            }
    110105            sync();
     
    257252    for (getline(&incoming, &n1, fin); !feof(fin); getline(&incoming, &n1, fin)) {
    258253        fgetpos(fin, &orig_pos);
    259         /* BERLIOS : Strange no ? */
     254        /* we want to execute lines begining with a # */
    260255        if (incoming[0] != '#') {
    261256            continue;
     
    268263        }
    269264        if ((p = strstr(incoming, "vgcreate"))) {
    270 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
     265            // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
    271266            for (getline(&tmp, &n, fin); !feof(fin); getline(&tmp, &n, fin)) {
    272267                if (tmp[0] == '#') {
     
    287282                }
    288283            }
    289             malloc_string(tmp1);
    290             strcpy(tmp1, p + strlen("vgcreate") + 1);
     284            asprintf(&tmp1, p + strlen("vgcreate") + 1);
    291285            for (q = tmp1; *q > 32; q++);
    292286            *q = '\0';
     
    294288            asprintf(&tmp, "rm -Rf /dev/%s", tmp1);
    295289            paranoid_free(tmp1);
     290
    296291            run_program_and_log_output(tmp, 1);
    297292            paranoid_free(tmp);
     
    304299        }
    305300        for (p = incoming + 1; *p == ' '; p++);
    306         paranoid_free(command);
    307         asprintf(&command, p);
     301        paranoid_alloc(command,p);
    308302        for (p = command; *p != '\0'; p++);
    309303        for (; *(p - 1) < 32; p--);
    310304        *p = '\0';
     305
     306        /* BERLIOS: we should rather define LVMv1 or v2 and use it */
    311307        res = run_program_and_log_output(command, 5);
    312308        if (res > 0 && (p = strstr(command, "lvm "))) {
     
    338334            log_msg(5, "p='%s' --> extents=%ld", p, extents);
    339335            paranoid_free(tmp);
     336
    340337            p = strstr(command, "-L");
    341338            if (!p) {
     
    349346                        *q = ' ';
    350347                    }
     348                    /* BERLIOS: Dangerous: no size control !! */
    351349                    sprintf(p, "%ld", extents);
    352350                    i = strlen(p);
     
    359357                        *(q - 1) = ' ';
    360358                    }
     359                    /* BERLIOS: Dangerous: no size control !! */
    361360                    sprintf(p, "%ld%c", extents, 'm');
    362361                    i = strlen(p);
     
    673672    char *tmp = NULL;
    674673    char *tmp1 = NULL;
     674#ifdef __FreeBSD__
    675675    char *line = NULL;
    676676    char *status = NULL;
     
    679679    size_t n = 0;
    680680    size_t n1 = 0;
     681#endif
    681682
    682683    /** end ****************************************************************/
     
    15251526            // If so, then we just call label_drive_or_slice() and return.
    15261527            char c;
     1528            char *command;
     1529
    15271530            if (current_devno == 1) {
    15281531                // try DangerouslyDedicated mode
     
    15381541                                                 drivename,
    15391542                                                 0);
    1540                     char command[MAX_STR_LEN];
    1541                     sprintf(command, "disklabel -B %s",
     1543                    asprintf(&command, "disklabel -B %s",
    15421544                            basename(drivename));
    15431545                    if (system(command)) {
     
    15461548                             ("Warning! Unable to make the drive bootable."));
    15471549                    }
     1550                    paranoid_free(command);
    15481551                    paranoid_free(device_str);
    15491552
     
    20772080        asprintf(&partcode, "8e");
    20782081    } else if (format[0] == '\0') { /* LVM physical partition */
    2079         asprintf(&partcode, "");
     2082        asprintf(&partcode, "%s", "");
    20802083    } else if (strlen(format) >= 1 && strlen(format) <= 2) {
    20812084        asprintf(&partcode, format);
     
    23752378
    23762379    assert_string_is_neither_NULL_nor_zerolength(format);
    2377     assert(program != NULL);
    23782380
    23792381    if (strcmp(format, "swap") == 0) {
    23802382#ifdef __FreeBSD__
    2381         strcpy(program, "true");
     2383        asprintf(&program, "true");
    23822384#else
    2383         strcpy(program, "mkswap");
     2385        asprintf(&program, "mkswap");
    23842386#endif
    23852387    } else if (strcmp(format, "vfat") == 0) {
    2386         strcpy(program, "format-and-kludge-vfat");
     2388        asprintf(&program, "format-and-kludge-vfat");
    23872389#ifndef __FreeBSD__
    23882390    } else if (strcmp(format, "reiserfs") == 0) {
    2389         strcpy(program, "mkreiserfs -ff");
     2391        asprintf(&program, "mkreiserfs -ff");
    23902392    } else if (strcmp(format, "xfs") == 0) {
    2391         strcpy(program, "mkfs.xfs -f -q");
     2393        asprintf(&program, "mkfs.xfs -f -q");
    23922394    } else if (strcmp(format, "jfs") == 0) {
    2393         strcpy(program, "mkfs.jfs");
     2395        asprintf(&program, "mkfs.jfs");
    23942396    } else if (strcmp(format, "ext3") == 0) {
    2395         strcpy(program, "mkfs -t ext2 -F -j -q");
     2397        asprintf(&program, "mkfs -t ext2 -F -j -q");
    23962398    } else if (strcmp(format, "minix") == 0) {
    2397         strcpy(program, "mkfs.minix");
     2399        asprintf(&program, "mkfs.minix");
    23982400#endif
    23992401    } else if (strcmp(format, "ext2") == 0) {
    2400         strcpy(program, "mke2fs -F -q");
     2402        asprintf(&program, "mke2fs -F -q");
    24012403    } else {
    24022404#ifdef __FreeBSD__
    2403         sprintf(program, "newfs_%s", format);
     2405        asprintf(&program, "newfs_%s", format);
    24042406#else
    2405         sprintf(program, "mkfs -t %s -c", format);  // -c checks for bad blocks
     2407        asprintf(&program, "mkfs -t %s -c", format);    // -c checks for bad blocks
    24062408#endif
    24072409        asprintf(&tmp, "Unknown format (%s) - assuming '%s' will do", format,
     
    25042506    }
    25052507
    2506     /*
    2507        sprintf (tmp, "cp -f %s %s.pre-resize", g_mountlist_fname, g_mountlist_fname);
    2508        run_program_and_log_output (tmp, FALSE);
    2509      */
    2510 
    25112508    current_size_of_drive = get_phys_size_of_drive(drive_name);
    25122509
     
    26002597    assert(mountlist != NULL);
    26012598
    2602     if (g_mountlist_fname[0] == '\0') {
     2599    if (g_mountlist_fname == NULL) {
    26032600        log_it
    26042601            ("resize_mountlist_prop...() - warning - mountlist fname is blank");
     
    26482645    if (c && strncmp(c, "/disc", 5) == 0) {
    26492646        /* yup its devfs, change the "disc" to "part" so the existing code works */
    2650         strcpy(c + 1, "part");
     2647        strncpy(c + 1, "part", (size_t)5);
    26512648    }
    26522649    drivemntlist->entries = 0;
Note: See TracChangeset for help on using the changeset viewer.