• usb udev


    [root@localhost ~] # udevadm monitor
    monitor will print the received events for:
    UDEV - the event which udev sends out after rule processing
    KERNEL - the kernel uevent

    KERNEL[105.208635] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/bsg/4:0:0:0 (bsg)
    KERNEL[105.208721] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_generic/sg1 (scsi_generic)
    KERNEL[105.208764] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_device/4:0:0:0 (scsi_device)
    KERNEL[105.208836] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_disk/4:0:0:0 (scsi_disk)
    KERNEL[105.209093] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb/sdb4 (block)
    UDEV [105.211112] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/bsg/4:0:0:0 (bsg)
    UDEV [105.212047] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_generic/sg1 (scsi_generic)
    KERNEL[105.213199] remove /devices/virtual/bdi/8:16 (bdi)
    KERNEL[105.213516] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb (block)
    KERNEL[105.213585] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0 (scsi)
    UDEV [105.213641] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_device/4:0:0:0 (scsi_device)
    UDEV [105.213998] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_disk/4:0:0:0 (scsi_disk)
    UDEV [105.214105] remove /devices/virtual/bdi/8:16 (bdi)
    UDEV [105.214980] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb/sdb4 (block)
    UDEV [105.216450] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb (block)
    UDEV [105.217848] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0 (scsi)
    KERNEL[105.221213] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0 (scsi)
    KERNEL[105.221232] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/scsi_host/host4 (scsi_host)
    KERNEL[105.221240] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4 (scsi)
    KERNEL[105.221284] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0 (usb)
    KERNEL[105.221557] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1 (usb)
    UDEV [105.221673] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0 (scsi)
    UDEV [105.221769] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/scsi_host/host4 (scsi_host)
    UDEV [105.221885] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4 (scsi)
    UDEV [105.222110] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0 (usb)
    UDEV [105.222325] remove /devices/pci0000:00/0000:00:14.0/usb2/2-1 (usb)

    KERNEL[128.272086] add /devices/pci0000:00/0000:00:14.0/usb2/2-1 (usb)
    KERNEL[128.283096] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0 (usb)
    KERNEL[128.283566] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4 (scsi)
    KERNEL[128.283617] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/scsi_host/host4 (scsi_host)
    UDEV [128.292000] add /devices/pci0000:00/0000:00:14.0/usb2/2-1 (usb)
    UDEV [128.294367] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0 (usb)
    UDEV [128.296326] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4 (scsi)
    UDEV [128.298073] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/scsi_host/host4 (scsi_host)
    KERNEL[129.311851] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0 (scsi)
    KERNEL[129.311874] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0 (scsi)
    KERNEL[129.311880] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_disk/4:0:0:0 (scsi_disk)
    KERNEL[129.311886] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_device/4:0:0:0 (scsi_device)
    KERNEL[129.311894] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_generic/sg1 (scsi_generic)
    KERNEL[129.311913] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/bsg/4:0:0:0 (bsg)
    KERNEL[129.312405] add /devices/virtual/bdi/8:16 (bdi)
    UDEV [129.312474] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0 (scsi)
    UDEV [129.312773] add /devices/virtual/bdi/8:16 (bdi)
    UDEV [129.312910] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0 (scsi)
    UDEV [129.313439] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_device/4:0:0:0 (scsi_device)
    UDEV [129.313483] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_disk/4:0:0:0 (scsi_disk)
    UDEV [129.313685] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/bsg/4:0:0:0 (bsg)
    UDEV [129.313707] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/scsi_generic/sg1 (scsi_generic)
    KERNEL[129.314981] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb (block)
    KERNEL[129.314993] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb/sdb4 (block)
    UDEV [129.346675] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb (block)
    UDEV [129.374249] add /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/host4/target4:0:0/4:0:0:0/block/sdb/sdb4 (block)

    [10月24 23:38] sdb: sdb4
    [10月24 23:39] usb 2-1: USB disconnect, device number 2
    [ +23.032664] usb 2-1: new SuperSpeed USB device number 3 using xhci_hcd
    [ +0.023654] usb 2-1: New USB device found, idVendor=0951, idProduct=1666
    [ +0.000005] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    [ +0.000003] usb 2-1: Product: DataTraveler 3.0
    [ +0.000003] usb 2-1: Manufacturer: Kingston
    [ +0.000002] usb 2-1: SerialNumber: 0026186645E5F0C078808600
    [ +0.011328] usb-storage 2-1:1.0: USB Mass Storage device detected
    [ +0.000359] scsi host4: usb-storage 2-1:1.0
    [ +1.027962] scsi 4:0:0:0: Direct-Access Kingston DataTraveler 3.0 PQ: 0 ANSI: 6
    [ +0.000176] sd 4:0:0:0: Attached scsi generic sg1 type 0
    [ +0.000207] sd 4:0:0:0: [sdb] 30218842 512-byte logical blocks: (15.5 GB/14.4 GiB)
    [ +0.000144] sd 4:0:0:0: [sdb] Write Protect is off
    [ +0.000000] sd 4:0:0:0: [sdb] Mode Sense: 4f 00 00 00
    [ +0.000142] sd 4:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
    [ +0.002550] sdb: sdb4
    [ +0.000741] sd 4:0:0:0: [sdb] Attached SCSI removable disk

        /* usbreset -- send a USB port reset to a USB device */
    
    #include <stdio.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <sys/ioctl.h>
    
    #include <linux/usbdevice_fs.h>
    
    
    int main(int argc, char **argv)
    {
        const char *filename;
        int fd;
        int rc;
    
        if (argc != 2) {
            fprintf(stderr, "Usage: usbreset device-filename
    ");
            return 1;
        }
        filename = argv[1];
    
        fd = open(filename, O_WRONLY);
        if (fd < 0) {
            perror("Error opening output file");
            return 1;
        }
    
        printf("Resetting USB device %s
    ", filename);
        rc = ioctl(fd, USBDEVFS_RESET, 0);
        if (rc < 0) {
            perror("Error in ioctl");
            return 1;
        }
        printf("Reset successful
    ");
    
        close(fd);
        return 0;
    }
    

    https://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line

  • 相关阅读:
    五大常用算法之三:贪心算法
    五大常用算法之二:动态规划算法
    pycharm最新激活码2020
    pgsql安装 centos自带的9.2.4
    centos 7+ 安装python虚拟环境
    常见HTTP状态码
    python搜索引擎和框架
    中文分词工具jieba的使用
    django分页功能 views与templates
    Django-Celery异步发送激活邮件,以及注意点
  • 原文地址:https://www.cnblogs.com/fangying7/p/7726494.html
Copyright © 2020-2023  润新知