summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-06-22 10:54:57 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-06-28 09:46:13 +0100
commit5bb76b5f03d75882ee21f97e621322710aab8755 (patch)
treeccd9efb783f07ededee8cb25b4a1b2402dd5c48c
parentdb6806593fae1f469156fce719a643723cfafe5b (diff)
downloadlibguestfs-5bb76b5f03d75882ee21f97e621322710aab8755.tar.gz
libguestfs-5bb76b5f03d75882ee21f97e621322710aab8755.tar.xz
libguestfs-5bb76b5f03d75882ee21f97e621322710aab8755.zip
part-get-bootable: Fix when partitions are missing or unordered (RHBZ#602997).
The original fix for this in commit 511c82df46f5c6f4a7f984fdb81d4691038ed6da was 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 commit 4d3ec25b47361601604e2f585178393e60f4cd4d)
-rw-r--r--daemon/parted.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/daemon/parted.c b/daemon/parted.c
index 1a020f9b..ceefc4af 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -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;
}