Changeset 3859 in MondoRescue for branches/3.3/mondo


Ignore:
Timestamp:
Mar 7, 2024, 1:33:54 AM (3 months ago)
Author:
Bruno Cornec
Message:

Fix build_partition_name to allocate dynamically and change proto accordingly

Location:
branches/3.3/mondo/src
Files:
6 edited

Legend:

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

    r3857 r3859  
    356356    assert(partno >= 0 && partno < 999);
    357357
    358     malloc_string(searchstr);
    359 
    360358#ifdef __FreeBSD__
    361359    // We assume here that this is running from mondorestore. (It is.)
    362     mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, build_partition_name(tmp, drive, partno));
     360    tmp = build_partition_name(drive, partno);
     361    mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, tmp);
     362    mr_free(tmp);
    363363    res = system(program);
    364364    mr_free(program);
     
    376376    mr_free(program);
    377377
    378     (void) build_partition_name(searchstr, drive, partno);
    379     strcat(searchstr, " ");
     378    searchstr = build_partition_name(drive, partno);
     379    mr_strcat(searchstr, " ");
    380380    for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) {
    381381        if (strstr(incoming, searchstr)) {
     
    384384        mr_free(incoming);
    385385    }
     386    mr_free(searchstr);
    386387    mr_free(incoming);
    387388
     
    389390        log_OS_error("Cannot pclose fin");
    390391    }
    391     paranoid_free(searchstr);
    392392    return (res);
    393393}
  • branches/3.3/mondo/src/common/libmondo-string-EXT.h

    r3858 r3859  
    33 */
    44
    5 extern char *build_partition_name(char *partition, const char *drive,
    6                                   int partno);
     5extern char *build_partition_name(const char *drive, int partno);
    76extern char *commarize(char *);
    87extern char *disklist_entry_to_string(struct list_of_disks *disklist,
  • branches/3.3/mondo/src/common/libmondo-string.c

    r3858 r3859  
    3535 * @param drive The drive basename of the partition name (e.g. /dev/hda)
    3636 * @param partno The partition number (e.g. 1)
    37  * @param partition Where to put the partition name (e.g. /dev/hda1)
    38  * @return @p partition.
     37 * @return @p the partition name (e.g. /dev/hda1)
    3938 * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno.
    4039 */
    41 char *build_partition_name(char *partition, const char *drive, int partno)
     40char *build_partition_name(const char *drive, int partno)
    4241{
    4342    char *p, *c;
    4443
    45     assert(partition != NULL);
    4644    assert_string_is_neither_NULL_nor_zerolength(drive);
    4745    assert(partno >= 0);
    4846
    49     p = strcpy(partition, drive);
     47    mr_free(partition);
     48    mr_asprintf(partition, "%s", drive);
     49    p = partition;
    5050    /* is this a devfs device path? */
    5151    c = strrchr(partition, '/');
     
    5454        /* This strcpy is safe */
    5555        strcpy(c + 1, "part");
    56         p = c + 5;
    5756    } else {
    5857        p += strlen(p);
    5958        if (isdigit(p[-1])) {
    60             *p++ =
     59            mr_strcat(partition, "%c",
    6160#ifdef BSD
    6261                's';
     
    6463                'p';
    6564#endif
     65                );
    6666        }
    6767    }
    68     sprintf(p, "%d", partno);
     68    mr_strcat(partition, "%d", partno);
    6969    return(partition);
    7070}
  • branches/3.3/mondo/src/common/libmondo-string.h

    r3858 r3859  
    33 */
    44
    5 char *build_partition_name(char *partition, const char *drive, int partno);
    65char *commarize(char *);
    76char *disklist_entry_to_string(struct list_of_disks *disklist, int lino);
  • branches/3.3/mondo/src/mondorestore/mondo-prep.c

    r3741 r3859  
    13231323
    13241324/** buffers *********************************************************/
    1325 char *device_str;
     1325char *device_str = NULL;
    13261326char *format = NULL;
    13271327char *tmp = NULL;
     
    13511351#endif
    13521352
    1353 malloc_string(device_str);
    1354 
    13551353for (current_devno = 1; current_devno < 99; current_devno++) {
    1356     build_partition_name(device_str, drivename, current_devno);
     1354    device_str = build_partition_name(drivename, current_devno);
    13571355    lino = find_device_in_mountlist(mountlist, device_str);
    13581356
     
    13771375                                                 drivename,
    13781376                                                 0);
    1379                     char command[MAX_STR_LEN];
    1380                     sprintf(command, "disklabel -B %s",
    1381                             basename(drivename));
     1377                    mr_asprintf(command, "disklabel -B %s", basename(drivename));
    13821378                    if (system(command)) {
    13831379                        log_to_screen
    13841380                            ("Warning! Unable to make the drive bootable.");
    13851381                    }
    1386                     paranoid_free(device_str);
     1382                    mr_free(command);
     1383                    mr_free(device_str);
    13871384                    return r;
    13881385                }
    13891386            }
    13901387            for (c = 'a'; c <= 'z'; c++) {
    1391                 mr_assprintf(subdev_str, "%s%c", device_str, c);
     1388                mr_asprintf(subdev_str, "%s%c", device_str, c);
    13921389                if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
    13931390                    fbsd_part = TRUE;
     
    14691466        if (current_devno == 5 && previous_devno == 4) {
    14701467            log_to_screen("You must leave at least one partition spare as the Extended partition.");
    1471             paranoid_free(device_str);
     1468            mr_free(device_str);
    14721469            mr_free(format);
    14731470            return (1);
     
    14921489
    14931490    previous_devno = current_devno;
     1491    mr_free(device_str);
    14941492}
    14951493
     
    15291527    }
    15301528}
    1531 paranoid_free(device_str);
    15321529return (retval);
    15331530}
     
    15501547/** buffers **********************************************************/
    15511548char *program = NULL;
    1552 char *partition_name;
     1549char *partition_name = NULL;
    15531550char *tmp = NULL;
    15541551char *output = NULL;
     
    15701567}
    15711568
    1572 malloc_string(partition_name);
    1573 build_partition_name(partition_name, drive, partno);
     1569partition_name = build_partition_name(drive, partno);
    15741570if (partsize <= 0) {
    15751571    mr_asprintf(tmp, "Partitioning device %s (max size)", partition_name);
     
    15831579if (is_this_device_mounted(partition_name)) {
    15841580    log_to_screen("%s is mounted, and should not be partitioned", partition_name);
    1585     paranoid_free(partition_name);
     1581    mr_free(partition_name);
    15861582    return (1);
    15871583}
     
    16031599            if (prev_partno >= 4) {
    16041600                log_to_screen("You need to leave at least one partition free, for 'extended/logical'");
    1605                 paranoid_free(partition_name);
     1601                mr_free(partition_name);
    16061602                paranoid_free(output);
    16071603                return (1);
     
    17121708mr_free(program);
    17131709mr_free(output);
     1710mr_free(partition_name);
    17141711
    17151712g_current_progress++;
    17161713log_it("partition_device() --- leaving");
    1717 paranoid_free(partition_name);
    17181714return (retval);
    17191715}
     
    18041800
    18051801/** buffers *********************************************************/
    1806 char *partition;
     1802char *partition = NULL;
    18071803char *command = NULL;
    18081804char *output = NULL;
     
    18211817assert(format != NULL);
    18221818
    1823 malloc_string(partition);
    1824 
    1825 build_partition_name(partition, drive, partno);
     1819partition = build_partition_name(drive, partno);
    18261820if (strcmp(format, "swap") == 0) {
    18271821    mr_asprintf(partcode, "82");
     
    18721866}
    18731867log_msg(1, "Setting %s's type to %s (%s)", partition, format, partcode);
     1868mr_free(partition);
     1869
    18741870if ((strcmp(partcode,"") != 0) && strcmp(partcode, "83")) { /* no need to set type if 83: 83 is default */
    18751871
     
    19251921}
    19261922mr_free(partcode);
    1927 
    1928 paranoid_free(partition);
    19291923
    19301924return (res);
  • branches/3.3/mondo/src/mondorestore/mondo-rstr-mountlist.c

    r3611 r3859  
    5454
    5555    /*@ buffers ******************************************************** */
    56     char tmp = NULL;
    57     char tmp1 = NULL;
    58     char device[MAX_STR_LEN];
     56    char *tmp = NULL;
     57    char *tmp1 = NULL;
     58    char *device = NULL;
    5959
    6060    char *flaws_str = NULL;
     
    8686    /* check DD */
    8787    for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    88         sprintf(device, "%s%c", drive, cur_sp_no);
     88        mr_asprintf(device, "%s%c", drive, cur_sp_no);
    8989        if (find_device_in_mountlist(mountlist, device) >= 0)
    9090            foundsome = TRUE;
     
    9292    if (foundsome) {
    9393        for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    94             sprintf(device, "%s%c", drive, cur_sp_no);
     94            mr_asprintf(device, "%s%c", drive, cur_sp_no);
    9595            pos = find_device_in_mountlist(mountlist, device);
    9696            if (pos < 0) {
     
    160160    npos = pos = 0;
    161161    for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
    162         build_partition_name(device, drive, curr_part_no);
     162        device = build_partition_name(drive, curr_part_no);
    163163        pos = find_device_in_mountlist(mountlist, device);
    164164        npos = 0;
    165165        for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) {
    166             sprintf(device, "%ss%i%c", device, curr_part_no, cur_sp_no);
     166            mr_asprintf(device, "%ss%i%c", device, curr_part_no, cur_sp_no);
    167167            if (find_device_in_mountlist(mountlist, device) >= 0)
    168168                npos++;
     
    170170        if (((pos >= 0) || npos) && foundsome) {
    171171            mr_strcat(flaws_str, " %s has both DD and PC-style partitions.", drive);
     172            mr_free(device);
    172173            return(flaws_str);      // fatal error
    173174        }
    174175
    175         build_partition_name(device, drive, curr_part_no);
    176176        if (pos > 0 && !npos) {
    177177            /* gap in the partition list? */
     
    255255            /* Check subpartitions */
    256256            for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    257                 sprintf(device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
     257                mr_asprintf(device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
    258258                pos = find_device_in_mountlist(mountlist, device);
    259259                if (pos < 0) {
     
    344344        }
    345345        prev_part_no = curr_part_no;
     346        mr_free(device);
    346347    }
    347348
     
    397398    mr_asprintf(flaws_str, "%s", "");
    398399
    399     malloc_string(device);
    400400    prev_part_no = 0;
    401401
     
    421421
    422422    for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
    423         build_partition_name(device, drive, curr_part_no);
     423        device = build_partition_name(drive, curr_part_no);
    424424        pos = find_device_in_mountlist(mountlist, device);
    425425        if (pos < 0) {
     
    520520
    521521  endoffunc:
    522     paranoid_free(device);
     522    mr_free(device);
    523523
    524524    if (res == 0) {
Note: See TracChangeset for help on using the changeset viewer.