1. check if /proc/scsi/usb-storage-# exist or not
2. if exist. check if /proc/scsi/usb-storage-#/# exist or not
3. if exist. check the file /proc/scsi/usb-storage-#/# if it says Attach: Yes
4. if Yes. the # can be converted to device name:
0 = sda, 1=sdb, 2=sdc
5. But I don't know which USB port it connects to. and you don't need to know also.
for example: /proc/scsi/usb-storage-0/0 says Attach: No, then /dev/sda is not attached
/proc/scsi/usb-storage-1/1 says Attach: Yes, then it is attached, you can mount it.
If you plug in usb storage with brandname A first, the it is
usb-storage-0, then you unplug it, but that directory still exists, and
now you plug in Brandname B, the storage-1 directory will be created,
and storage-0 is still there.
linux 2.6
http://blog.chinaunix.net/u2/72751/showart_1082492.html 待研究
本文介绍了一种在Linux 2.6系统中检测USB存储设备的方法。通过检查/proc/scsi/usb-storage-#目录的存在与否及Attach状态来判断USB设备是否连接。如果Attach为Yes,则说明设备已连接并可根据编号转换成设备名如sda、sdb等。
394

被折叠的 条评论
为什么被折叠?



