]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: recount size when apply user device properties
authorKarel Zak <kzak@redhat.com>
Fri, 13 Jan 2017 11:16:06 +0000 (12:16 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Jan 2017 11:16:06 +0000 (12:16 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/alignment.c

index b874a48f897c479bfea8a300ab0de3f7f0e62094..c4496fe9f22f65f109b058b896713be8b7778dea 100644 (file)
@@ -337,10 +337,19 @@ int fdisk_apply_user_device_properties(struct fdisk_context *cxt)
 
        if (cxt->user_pyh_sector)
                cxt->phy_sector_size = cxt->user_pyh_sector;
-       if (cxt->user_log_sector)
+       if (cxt->user_log_sector) {
+               uint64_t old_total = cxt->total_sectors;
+               uint64_t old_secsz = cxt->sector_size;
+
                cxt->sector_size = cxt->min_io_size =
                        cxt->io_size = cxt->user_log_sector;
 
+               if (cxt->sector_size != old_secsz) {
+                       cxt->total_sectors = (old_total * (old_secsz/512)) / (cxt->sector_size >> 9);
+                       DBG(CXT, ul_debugobj(cxt, "new total sectors: %ju", cxt->total_sectors));
+               }
+       }
+
        if (cxt->user_geom.heads)
                cxt->geom.heads = cxt->user_geom.heads;
        if (cxt->user_geom.sectors)