linuxlinux-device-driverusb-drive

Determine if a usb is mounted using lsusb data


I'm trying to identify if a USB storage device (USB stick) is mounted or not on a Linux distro (modified Ubuntu 10.04). At the moment I use the lsusb -v command and parse it to obtain the Bus, Device and ID of the USB device I'm interested in.

Bus:001 DEVICE:008 ID 0781:5560 SanDisk Corp. . . .

What I ideally want is to be able to use the data I get from lsusb -v to determine if that USB has been mounted or not.

I've never really fiddled in this area before (it's kind of just ended up in my lap) any pointers would be appreciated. I've looked on here and other sites and learnt some interesting things but nothing that really gets me any closer. I can see in /proc/mount that the usb is mounted but can't match the info I get for the device with lsusb with what I get in cat /proc/mount, as this will form part of an application I need to be able to match one with another.

FYI: The application is written in Python and I'm under the constraint of not being able to use external libraries such as pyUSB. As I say any pointers/help would be greatly appreciated.

Cheers


Solution

  • My suggestion would be to use lsusb in conjunction with the dmesg command to determine if the USB device is mounted.

    Here' a sample output from lsusb and dmesg from my Ubuntu machine. The output from dmesg includes the device number and product/vendor information reported by lsusb

    dbala@ubuntu:~$ lsusb
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
    Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
    Bus 001 Device 005: ID 0781:5530 SanDisk Corp. Cruzer U3 4gb SDCZ36
    
    dbala@ubuntu:~$ dmesg | tail
    [1084707.969418] usb 1-1: new high speed USB device number 5 using ehci_hcd
    [1084708.119662] scsi5 : usb-storage 1-1:1.0
    [1084709.120841] scsi 5:0:0:0: Direct-Access     SanDisk  Cruzer           1.19 PQ: 0   ANSI: 5
    [1084709.125158] sd 5:0:0:0: Attached scsi generic sg2 type 0
    [1084709.130677] sd 5:0:0:0: [sdb] 31266816 512-byte logical blocks: (16.0 GB/14.9 GiB)
    [1084709.138819] sd 5:0:0:0: [sdb] Write Protect is off
    [1084709.138821] sd 5:0:0:0: [sdb] Mode Sense: 43 00 00 00
    [1084709.146812] sd 5:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
    [1084709.186467]  sdb: sdb1
    [1084709.215365] sd 5:0:0:0: [sdb] Attached SCSI removable disk
    dbala@ubuntu:~$