[parted-devel] [PATCH] libparted: Fix _device_probe_geometry

David Cantrell dcantrell at redhat.com
Fri Mar 18 12:14:57 UTC 2016


Right, the 512b block size thing.  Thanks for the update on this.  I'll
give it a try on the 32GB card.

On Thu, Mar 17, 2016 at 7:53 PM, Brian C. Lane <bcl at redhat.com> wrote:

> 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, &sector_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
>
>
-- 
David Cantrell <dcantrell at redhat.com>
Manager, Installer Engineering Team
Red Hat, Inc. | Westford, MA | EST5EDT
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/parted-devel/attachments/20160318/bffbde6a/attachment.html>


More information about the parted-devel mailing list