Example #1
0
s32 USBStorage_Write_Sectors(int device, u32 sector, u32 numSectors, const void *buffer) {
	s32 retval = 0;
	int retry;
	
	if (_ehci_data[device].__mounted != 1)
		return FALSE;

	for (retry = 0; retry < 16; retry++) {
		if (retry > 12) retry = 12; // infinite loop

		//ehci_usleep(100);

		if (!unplug_procedure(device)) {
			retval = 0;
		}

		if (retval == USBSTORAGE_ETIMEDOUT && retry > 0) {
			unplug_device = 1;
			//retval=__usbstorage_reset(&__usbfd,1);
			//if(retval>=0) retval=-666;
		}
		if (unplug_device != 0) continue;
		usb_timeout = 1000 * 1000; // 4 seconds to wait
		if (retval >= 0)
			retval = USBStorage_Write(_ehci_data[device].__ehci, &_ehci_data[device].__usbfd, _ehci_data[device].__lun, sector, numSectors, buffer);
		usb_timeout = 1000 * 1000;
		if (unplug_device != 0) continue;
		if (retval >= 0) break;
	}

	if (retval < 0)
		return FALSE;
	return TRUE;
}
Example #2
0
static bool __usbstorage_WriteSectors(u32 sector, u32 numSectors, const void *buffer)
{
	s32 retval;

	if (!__mounted)
		return false;

	retval = USBStorage_Write(&__usbfd, __lun, sector, numSectors, buffer);

	return retval >= 0;
}
s32 USBStorage_Write_Sectors(u32 sector, u32 numSectors, const void *buffer)
{
    s32 retval;
    
    if(__mounted != 1)
        return false;
    
    retval = USBStorage_Write(&__usbfd, __lun, sector, numSectors, buffer);
    if(retval == USBSTORAGE_ETIMEDOUT)
    {        __mounted = 0;
        USBStorage_Close(&__usbfd);
    }
    if(retval < 0)
        return false;
    return true;
}