[parted-devel] [PATCH] libparted: Fix _device_probe_geometry
Brian C. Lane
bcl at redhat.com
Thu Mar 17 23:53:04 UTC 2016
dev->length is in 512b blocks, sectors should also be in the same units,
so divide sector_size by PED_SECTOR_SIZE_DEFAULT.
CHS sectors also start at 1, so add 1 to it and use 2 as the fallback
default.
FWIW the HDIO_GETGEO ioctl returns this on a 2048 sector 512b/sector scsi_debug
disk:
cyl=1024 heads=1 sectors=2
With this change all tests pass, but it should also be tried with the
32G SD card.
---
libparted/arch/linux.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 6422c56..326b956 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -871,7 +871,7 @@ _device_probe_geometry (PedDevice* dev)
if (!ioctl (arch_specific->fd, BLKSSZGET, §or_size)) {
/* get the sector count first */
- dev->bios_geom.sectors = sector_size;
+ dev->bios_geom.sectors = 1 + (sector_size / PED_SECTOR_SIZE_DEFAULT);
dev->bios_geom.heads = 255;
} else if (!ioctl (arch_specific->fd, HDIO_GETGEO, &geometry)
&& geometry.sectors && geometry.heads) {
@@ -885,20 +885,14 @@ _device_probe_geometry (PedDevice* dev)
_("Could not determine sector size for %s: %s.\n"
"Using the default sector size (%lld)."),
dev->path, strerror (errno), PED_SECTOR_SIZE_DEFAULT);
- dev->bios_geom.sectors = PED_SECTOR_SIZE_DEFAULT;
+ dev->bios_geom.sectors = 2;
dev->bios_geom.heads = 255;
}
- dev->hw_geom.heads = dev->bios_geom.heads;
- dev->hw_geom.sectors = dev->bios_geom.sectors;
-
dev->bios_geom.cylinders
= dev->length / (dev->bios_geom.heads
* dev->bios_geom.sectors);
- dev->hw_geom.cylinders
- = dev->length / (dev->hw_geom.heads
- * dev->hw_geom.sectors);
-
+ dev->hw_geom = dev->bios_geom;
return 1;
}
--
2.5.0
More information about the parted-devel
mailing list