コード例 #1
0
ファイル: usbstorage.c プロジェクト: AirBrowse/libxenon
s32 USBStorage_Read_Sectors(int device, u32 sector, u32 numSectors, 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;
			ehci_msleep(10);*/
		}
		if (unplug_device != 0) continue;
		//if(retval==-ENODEV) return 0;
		usb_timeout = 1000 * 1000; // 4 seconds to wait
		if (retval >= 0)
			retval = USBStorage_Read(_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==-ENODEV) return 0;
		if (retval >= 0) break;
	}

	if (retval < 0)
		return FALSE;
	return TRUE;
}
コード例 #2
0
ファイル: usbstorage.c プロジェクト: MANICX100/wiimc
static bool __usbstorage_ReadSectors(u32 sector, u32 numSectors, void *buffer)
{
	s32 retval;

	if (!__mounted)
		return false;

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

	return retval >= 0;
}
コード例 #3
0
s32 USBStorage_Read_Sectors(u32 sector, u32 numSectors, void *buffer)
{
    s32 retval;
    
    if(__mounted != 1)
        return false;
    
    retval = USBStorage_Read(&__usbfd, __lun, sector, numSectors, buffer);
    if(retval == USBSTORAGE_ETIMEDOUT)
    {
        __mounted = 0;
        USBStorage_Close(&__usbfd);
    }
    if(retval < 0)
        return false;
    return true;
}
コード例 #4
0
/* perform 512 time the same read */
s32 USBStorage_Read_Stress(u32 sector, u32 numSectors, void *buffer)
{
    s32 retval;
    int i;
    if(__mounted != 1)
        return false;
    
    for(i=0;i<512;i++){
        retval = USBStorage_Read(&__usbfd, __lun, sector, numSectors, buffer);
        sector+=numSectors;
        if(retval == USBSTORAGE_ETIMEDOUT)
        {
            __mounted = 0;
            USBStorage_Close(&__usbfd);
        }
        if(retval < 0)
            return false;
    }
    return true;
    
}
コード例 #5
0
ファイル: usbstorage.c プロジェクト: AirBrowse/libxenon
/* perform 512 time the same read */
s32 USBStorage_Read_Stress(u32 sector, u32 numSectors, void *buffer) {
	s32 retval;
	int i;
	
	ehci_device_data * device_data = find_ehci_data(ehci);
	
	if (__mounted != 1)
		return FALSE;

	for (i = 0; i < 512; i++) {
		retval = USBStorage_Read(__ehci, &__usbfd, __lun, sector, numSectors, buffer);
		sector += numSectors;
		if (retval == USBSTORAGE_ETIMEDOUT) {
			__mounted = 0;
			USBStorage_Close(&__usbfd);
		}
		if (retval < 0)
			return FALSE;
	}
	return TRUE;

}
コード例 #6
0
ファイル: usbstorage.c プロジェクト: MANICX100/wiimc
static bool __usbstorage_IsInserted(void)
{
	usb_device_entry *buffer;
	u8 device_count;
	u8 i, j;
	u16 vid, pid;
	s32 maxLun;
	s32 retval;

#ifdef DEBUG_USB		
	usb_log("__usbstorage_IsInserted\n");
	if(__mounted)
		usb_log("device previously mounted.\n");
#endif

	if(__mounted)
		return true;

	if(!__inited)
		return false;

	buffer = (usb_device_entry*)__lwp_heap_allocate(&__heap, DEVLIST_MAXSIZE * sizeof(usb_device_entry));
	if (!buffer)
		return false;

	memset(buffer, 0, DEVLIST_MAXSIZE * sizeof(usb_device_entry));

	if (USB_GetDeviceList(buffer, DEVLIST_MAXSIZE, USB_CLASS_MASS_STORAGE, &device_count) < 0)
	{
		if (__vid != 0 || __pid != 0)
			USBStorage_Close(&__usbfd);

		__lwp_heap_free(&__heap, buffer);
		usb_log("Error in USB_GetDeviceList\n");
		return false;
	}

	usleep(100);

	if (__vid != 0 || __pid != 0) {
		for(i = 0; i < device_count; i++) {
			vid = buffer[i].vid;
			pid = buffer[i].pid;
			if(vid != 0 || pid != 0) {
				if((vid == __vid) && (pid == __pid)) {
					__mounted = true;
					__lwp_heap_free(&__heap,buffer);
					usleep(50); // I don't know why I have to wait but it's needed
					return true;
				}
			}
		}
		USBStorage_Close(&__usbfd);  // device changed or unplugged, return false the first time to notify to the client that he must unmount devices
		__lwp_heap_free(&__heap,buffer);
		usb_log("USB_GetDeviceList. device_count: %i\n",device_count);
		return false;
	}
	usb_log("USB_GetDeviceList. device_count: %i\n",device_count);
	for (i = 0; i < device_count; i++) {
		vid = buffer[i].vid;
		pid = buffer[i].pid;
		if (vid == 0 || pid == 0)
			continue;

		if (USBStorage_Open(&__usbfd, buffer[i].device_id, vid, pid) < 0)
		{
			usb_log("Error USBStorage_Open (%i,%i)\n",vid, pid);
			continue;
		}

		maxLun = USBStorage_GetMaxLUN(&__usbfd);
		usb_log("GetMaxLUN: %i\n",maxLun);
		for (j = 0; j < maxLun; j++) {
			retval = USBStorage_MountLUN(&__usbfd, j);
			if(retval<0)
				usb_log("Error USBStorage_MountLUN(%i): %i\n",j,retval);
			else
				usb_log("USBStorage_MountLUN(%i) Ok\n",j);
			//if (retval == USBSTORAGE_ETIMEDOUT)
			//	break;

			if (retval < 0)
			{
				__usbstorage_reset(&__usbfd);
				continue;
			}

			__mounted = true;
			__lun = j;
			__vid = vid;
			__pid = pid;
			usb_last_used = gettime()-secs_to_ticks(100);
			usleep(100);
#ifdef DEBUG_USB
			{
				u8 bf[2048];
				if(USBStorage_Read(&__usbfd, __lun, 0, 1, bf)<0)
				{
					usb_log("Error reading sector 0\n");
					USBStorage_Close(&__usbfd);
					return false;
				}
				else
					usb_log("Read sector 0 ok\n");
			}
#endif
			break;
		}

		if (__mounted)
			break;

		USBStorage_Close(&__usbfd);
	}
	__lwp_heap_free(&__heap, buffer);
	return __mounted;
}