Thread: Need drives information on linux

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    15

    Need drives information on linux

    hi all,
    I need information regarding the Drives on linux, just like the information provided by ::GetLogicalDrives & ::GetDriveType on Windows.
    Please help me out if u have any idea, basically I need to detect USB drive,
    also if anyone has any idea of about how to register my task, so as I can get the information(signal) when a pen drive is attached/detached(I need to do some task on the basis of this).

    Thanks in advance,
    Amit Sahrawat

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    For detecting USB devices, you need to look up "Linux Hotplug" in google.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    For finding out what drives are actually mounted, where, which devices, which filesystem and what options, parse /proc/mounts.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    15
    I need some point in my task where I can get messages like whether device is added/removed. On each addition/removed I need to keep track of these devices and browse them.
    So, how do we do that here?

    Thanks
    Amit Sahrawat

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by amit_sahrawat View Post
    I need some point in my task where I can get messages like whether device is added/removed. On each addition/removed I need to keep track of these devices and browse them.
    So, how do we do that here?
    Poll the /proc directory at some sane interval and watch for things being added/removed.

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    15
    Some how I am not getting any entry in /proc/bus/usb, I am plugging in USB hub device with once CARD. So, I suppose I should get an entry into that...
    and I am not able to understand the /sys/bus/usb/devices/ things

    OR the entry would be some where else?

    Thanks,
    Amit Sahrawat

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    15
    Now I have plugged in my Pen drive, but there is still no entry in /proc/bus/usb...

    But, I got something which might be useful...
    /sys/block/sda/

    An entry gets created each time(addition) under /sys/block/sda, and all the details related with the device are available here, but still auto mounting does not happen.

    Removing the pen drive the entry gets deleted.

    Thanks
    Amit Sahrawat

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Do you want to get "it's_plugged_in"-events or do you need "it's_mounted_events"?
    In the latter case you have to check, if your usb stick file system really gets mounted. therefore just type mount[enter] in a root shell. mounting will create the /proc/mounts entries. if your stick doesn't get auto mounted you'll probably want to google for "automounting linux" or something like that. the /sys/-entries get created while the kernel detects if your device gets plugged in. After doing so you can also check the kernel message buffer with dmesg[enter] to see what the kernel detects.

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    15
    anyways I would have to somehow create a listener thread on /sys/block and look out for the 'removable=1' option to get the the removable drives, rest I need to look further...

    neways thanks..

    Regards,
    Amit Sahrawat

  10. #10
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    just fork a `df` command and parse the output of that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  2. Port app from Windows to Linux
    By BobS0327 in forum Linux Programming
    Replies: 12
    Last Post: 02-12-2006, 02:35 AM
  3. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  4. Which distribution of Linux should I get?
    By joshdick in forum A Brief History of Cprogramming.com
    Replies: 50
    Last Post: 01-19-2003, 09:26 AM
  5. linux vs linux?
    By Dreamerv3 in forum Linux Programming
    Replies: 5
    Last Post: 01-22-2002, 09:39 AM