I have it automatic now. The interface descriptor is parsed again in 'OnLoadDevice', the ep addresses are extracted and passed as extra parameters to 'OnDiskInsert'. USBFileSystem now also derives from USBSCSI which wraps all the non-OOP stuff in MassStorage.cpp. USBSCSI has the endpoints and the device as members, so the device parameter is removed from all members except 'SetDevice'.
'main' looks now like this:
<<code>>
class USBFileSystem : public FATFileSystem, public USBSCSI
{
//int _device;
u32 _blockSize;
u32 _blockCount;
public:
USBFileSystem() : FATFileSystem("usb")/*,_device(0)*/,_blockSize(0),_blockCount(0)
{
}
/*
void SetDevice(int device, unsigned char in, unsigned char out)
{
_device = device;
}
*/
virtual int disk_initialize()
{
return SCSIReadCapacity(&_blockCount,&_blockSize);
//return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
}
virtual int disk_write(const char *buffer, int block_number)
{
return SCSITransfer(block_number, 1,(u8*)buffer,_blockSize,HOST_TO_DEVICE);
//return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
}
virtual int disk_read(char *buffer, int block_number)
{
return SCSITransfer(block_number, 1, (u8*)buffer, _blockSize, DEVICE_TO_HOST);
//return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
}
virtual int disk_sectors()
{
return _blockCount;
}
};
void DumpFS(int depth, int count)
{
DIR *d = opendir("/usb");
if (!d)
{
printf("USB file system borked\n");
return;
}
printf("\nDumping root dir\n");
struct dirent *p;
for(;;)
{
p = readdir(d);
if (!p)
break;
int len = sizeof( dirent);
printf("%s %d\n", p->d_name, len);
}
closedir(d);
}
int OnDiskInsert(int device, unsigned char in, unsigned char out)
{
USBFileSystem fs;
fs.SetDevice(device, in, out);
DumpFS(0,0);
return 0;
}
<</code>>
Dude,
You are insane! This is really great work!!
Magnificent! :D
/ Lerche