Find the answer to your Linux question:
Results 1 to 3 of 3
Hi I'm developing a little script that automatically detects the insertion of a usb device and tries to open the directory of this device in nautilus. I am using Python ...
  1. #1
    Just Joined!
    Join Date
    Mar 2010
    Posts
    1

    finding the mount point of a particular usb device

    Hi

    I'm developing a little script that automatically detects the insertion of a usb device and tries to open the directory of this device in nautilus. I am using Python

    So far I was able to sample and compare the changes that occur in the output of 'lsusb' command and get information pertaining to the addition and removal of usb devices.

    Now I want to know if we can use that information (or some other info present in the usb sybsyste -- /sys/bus/usb folder) to determine exactly where this device has been mounted.

    I know you might recommend using 'mount' as a quick way to do the same. I have already done that, but the limitation is that mount only gives u the mountpoint information. How does one (using a program/logic) determine which mount point corresponds to which device.

    If I were to plug in two devices together, and both were automatically mounted, how will I be able to tell which mountpoint corresponded to which device? the output of lsusb provides no information whatsoever about where the device is mounted. So its kind of a deadlock

    from lsusb ive been able to gather : Device name, serial and bus number and device number

    Another thing i've noticed is the 'autoplay'. Whenever I insert a my music player into my computer, it gets mounted automatically and I'm presented with options about simply opening the file or playing it with rhythmbox... now if all that was being done was polling the output of mount, they would not be able to know that the device inserted was a music player (that info u can get from the /sys/bus/usb folder only using the device class and subclass info). So obviously the two are linked somewhere...

    Any help would be greatly appreciated. Thanks
    Asim

  2. #2
    Linux Guru reed9's Avatar
    Join Date
    Feb 2009
    Location
    Boston, MA
    Posts
    4,651
    I don't know anything about programming, so I can't give you details.

    But, very basically, the process goes as so:
    Device is plugged in and recognized by the kernel;
    Udev creates a device node, ie, /dev/sdc1 or whatever it is;
    The HAL Daemon is notified via D-Bus and adds info to its database;
    HAL broadcasts the addition of the new device via D-Bus;
    Listening programs can take action based on that info, such as offering to launch rhythmbox for you.

    But to complicate things, HAL is being deprecated. I believe Ubuntu 10.04 will have removed it altogether. It's functionality is being replaced by udev and udisks (formerly devicekit-disks).

    I know you can create udev rules for custom mount points, so that might be a key. Good info here:
    Udev - ArchWiki

    D-Bus and Python
    dbus-python tutorial

    freedesktop.org - Software/DeviceKit
    freedesktop.org - Software/udisks

  3. #3
    Just Joined! Leppie's Avatar
    Join Date
    Feb 2010
    Posts
    72
    if i plug in a usb stick and check my dmesg, i get:
    Code:
    [49512.689033] usb 2-5: new high speed USB device using ehci_hcd and address 9
    [49512.823772] usb 2-5: configuration #1 chosen from 1 choice
    [49512.849453] scsi11 : SCSI emulation for USB Mass Storage devices
    [49512.854828] usb-storage: device found at 9
    [49512.854831] usb-storage: waiting for device to settle before scanning
    [49517.852293] usb-storage: device scan complete
    [49517.855295] scsi 11:0:0:0: Direct-Access     USB 2.0  USB Flash Drive  1.00 PQ: 0 ANSI: 2
    [49517.856270] sd 11:0:0:0: Attached scsi generic sg3 type 0
    which seems to be related with the lsusb output:
    Code:
    Bus 002 Device 009: ID 1043:8012 iCreate Technologies Corp.
    and the contents of the /sys/bus/usb folder.

    this thread might be useful: How to automount USB pendrive and CD/DVD, using udev/HAL/D-BUS | debianHELP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...