[PATCH 4/8] usb: storage: support USB disks up to 2TiB of size

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Feb 16 15:02:04 EST 2021


SCSI Read Capacity (10) only supports up to 0xFFFF_FFFF sectors at most,
which at 512 bytes per sector equals a disk size of 2 TiB.

Due to barebox block layer limits, however, the barebox mass storage
driver doesn't address sectors that need more than 31 bits to describe.
These block layer limits were removed in a previous commit, so make the
USB driver use the full 32 bit to support 512-byte sector USB disks up
to 2 TiB of size.

Disks that are larger than that must either implement SCSI Read Capacity
(16) to support up to 16 Exabytes or increase the sector size beyond 512
bytes. This commit doesn't do that as I don't have the suitable hardware
to test.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/usb/storage/usb.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 4a46bc14fd66..c264dd4b71e2 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -305,10 +305,11 @@ static int usb_stor_init_blkdev(struct us_blk_dev *pblk_dev)
 		return result;
 	}
 
-	if (last_lba > INT_MAX - 1) {
-		last_lba = INT_MAX - 1;
+	if (last_lba == U32_MAX) {
+		last_lba = U32_MAX - 1;
 		dev_warn(dev,
-			 "Limiting device size due to 31 bit contraints\n");
+			 "Limiting device size due to 32 bit constraints\n");
+		/* To support LBA >= U32_MAX, a READ CAPACITY (16) should be issued here */
 	}
 
 	pblk_dev->blk.num_blocks = last_lba + 1;
-- 
2.29.2




More information about the barebox mailing list