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

Julius Lehmann lehmanju at devpi.de
Mon Oct 14 18:06:35 CEST 2024


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 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>
---
 drivers/scsi/scsi.c | 2 ++
 1 file changed, 2 insertions(+)

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) |

---
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