/******************************************************************************* * 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; }
void usb_fs_mount(UINT32 nodeid) { int result = -EIO; int hdd_ns = 0; int vol_ns = 0; int i = 0; int j = 0; char dirbuf[sizeof(struct dirent) + 32]; struct dirent *dire = (struct dirent *)dirbuf; char dev_name[16], vol_name[16]; int fd; struct stat st; int devid; UINT32 msg_code = 0; INT32 lun_num; lun_num = usb_get_max_lun(nodeid); #ifdef USB_SUPPORT_HUB struct fs_sto_param fs_param; fs_param.type = MNT_TYPE_USB; fs_param.id = 0; fs_param.partition_id = 0; #endif FS_PRINTF("USB lun_num = %d\n", lun_num); //firstly create all the device and partitions for( i = 0; i< lun_num; ++i) { if(usb_check_lun_ready(nodeid, i)) { result = usb_dev_fs_init(nodeid, i); if(result == 0) { /* usb hdd is ready, we should send message to UI */ int hdd_vol_ns = 0; // how many volume of this hdd mount success hdd_ns++; //loop the /dev try to mount all the device devid = usb_hdd_get_dev(nodeid, i); #ifdef USB_SUPPORT_HUB fs_param.id = devid; #endif fd = fs_opendir("/dev"); while(fs_readdir(fd, dire) > 0) { fs_get_mount_name(MNT_TYPE_USB, devid, 0, dev_name); if((STRLEN(dire->d_name) == 4) && !MEMCMP(&dire->d_name, &dev_name[5], 3)) { STRCPY(dev_name, "/dev/"); strcat(dev_name, dire->d_name); STRCPY(vol_name, "/mnt/"); strcat(vol_name, dire->d_name); //mount the device result = mount_device(dev_name, vol_name); if(result >= 0) { link_device(vol_name, "/c"); #if (SYS_CHIP_MODULE != ALI_S3602) link_device(vol_name, "/r"); #endif vol_ns++; hdd_vol_ns++; #if (defined(FS_MAX_USB_VOLUME_SUPPORT)) if (hdd_vol_ns >= FS_MAX_USB_VOLUME_SUPPORT) break; #elif ((SYS_SDRAM_SIZE == 64) && (defined(M36F_CHIP_MODE)||defined(S3811_CHIP_MODE))) if (hdd_vol_ns >= 4) break; #endif } } } fs_closedir(fd); #if (SYS_CHIP_MODULE == ALI_S3602) int mnt_status = (hdd_vol_ns > 0) ? MNT_MOUNT_OK : MNT_FAILED; #ifdef USB_SUPPORT_HUB FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(mnt_status, fs_param.type, fs_param.id)); #else FS_NOTICE_MESSAGE(MP_FS_MOUNT, MNT_MSG_PARAM(mnt_status, MNT_TYPE_USB, 0)); #endif #endif } else { FS_PRINTF("device lun = %d init failed! err = %d\n", i, result); } } } if(hdd_ns == 0) { FS_PRINTF("all the device are inited failed!\n"); #if (SYS_CHIP_MODULE != ALI_S3602) #ifdef USB_SUPPORT_HUB fs_param.msg_code = MNT_NO_PARTITION; msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code; #else msg_code = 11; #endif FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code); #endif return; } if(vol_ns == 0) { FS_PRINTF("fs mount failed!\n"); #if (SYS_CHIP_MODULE != ALI_S3602) #ifdef USB_SUPPORT_HUB fs_param.msg_code = MNT_FAILED; msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code; #else msg_code = 1; #endif FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code); #endif return; } #if (SYS_CHIP_MODULE != ALI_S3602) #ifdef USB_SUPPORT_HUB fs_param.msg_code = MNT_MOUNT_OK; msg_code = fs_param.type<<24 | fs_param.id<<16 | fs_param.partition_id<<8 | fs_param.msg_code; #else msg_code = 3; #endif FS_NOTICE_MESSAGE(MP_FS_MOUNT, msg_code); #endif return; }