• PF_NETLINK类型建立的socket, 检测USB口


    摘自:https://blog.csdn.net/wandersky0822/article/details/110202371

    通过使用PF_NETLINK类型建立的socket, 确实能检测到USB口的变化,这个东西太好了,做U盘自动检测,自动挂载就靠它了。 眼前豁然开朗

    当插入U盘时,打印如下信息:

    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2
    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0

    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35
    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/scsi_host/host35
    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0
    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0

    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/scsi_disk/35:0:0:0
    bind@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0
    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/scsi_generic/sg2
    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/bsg/35:0:0:0
    add@/devices/virtual/bdi/8:48
    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/block/sdd
    add@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/block/sdd/sdd1

    当拨出U盘时,打印如下信息:
    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/bsg/35:0:0:0

    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/scsi_generic/sg2
    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/scsi_device/35:0:0:0

    remove@/devices/virtual/bdi/8:48
    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0/block/sdd
    unbind@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0/35:0:0:0
    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/target35:0:0
    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35/scsi_host/host35
    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0/host35
    unbind@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0
    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2/3-2:1.0
    unbind@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2
    remove@/devices/pci0000:00/0000:00:15.0/0000:03:00.0/usb3/3-2
    在电脑虚拟机上可以用, 但是在我的树莓派上却用不了,我怀疑怀疑还是系统的原因,因此采用这种高大上的办法好像适用性不是很广泛, 

    于是我又老实了把 检测access  /dev/sda1 节点, 检测到之后,再挂载的办法,也实现了。还是这个办法保险。

  • 相关阅读:
    使用XUACompatible来设置IE8兼容模式[转]
    XML Sitemaps 格式
    A Link 链接的rel、target属性详解
    IE与Firefox等浏览器对容器width的不同解释及解决办法
    超越文档类型,web标准化向前兼容和IE8
    MSSQL、MYSQL,ACCESSl,Oracle随机读取N条记录方法
    IE8如何定义浏览器工作模式避免网页显示混乱
    什么是SVN? 什么是CVS? SVN跟CVS又有什么关系呢?
    2008年度75套最佳网页设计资源
    一组JS创建和操作表格的函数集合
  • 原文地址:https://www.cnblogs.com/LiuYanYGZ/p/14595727.html
Copyright © 2020-2023  润新知