linux(ubuntu)下怎样检测U盘的插入
u盘插入那个文件会发生变化,如何知道U盘是哪个盘符?然后读取它
30 个解决方案
#1
/proc/scsi/usb-storage-0/0
Attached: Yes or No
Attached: Yes or No
#2
我是来围观地,这个问题貌似还要装那啥啥啥的~
#3
命令: lsusb
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 0a81:0101 Chesen Electronics Corp. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 148f:3370 Ralink Technology, Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
这个里面可以查看
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 0a81:0101 Chesen Electronics Corp. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 148f:3370 Ralink Technology, Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
这个里面可以查看
#4
用C语言实现吗?
#5
是的 libusb
#6
/proc/scsi/usb-storage-0/0 vi这个文件怎么是空的
#7
查看文件系统应该可以查到吧,只是木有挂载点.
#8
我要查看插入的盘符是什么,然后才能读取里面的文件
#9
fdisk -l 就可以查看到设备文件名,然后直接挂载到某个目录下就可以了。
我的移动硬盘是NTFS的,系统识别不了。。。
我的移动硬盘是NTFS的,系统识别不了。。。
#10
fdisk -l 列出那么多
如何知道哪个是U盘?
#11
fdisk -l 查看不了u盘
#12
命令: lsusb
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 0a81:0101 Chesen Electronics Corp. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 148f:3370 Ralink Technology, Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
这个里面怎么知道那个是U盘,使用程序判断的,非肉眼
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 0a81:0101 Chesen Electronics Corp. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 148f:3370 Ralink Technology, Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
这个里面怎么知道那个是U盘,使用程序判断的,非肉眼
#13
fdisk -l 看文件系统是FAT32的。。
#14
那还是找不到U盘啊
#15
到sysfs里找找吧,,顺便给给链接http://blog.csdn.net/fudan_abc/category/332148.aspx
#16
其实就是usb的枚举,什么os都差不多
#17
还是找不到u盘的盘符,
#18
ls /sys/bus/usb/devices/
#19
不知道你要实现什么功能
#20
ubuntu里面有一个自动挂载的程序,你可以看看它是怎么弄的。
#21
就是实现检测u盘插入,马上读取里面的文件
#22
Linux不支持NTFS,要安装驱动的,FAT32可以识别。
#23
安装个啥就能支持了 具体google
#24
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.
更高级的方法是用libudev访问内核的udev,udev_monitor可以用来监视设备插入/拔出事件。
http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/
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.
更高级的方法是用libudev访问内核的udev,udev_monitor可以用来监视设备插入/拔出事件。
http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/
#25
如果26l的方法失败的话,可以尝试dbus
还是推荐使用udev,dbus较udev底层些。
还是推荐使用udev,dbus较udev底层些。
#26
udev是基于sysfs文件系统的,现在大多数arm
开发板都是yaffs2文件系统的,所以hotplug还是最佳选择。整个消息传送是内核---》hotplug-----》udev-----》dbus 你说哪个底层??
开发板都是yaffs2文件系统的,所以hotplug还是最佳选择。整个消息传送是内核---》hotplug-----》udev-----》dbus 你说哪个底层??
#27
这个是针对2.4内核的,2.6以后就不能用这个方法了。
#1
/proc/scsi/usb-storage-0/0
Attached: Yes or No
Attached: Yes or No
#2
我是来围观地,这个问题貌似还要装那啥啥啥的~
#3
命令: lsusb
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 0a81:0101 Chesen Electronics Corp. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 148f:3370 Ralink Technology, Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
这个里面可以查看
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 0a81:0101 Chesen Electronics Corp. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 148f:3370 Ralink Technology, Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
这个里面可以查看
#4
用C语言实现吗?
#5
是的 libusb
#6
/proc/scsi/usb-storage-0/0 vi这个文件怎么是空的
#7
查看文件系统应该可以查到吧,只是木有挂载点.
#8
我要查看插入的盘符是什么,然后才能读取里面的文件
#9
fdisk -l 就可以查看到设备文件名,然后直接挂载到某个目录下就可以了。
我的移动硬盘是NTFS的,系统识别不了。。。
我的移动硬盘是NTFS的,系统识别不了。。。
#10
fdisk -l 列出那么多
如何知道哪个是U盘?
#11
fdisk -l 查看不了u盘
#12
命令: lsusb
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 0a81:0101 Chesen Electronics Corp. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 148f:3370 Ralink Technology, Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
这个里面怎么知道那个是U盘,使用程序判断的,非肉眼
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 0a81:0101 Chesen Electronics Corp. Keyboard
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 148f:3370 Ralink Technology, Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
这个里面怎么知道那个是U盘,使用程序判断的,非肉眼
#13
fdisk -l 看文件系统是FAT32的。。
#14
那还是找不到U盘啊
#15
到sysfs里找找吧,,顺便给给链接http://blog.csdn.net/fudan_abc/category/332148.aspx
#16
其实就是usb的枚举,什么os都差不多
#17
还是找不到u盘的盘符,
#18
ls /sys/bus/usb/devices/
#19
不知道你要实现什么功能
#20
ubuntu里面有一个自动挂载的程序,你可以看看它是怎么弄的。
#21
就是实现检测u盘插入,马上读取里面的文件
#22
Linux不支持NTFS,要安装驱动的,FAT32可以识别。
#23
安装个啥就能支持了 具体google
#24
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.
更高级的方法是用libudev访问内核的udev,udev_monitor可以用来监视设备插入/拔出事件。
http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/
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.
更高级的方法是用libudev访问内核的udev,udev_monitor可以用来监视设备插入/拔出事件。
http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/
#25
如果26l的方法失败的话,可以尝试dbus
还是推荐使用udev,dbus较udev底层些。
还是推荐使用udev,dbus较udev底层些。
#26
udev是基于sysfs文件系统的,现在大多数arm
开发板都是yaffs2文件系统的,所以hotplug还是最佳选择。整个消息传送是内核---》hotplug-----》udev-----》dbus 你说哪个底层??
开发板都是yaffs2文件系统的,所以hotplug还是最佳选择。整个消息传送是内核---》hotplug-----》udev-----》dbus 你说哪个底层??
#27
这个是针对2.4内核的,2.6以后就不能用这个方法了。