Skip to content

Commit 35918dc

Browse files
committed
USB mass storage device support improved
USB mass storage device support did not work with some drives. Should be better now. USBBulkOnlyMassStorageDeviceGetCapacity() added FIXED: Wrong assert() in lib/usbstring.c
1 parent bc6bbf9 commit 35918dc

File tree

6 files changed

+278
-122
lines changed

6 files changed

+278
-122
lines changed

kernel/syscalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ DRESULT disk_ioctl (
475475
}
476476
if (cmd == GET_SECTOR_COUNT)
477477
{
478-
*(DWORD *)buff = 340000; // TODO: Get real number of blocks
478+
*(DWORD *)buff = USPiMassStorageDeviceGetCapacity(pdrv - USB);
479479
return RES_OK;
480480
}
481481
if (cmd == GET_SECTOR_SIZE)

uspi/include/uspi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ int USPiMassStorageDeviceRead (unsigned long long ullOffset, void *pBuffer, unsi
117117
// nDeviceIndex is 0-based
118118
int USPiMassStorageDeviceWrite (unsigned long long ullOffset, const void *pBuffer, unsigned nCount, unsigned nDeviceIndex);
119119

120+
// returns the number of available blocks of USPI_BLOCK_SIZE or 0 on failure
121+
unsigned USPiMassStorageDeviceGetCapacity (unsigned nDeviceIndex);
122+
120123
//
121124
// Ethernet services
122125
//

uspi/include/uspi/usbmassdevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct TUSBBulkOnlyMassStorageDevice
4242
TUSBEndpoint *m_pEndpointOut;
4343

4444
unsigned m_nCWBTag;
45+
unsigned m_nBlockCount;
4546
unsigned long long m_ullOffset;
4647
}
4748
TUSBBulkOnlyMassStorageDevice;
@@ -56,6 +57,8 @@ int USBBulkOnlyMassStorageDeviceWrite (TUSBBulkOnlyMassStorageDevice *pThis, con
5657

5758
unsigned long long USBBulkOnlyMassStorageDeviceSeek (TUSBBulkOnlyMassStorageDevice *pThis, unsigned long long ullOffset);
5859

60+
unsigned USBBulkOnlyMassStorageDeviceGetCapacity (TUSBBulkOnlyMassStorageDevice *pThis);
61+
5962
#ifdef __cplusplus
6063
}
6164
#endif

0 commit comments

Comments
 (0)