コード例 #1
0
ファイル: usb_storage.c プロジェクト: Analias/SNOWLeo-SDR-1
/*******************************************************************************
 * scan the usb and reports device info
 * to the user if mode = 1
 * returns current device or -1 if no
 */
int usb_stor_scan(int mode)
{
	unsigned char i;
	struct usb_device *dev;

	if (mode == 1)
		printf("       scanning bus for storage devices... ");

	usb_disable_asynch(1); /* asynch transfer not allowed */

	for (i = 0; i < USB_MAX_STOR_DEV; i++) {
		memset(&usb_dev_desc[i], 0, sizeof(block_dev_desc_t));
		usb_dev_desc[i].if_type = IF_TYPE_USB;
		usb_dev_desc[i].dev = i;
		usb_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
		usb_dev_desc[i].target = 0xff;
		usb_dev_desc[i].type = DEV_TYPE_UNKNOWN;
		usb_dev_desc[i].block_read = usb_stor_read;
		usb_dev_desc[i].block_write = usb_stor_write;
	}

	usb_max_devs = 0;
	for (i = 0; i < USB_MAX_DEVICE; i++) {
		dev = usb_get_dev_index(i); /* get device */
		USB_STOR_PRINTF("i=%d\n", i);
		if (dev == NULL)
			break; /* no more devices available */

		if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
			/* OK, it's a storage device.  Iterate over its LUNs
			 * and populate `usb_dev_desc'.
			 */
			int lun, max_lun, start = usb_max_devs;

			max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]);
			for (lun = 0;
			     lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV;
			     lun++) {
				usb_dev_desc[usb_max_devs].lun = lun;
				if (usb_stor_get_info(dev, &usb_stor[start],
						      &usb_dev_desc[usb_max_devs]) == 1) {
				usb_max_devs++;
		}
			}
		}
		/* if storage device */
		if (usb_max_devs == USB_MAX_STOR_DEV) {
			printf("max USB Storage Device reached: %d stopping\n",
				usb_max_devs);
			break;
		}
	} /* for */

	usb_disable_asynch(0); /* asynch transfer allowed */
	printf("%d Storage Device(s) found\n", usb_max_devs);
	if (usb_max_devs > 0)
		return 0;
	return -1;
}
コード例 #2
0
/*******************************************************************************
 * scan the usb and reports device info
 * to the user if mode = 1
 * returns current device or -1 if no
 */
int usb_stor_scan(int mode)
{
	unsigned char i;
	struct usb_device *dev;

	/* GJ */
	memset(usb_stor_buf, 0, sizeof(usb_stor_buf));

	if (mode == 1)
		printf("       scanning bus for storage devices... ");

	usb_disable_asynch(1); /* asynch transfer not allowed */

	for (i = 0; i < USB_MAX_STOR_DEV; i++) {
		memset(&usb_dev_desc[i], 0, sizeof(block_dev_desc_t));
		usb_dev_desc[i].target = 0xff;
		usb_dev_desc[i].if_type = IF_TYPE_USB;
		usb_dev_desc[i].dev = i;
		usb_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
		usb_dev_desc[i].block_read = usb_stor_read;
		usb_dev_desc[i].block_write = usb_stor_write;
	}

	usb_max_devs = 0;
	for (i = 0; i < USB_MAX_DEVICE; i++) {
		dev = usb_get_dev_index(i); /* get device */
		USB_STOR_PRINTF("i=%d\n", i);
		if (dev == NULL)
			break; /* no more devices avaiable */

		if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
			/* ok, it is a storage devices
			 * get info and fill it in
			 */
			if (usb_stor_get_info(dev, &usb_stor[usb_max_devs],
						&usb_dev_desc[usb_max_devs]) == 1)
				usb_max_devs++;
		}
		/* if storage device */
		if (usb_max_devs == USB_MAX_STOR_DEV) {
			printf("max USB Storage Device reached: %d stopping\n",
				usb_max_devs);
			break;
		}
	} /* for */

	usb_disable_asynch(0); /* asynch transfer allowed */
	printf("%d Storage Device(s) found\n", usb_max_devs);
	if (usb_max_devs > 0)
		return 0;
	return -1;
}