Ignore:
Timestamp:
Jun 17, 2009, 10:53:23 PM (15 years ago)
Author:
Bruno Cornec
Message:
  • Simplify log_it calls when possible (with just a fixed string)
  • issue with truncate_to_drive_name reported by valgrind at restore time. Needs rewrite IMO
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/libmondo-string.c

    r2211 r2230  
    841841    int i = strlen(partition) - 1;
    842842    char *c;
     843    char *trunc = NULL;
     844
     845    mr_asprintf(&trunc, "%s", partition);
    843846
    844847#ifdef __FreeBSD__
    845848
    846     if (islower(partition[i]))  // BSD subpartition
     849    if (islower(trunc[i]))  // BSD subpartition
    847850        i--;
    848     if (partition[i - 1] == 's') {
    849         while (isdigit(partition[i]))
     851    if (trunc[i-1] == 's') {
     852        while (isdigit(trunc[i]))
    850853            i--;
    851854        i--;
    852855    }
    853     partition[i + 1] = '\0';
     856    trunc[i+1] = '\0';
    854857
    855858#else
     
    857860    assert_string_is_neither_NULL_nor_zerolength(partition);
    858861    /* first see if it's a devfs style device */
    859     c = strrchr(partition, '/');
     862    c = strrchr(trunc, '/');
    860863    if (c && strncmp(c, "/part", 5) == 0) {
    861864        /* yup it's devfs, return the "disc" path */
    862865        strcpy(c + 1, "disc");
    863         return partition;
     866        return trunc;
    864867    }
    865868    /* then see if it's a dm style device */
    866869    if (c && strncmp(c, "/dm-", 4) == 0) {
    867870        /* yup it's dm, return the full path */
    868         return partition;
    869     }
    870 
    871 
    872     for (i = strlen(partition); isdigit(partition[i - 1]); i--)
     871        return trunc;
     872    }
     873
     874
     875    for (i = strlen(trunc); isdigit(trunc[i-1]); i--)
    873876        continue;
    874     if (partition[i - 1] == 'p' && isdigit(partition[i - 2])) {
     877    if (trunc[i-1] == 'p' && isdigit(trunc[i-2])) {
    875878        i--;
    876879    } else {
    877880        /* Some full devices like this /dev/mapper/mpath0
    878881           /dev/cciss/c0d0 may be used as partition names */
    879         if ((strstr(partition,"/dev/mapper/mpath") != NULL) ||
    880             (strstr(partition,"/dev/cciss/c") != NULL) ||
    881             (strstr(partition,"/dev/rd/") != NULL)) {
    882                 return partition;
     882        if ((strstr(trunc,"/dev/mapper/mpath") != NULL) ||
     883            (strstr(trunc,"/dev/cciss/c") != NULL) ||
     884            (strstr(trunc,"/dev/rd/") != NULL)) {
     885                return trunc;
    883886            }
    884887    }
    885     partition[i] = '\0';
     888    trunc[i] = '\0';
    886889
    887890#endif
    888891
    889     return partition;
     892    return trunc;
    890893}
    891894
Note: See TracChangeset for help on using the changeset viewer.