[PATCH v2] scsi: fix disk capacity too small by one sector

Simon Glass sjg at chromium.org
Mon Oct 28 18:03:48 CET 2024


+Heinrich Schuchardt <xypron.glpk at gmx.de>

On Sat, 26 Oct 2024 at 20:06, Julius Lehmann <lehmanju at devpi.de> wrote:
>
> SCSI READ CAPACITY reports the address of the last block and the block
> size. The total number of blocks is thus last block address plus one.
>
> This also fixes the corresponding test case.
>
> ---
> This patch fixes the disk size reported by scsi. Up until now, the
reported disk size is too small by one sector. Read/Write operations on
other sectors have not been affected. Trying to partition scsi backed
storage via ums has resulted in "storage too small" errors.
>
> doc: https://linux.die.net/man/8/sg_readcap
>
> Signed-off-by: Julius Lehmann <lehmanju at devpi.de>
> ---
> Changes in v2:
> - fixed corresponding test case
> - Link to v1:
https://lore.kernel.org/r/20241014-fix-scsi-disksize-v1-1-0edb9959b580@devpi.de
> ---
>  drivers/scsi/scsi.c | 2 ++
>  test/boot/bootdev.c | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> index
51cacf3479236be6c6ea3e7d15b87e03f10e7f3a..bcdeda95ed1514119057cc67974fec465cf5672c
100644
> --- a/drivers/scsi/scsi.c
> +++ b/drivers/scsi/scsi.c
> @@ -309,6 +309,7 @@ static int scsi_read_capacity(struct udevice *dev,
struct scsi_cmd *pccb,
>                          ((unsigned long)pccb->pdata[5] << 16) |
>                          ((unsigned long)pccb->pdata[6] << 8)  |
>                          ((unsigned long)pccb->pdata[7]);
> +               *capacity += 1;
>                 return 0;
>         }
>
> @@ -332,6 +333,7 @@ static int scsi_read_capacity(struct udevice *dev,
struct scsi_cmd *pccb,
>                     ((uint64_t)pccb->pdata[5] << 16) |
>                     ((uint64_t)pccb->pdata[6] << 8)  |
>                     ((uint64_t)pccb->pdata[7]);
> +       *capacity += 1;
>
>         *blksz = ((uint64_t)pccb->pdata[8]  << 56) |
>                  ((uint64_t)pccb->pdata[9]  << 48) |
> diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c
> index
c635d06ec25d4bf274099f153648d34f5a845436..bc632a3d14124f5f821c4625e5b29b7d352f7161
100644
> --- a/test/boot/bootdev.c
> +++ b/test/boot/bootdev.c
> @@ -621,7 +621,7 @@ static int bootdev_test_next_label(struct
unit_test_state *uts)
>         ut_assertok(bootdev_next_label(&iter, &dev, &mflags));
>         ut_assert_nextline("scanning bus for devices...");
>         ut_assert_skip_to_line(
> -               "            Capacity: 1.9 MB = 0.0 GB (4095 x 512)");
> +               "            Capacity: 2.0 MB = 0.0 GB (4096 x 512)");
>         ut_assert_console_end();
>         ut_assertnonnull(dev);
>         ut_asserteq_str("scsi.id0lun0.bootdev", dev->name);
>
> ---
> base-commit: 29e5dbc55c64c6450f066c55a5bc48bd1717aa1b
> change-id: 20241014-fix-scsi-disksize-d73a017cadf4
>
> Best regards,
> --
> Julius Lehmann <lehmanju at devpi.de>
>


More information about the U-Boot mailing list