Skip to content

Commit

Permalink
Fixed devices-shrinking-by-one-block problem.
Browse files Browse the repository at this point in the history
So it turns out the SCSI ReadCapacity10 command does not return the
device capacity. It returns the address of the last block, which is
(capacity - 1).

Also fixed Upstream's end-of-device sanity check.
  • Loading branch information
robertfisk committed Mar 14, 2017
1 parent e240410 commit b476df2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost,
if(error == USBH_OK)
{
/*assign the capacity*/
capacity->block_nbr = MSC_Handle->hbot.pbuf[3] | (MSC_Handle->hbot.pbuf[2] << 8) |\
(MSC_Handle->hbot.pbuf[1] << 16) | (MSC_Handle->hbot.pbuf[0] << 24);
capacity->block_nbr = (MSC_Handle->hbot.pbuf[3] | (MSC_Handle->hbot.pbuf[2] << 8) |\
(MSC_Handle->hbot.pbuf[1] << 16) | (MSC_Handle->hbot.pbuf[0] << 24)) + 1; //block_nbr = logical address of last block + 1

/*assign the page length*/
capacity->block_size = MSC_Handle->hbot.pbuf[7] | (MSC_Handle->hbot.pbuf[6] << 8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,8 @@ static void SCSI_Verify10(void)
*/
static int8_t SCSI_CheckAddressRange (uint32_t blk_offset , uint16_t blk_nbr)
{
if ((blk_offset > SCSI_ProcessCmd_hmsc->scsi_blk_nbr) ||
((blk_offset + blk_nbr) > SCSI_ProcessCmd_hmsc->scsi_blk_nbr))
if ((blk_offset >= SCSI_ProcessCmd_hmsc->scsi_blk_nbr) ||
((blk_offset + blk_nbr - 1) >= SCSI_ProcessCmd_hmsc->scsi_blk_nbr))
{
SCSI_SenseCode(SCSI_ProcessCmd_pdev,
SCSI_ProcessCmd_lun,
Expand Down

0 comments on commit b476df2

Please sign in to comment.