mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
part-get-bootable: Fix when partitions are missing or unordered (RHBZ#602997).
The original fix for this in commit511c82df46was not complete, in that it did not fix the case of the old (pre '-m' option) parted. This doesn't matter for Fedora, but it matters for RHEL 5 which has this ancient parted. (cherry picked from commit4d3ec25b47)
This commit is contained in:
@@ -696,10 +696,22 @@ do_part_get_bootable (const char *device, int partnum)
|
||||
}
|
||||
size_t col = p - lines[header];
|
||||
|
||||
/* Look for the line corresponding to this partition number. */
|
||||
row = start + partnum - 1;
|
||||
if (row >= count_strings (lines) || !STRPREFIX (lines[row], " ")) {
|
||||
reply_with_error ("partition number out of range: %d", partnum);
|
||||
/* Partitions may not be in any order, so we have to look for
|
||||
* the matching partition number (RHBZ#602997).
|
||||
*/
|
||||
int pnum;
|
||||
for (row = start; lines[row] != NULL; ++row) {
|
||||
if (sscanf (lines[row], " %d", &pnum) != 1) {
|
||||
reply_with_error ("could not parse row from output of parted print command: %s", lines[row]);
|
||||
free_strings (lines);
|
||||
return -1;
|
||||
}
|
||||
if (pnum == partnum)
|
||||
break;
|
||||
}
|
||||
|
||||
if (lines[row] == NULL) {
|
||||
reply_with_error ("partition number %d not found", partnum);
|
||||
free_strings (lines);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user