]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add sector-size to dump
authorKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2019 08:29:41 +0000 (10:29 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2019 08:29:41 +0000 (10:29 +0200)
We do not use sector-size from dumps to create partition tables,
because it's always necessary to use real device specific settings.

The new sector-size value is usable when you use the dump as
a description of the device or disk image.

Addresses: https://github.com/karelzak/util-linux/issues/869
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/sfdisk.8
libfdisk/src/script.c

index 9dee0cace8f1ed2f0505d72934a0119c619ac650..d1e429381f74c6921294e646e6e90e1bd7ea9569 100644 (file)
@@ -337,6 +337,11 @@ Specify the maximal number of GPT partitions.
 Specify minimal size in bytes used to calculate partitions alignment.  The
 default is 1MiB and it's strongly recommended to use the default.  Do not
 modify this variable if you're not sure.
+.TP
+.B sector-size
+Specify sector size. This header is informative only and it is not used when
+sfdisk creates a new partition table, in this case the real device specific
+value is always used and sector size from the dump is ignored.
 .RE
 .sp
 Note that it is only possible to use header lines before the first partition
index a28983dbad866d438156249509ebec92e28e34a6..50899664fe4f5c075020db8401e8263923072c41 100644 (file)
@@ -445,6 +445,7 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt
        struct fdisk_label *lb;
        int rc;
        char *p = NULL;
+       char buf[64];
 
        if (!dp || (!cxt && !dp->cxt))
                return -EINVAL;
@@ -478,7 +479,6 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt
 
        if (!rc && fdisk_is_label(cxt, GPT)) {
                struct fdisk_labelitem item = FDISK_LABELITEM_INIT;
-               char buf[64];
 
                /* first-lba */
                rc = fdisk_get_disklabel_item(cxt, GPT_LABELITEM_FIRSTLBA, &item);
@@ -506,12 +506,14 @@ int fdisk_script_read_context(struct fdisk_script *dp, struct fdisk_context *cxt
        }
 
        if (!rc && fdisk_get_grain_size(cxt) != 2048 * 512) {
-               char buf[64];
-
                snprintf(buf, sizeof(buf), "%lu", fdisk_get_grain_size(cxt));
                rc = fdisk_script_set_header(dp, "grain", buf);
        }
 
+       if (!rc) {
+               snprintf(buf, sizeof(buf), "%lu", fdisk_get_sector_size(cxt));
+               rc = fdisk_script_set_header(dp, "sector-size", buf);
+       }
 
        DBG(SCRIPT, ul_debugobj(dp, "read context done [rc=%d]", rc));
        return rc;
@@ -580,6 +582,9 @@ static int write_file_json(struct fdisk_script *dp, FILE *f)
                } else if (strcmp(name, "last-lba") == 0) {
                        name = "lastlba";
                        num = 1;
+               } else if (strcmp(name, "sector-size") == 0) {
+                       name = "sectorsize";
+                       num = 1;
                } else if (strcmp(name, "label-id") == 0)
                        name = "id";