]> 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>
Tue, 17 Jan 2017 15:12:02 +0000 (16:12 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/alignment.c

index 58acefb890b8cebb595d5eb50db5acb070a0cc08..f4446c145a5fd8330bfcfc7ee438bdb77d5f86ec 100644 (file)
@@ -335,10 +335,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)