]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: use table-length in dump for non-standard PT
authorKarel Zak <kzak@redhat.com>
Wed, 18 May 2016 12:29:50 +0000 (14:29 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 18 May 2016 12:29:50 +0000 (14:29 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/fdiskP.h
libfdisk/src/gpt.c
libfdisk/src/script.c

index e20723e61e2f901bdcf0f0f1f579eab646afc306..82561297d416bbd737f68331080c295a47968537 100644 (file)
@@ -58,6 +58,7 @@ struct fdisk_test {
 extern int fdisk_run_test(struct fdisk_test *tests, int argc, char *argv[]);
 #endif
 
+#define FDISK_GPT_NPARTITIONS_DEFAULT  128
 
 /*
  * Generic iterator
index eaa9f4803b9874f576320b4d0c2b3fbc1278e90a..3028a392f8539ffa516c9e6139b96b0c01fbcaf8 100644 (file)
@@ -50,7 +50,7 @@
 #define EFI_PMBR_OSTYPE     0xEE
 #define MSDOS_MBR_SIGNATURE 0xAA55
 #define GPT_PART_NAME_LEN   (72 / sizeof(uint16_t))
-#define GPT_NPARTITIONS     128
+#define GPT_NPARTITIONS     FDISK_GPT_NPARTITIONS_DEFAULT
 
 /* Globally unique identifier */
 struct gpt_guid {
index 75e1b52debd4311e658eba6b0c7db247f78dba37..956d4f52e638421cefdac8a734dc51fc4e9be5fb 100644 (file)
@@ -403,24 +403,31 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt
                struct fdisk_labelitem item;
                char buf[64];
 
+               /* first-lba */
                rc = fdisk_get_disklabel_item(cxt, GPT_LABELITEM_FIRSTLBA, &item);
-               if (rc == 0) {
+               if (!rc) {
                        snprintf(buf, sizeof(buf), "%"PRIu64, item.data.num64);
                        rc = fdisk_script_set_header(dp, "first-lba", buf);
                }
-               if (rc < 0)
-                       goto done;
 
-               rc = fdisk_get_disklabel_item(cxt, GPT_LABELITEM_LASTLBA, &item);
-               if (rc == 0) {
+               /* last-lba */
+               if (!rc)
+                       rc = fdisk_get_disklabel_item(cxt, GPT_LABELITEM_LASTLBA, &item);
+               if (!rc) {
                        snprintf(buf, sizeof(buf), "%"PRIu64, item.data.num64);
                        rc = fdisk_script_set_header(dp, "last-lba", buf);
                }
-               if (rc < 0)
-                       goto done;
+
+               /* table-length */
+               if (!rc) {
+                       size_t n = fdisk_get_npartitions(cxt);
+                       if (n != FDISK_GPT_NPARTITIONS_DEFAULT) {
+                               snprintf(buf, sizeof(buf), "%zu", n);
+                               rc = fdisk_script_set_header(dp, "table-length", buf);
+                       }
+               }
        }
 
-done:
        DBG(SCRIPT, ul_debugobj(dp, "read context done [rc=%d]", rc));
        return rc;
 }