]> err.no Git - util-linux/commitdiff
libblkid: fix 'partno' usage
authorKarel Zak <kzak@redhat.com>
Wed, 7 Apr 2010 07:39:05 +0000 (09:39 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 7 Apr 2010 07:39:05 +0000 (09:39 +0200)
Linux kernel ignores empty partitions, but partition number is always
allocated for the partition. (This rule is used for primary partitions
only.)

For example:

  part 1.  size=12345
  part 2.  size=0
  part 3.  size=24567

the final list of partitions:

  sda1 sda3

'sda2' is not defined and partno=2 is not used for any other
partitions.

The libblkid library has to be compatible with this rule.

Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/partitions/dos.c
shlibs/blkid/src/partitions/gpt.c
shlibs/blkid/src/partitions/partitions.c
shlibs/blkid/src/partitions/partitions.h
shlibs/blkid/src/partitions/sgi.c
shlibs/blkid/src/partitions/sun.c

index c9865b75ded322bb24eb422d267adba50655d602..7c95b8beafae490f3b7bb06edfb58e488d8b0379 100644 (file)
@@ -203,9 +203,12 @@ static int probe_dos_pt(blkid_probe pr, const struct blkid_idmag *mag)
                start = dos_partition_start(p) * ssf;
                size = dos_partition_size(p) * ssf;
 
-               if (!size)
+               if (!size) {
+                       /* Linux kernel ignores empty partitions, but partno for
+                        * the empty primary partitions is not reused */
+                       blkid_partlist_increment_partno(ls);
                        continue;
-
+               }
                par = blkid_partlist_add_partition(ls, tab, start, size);
                if (!par)
                        goto err;
index 569490131191604419f3959fc10ec10ef02ba73f..12100e0f8589c216258146a068dcc08718b733bc 100644 (file)
@@ -328,14 +328,16 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag)
                                        le64_to_cpu(e->starting_lba) + 1ULL;
 
                /* 00000000-0000-0000-0000-000000000000 entry */
-               if (!guidcmp(e->partition_type_guid, GPT_UNUSED_ENTRY_GUID))
+               if (!guidcmp(e->partition_type_guid, GPT_UNUSED_ENTRY_GUID)) {
+                       blkid_partlist_increment_partno(ls);
                        continue;
-
+               }
                /* the partition has to inside usable range */
                if (start < fu || start + size - 1 > lu) {
                        DBG(DEBUG_LOWPROBE, printf(
                                "GPT entry[%d] overflows usable area - ignore\n",
                                i));
+                       blkid_partlist_increment_partno(ls);
                        continue;
                }
 
index a5c56c8898505bc5121bb3f6611ac178206836b0..219a19732055647a54a37fc5033e39471d2fb9c0 100644 (file)
@@ -27,7 +27,9 @@
  * @short_description: partitions tables detection and parsing
  *
  * This chain supports binary and NAME=value interfaces, but complete PT
- * description is provided by binary interface only.
+ * description is provided by binary interface only. The libblkid prober is
+ * compatible with kernel partition tables parser. The parser does not return
+ * empty (size=0) partitions or special hidden partitions.
  *
  * NAME=value interface, supported tags:
  *
@@ -424,7 +426,7 @@ static blkid_partition new_partition(blkid_partlist ls, blkid_parttable tab)
 
        ref_parttable(tab);
        par->tab = tab;
-       par->partno = ls->next_partno++;
+       par->partno = blkid_partlist_increment_partno(ls);
 
        return par;
 }
@@ -457,6 +459,11 @@ int blkid_partlist_set_partno(blkid_partlist ls, int partno)
        return 0;
 }
 
+int blkid_partlist_increment_partno(blkid_partlist ls)
+{
+       return ls ? ls->next_partno++ : -1;
+}
+
 /* allows to set "parent" for the next nested partition */
 int blkid_partlist_set_parent(blkid_partlist ls, blkid_partition par)
 {
index 190918f9e4f5d177191af7e0966cfcb67123266f..2a4d20af5614aa419bcb4901459706e312fbd652 100644 (file)
@@ -14,6 +14,8 @@ extern blkid_partition blkid_partlist_add_partition(blkid_partlist ls,
                                blkid_loff_t start, blkid_loff_t size);
 
 extern int blkid_partlist_set_partno(blkid_partlist ls, int partno);
+extern int blkid_partlist_increment_partno(blkid_partlist ls);
+
 extern blkid_partition blkid_partlist_get_parent(blkid_partlist ls);
 
 extern int blkid_partitions_do_subprobe(blkid_probe pr,
index 3a9cd0a76922000f89b6dfc44a4314b7341f48aa..945ead542a21d5360c59bee7ebd14f28eb56382a 100644 (file)
@@ -126,9 +126,10 @@ static int probe_sgi_pt(blkid_probe pr, const struct blkid_idmag *mag)
                blkid_partition par;
 
                if (size == 0 || type == SGI_TYPE_VOLULME ||
-                                type == SGI_TYPE_VOLHDR)
+                                type == SGI_TYPE_VOLHDR) {
+                       blkid_partlist_increment_partno(ls);
                        continue;
-
+               }
                par = blkid_partlist_add_partition(ls, tab, start, size);
                if (!par)
                        goto err;
index d70200c850e1e9cf4f382f3ff14f2ca88f37f2a6..dffab24c60ce635d7899f05a0883be661def8b25 100644 (file)
@@ -148,9 +148,10 @@ static int probe_sun_pt(blkid_probe pr, const struct blkid_idmag *mag)
                        flags = be16_to_cpu(l->vtoc.infos[i].flags);
                }
 
-               if (type == SUN_TAG_WHOLEDISK || !size)
+               if (type == SUN_TAG_WHOLEDISK || !size) {
+                       blkid_partlist_increment_partno(ls);
                        continue;
-
+               }
                par = blkid_partlist_add_partition(ls, tab, start, size);
                if (!par)
                        goto err;