]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: improve fdisk_save_user_geometry()
authorKarel Zak <kzak@redhat.com>
Wed, 25 Sep 2013 15:11:08 +0000 (17:11 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 25 Sep 2013 15:11:08 +0000 (17:11 +0200)
The functions should not overwrite old setting if the new value (C/H/S) is
zero.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/alignment.c

index 0f445acc3cd54659dad7dd41b5bbeb3c36c33945..f661c5cce4d7192277f591e7b4526f9dc50dde59 100644 (file)
@@ -176,12 +176,17 @@ int fdisk_save_user_geometry(struct fdisk_context *cxt,
        if (!cxt)
                return -EINVAL;
 
-       cxt->user_geom.heads = heads > 256 ? 0 : heads;
-       cxt->user_geom.sectors = sectors >= 64 ? 0 : sectors;
-       cxt->user_geom.cylinders = cylinders;
+       if (heads)
+               cxt->user_geom.heads = heads > 256 ? 0 : heads;
+       if (sectors)
+               cxt->user_geom.sectors = sectors >= 64 ? 0 : sectors;
+       if (cylinders)
+               cxt->user_geom.cylinders = cylinders;
 
        DBG(GEOMETRY, dbgprint("user C/H/S: %u/%u/%u",
-                               cylinders, heads, sectors));
+                               (unsigned) cxt->user_geom.cylinders,
+                               (unsigned) cxt->user_geom.heads,
+                               (unsigned) cxt->user_geom.sectors));
 
        return 0;
 }