virDiskNameToIndex: ignore trailing digits

* src/util/util.c (virDiskNameToIndex): Accept sda1, and map it to "sda".
I.e., accept and ignore any string of trailing digits.
This commit is contained in:
Jim Meyering 2010-03-19 18:26:09 +01:00
parent b9a3287e80
commit 67ef701779

View File

@ -2260,8 +2260,9 @@ const char *virEnumToString(const char *const*types,
return types[type]; return types[type];
} }
/* Translates a device name of the form (regex) "[fhv]d[a-z]+" into /* Translates a device name of the form (regex) /^[fhv]d[a-z]+[0-9]*$/
* the corresponding index (e.g. sda => 0, hdz => 25, vdaa => 26) * into the corresponding index (e.g. sda => 0, hdz => 25, vdaa => 26)
* Note that any trailing string of digits is simply ignored.
* @param name The name of the device * @param name The name of the device
* @return name's index, or -1 on failure * @return name's index, or -1 on failure
*/ */
@ -2285,12 +2286,17 @@ int virDiskNameToIndex(const char *name) {
idx = (idx + (i < 1 ? 0 : 1)) * 26; idx = (idx + (i < 1 ? 0 : 1)) * 26;
if (!c_islower(*ptr)) if (!c_islower(*ptr))
return -1; break;
idx += *ptr - 'a'; idx += *ptr - 'a';
ptr++; ptr++;
} }
/* Count the trailing digits. */
size_t n_digits = strspn(ptr, "0123456789");
if (ptr[n_digits] != '\0')
return -1;
return idx; return idx;
} }