From a4347d207290d70a8e110d5cce3fa757b3458c5a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 25 Sep 2013 17:11:08 +0200 Subject: libfdisk: improve fdisk_save_user_geometry() The functions should not overwrite old setting if the new value (C/H/S) is zero. Signed-off-by: Karel Zak --- libfdisk/src/alignment.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'libfdisk/src') diff --git a/libfdisk/src/alignment.c b/libfdisk/src/alignment.c index 0f445acc3..f661c5cce 100644 --- a/libfdisk/src/alignment.c +++ b/libfdisk/src/alignment.c @@ -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; } -- cgit v1.2.3-55-g7522