From 52a0936fbc642d102e20ab9c1558d02f7f0ee674 Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Fri, 24 Jun 2022 13:39:43 -0500 Subject: [PATCH] Fix onReadCapacity calculation --- src/BlueSCSI.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/BlueSCSI.cpp b/src/BlueSCSI.cpp index c731bf6..f2d17f8 100644 --- a/src/BlueSCSI.cpp +++ b/src/BlueSCSI.cpp @@ -999,16 +999,18 @@ byte onRequestSense(SCSI_DEVICE *dev, const byte *cdb) * READ CAPACITY command processing. */ byte onReadCapacity(SCSI_DEVICE *dev, const byte *cdb) -{ +{ + uint32_t blocksize = dev->m_blocksize; + uint32_t blockcount = dev->m_fileSize / blocksize - 1; // Points to last LBA uint8_t buf[8] = { - dev->m_blockcount >> 24, - dev->m_blockcount >> 16, - dev->m_blockcount >> 8, - dev->m_blockcount - 1, // Points to last LBA - dev->m_blocksize >> 24, - dev->m_blocksize >> 16, - dev->m_blocksize >> 8, - dev->m_blocksize + blockcount >> 24, + blockcount >> 16, + blockcount >> 8, + blockcount, + blocksize >> 24, + blocksize >> 16, + blocksize >> 8, + blocksize }; writeDataPhase(8, buf); return SCSI_STATUS_GOOD;