When running the partition table probes, the code considered empty
tables as invalid ones. Because of this, kpartx -u / -d does not work
correctly on empty tables (with zero partitions).
The return value of the probes should be:
-1: not our partition table type
0: our partition table, but no partitions exist
>0: number of partitions found
Adapt read_gpt_pt() to this semantics.
CC: Hannes Reinecke <hare@suse.com>
CC: Christophe Varoqui <christophe.varoqui@gmail.com>
diff --git a/kpartx/gpt.c b/kpartx/gpt.c
index 3082cae..18be035 100644
--- a/kpartx/gpt.c
+++ b/kpartx/gpt.c
@@ -625,8 +625,8 @@ find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes)
* @fd
* @all - slice with start/size of whole disk
*
- * 0 if this isn't our partition table
- * number of partitions if successful
+ * -1 if this isn't our partition table
+ * number of partitions if successful (>= 0)
*
*/
int
@@ -643,7 +643,7 @@ read_gpt_pt (int fd, struct slice all, struct slice *sp, int ns)
free (gpt);
if (ptes)
free (ptes);
- return 0;
+ return -1;
}
for (i = 0; i < __le32_to_cpu(gpt->num_partition_entries) && i < ns; i++) {
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index b5e0a32..9a4c694 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -368,12 +368,10 @@ main(int argc, char **argv){
/* here we get partitions */
n = ptp->fn(fd, all, slices, SIZE(slices));