LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices

Reply
 
LinkBack Search this Thread
Old 10-30-2008, 04:34 AM   #1
ebinjose
LQ Newbie
 
Registered: Jan 2008
Posts: 14

Rep: Reputation: 0
how to get the device ID of a USB mass storage device


Hi,

I need to mount a USB mass storage device (a memory stick) on to my linux.
from the output of "dmesg" I can see the device name/node is "sdb1".

At different times, when I inserted different USB drives, on different linux PCs I have seen this name in different ways. Sometimes its "sda" sometimes "sda1" etc.

My requirement is I should be able to mount the USB device from "C" program using the mount system call ie.

int mount(const char *source, const char *target, const char *filesystemtype,
unsigned long mountflags, const void *data);

So I need the device name/node everytime.

1) My question is say I hardcoded the device name as "sdb1" after reading the output of "dmesg" manually. Is the name going to be same everytime.
I may be using a different USB device etc.

2) Or is there a way to get the device name dynamically by invoking some linux system call, so that at startup I check this and mount accordingly.

Thanks in advance.
Ebin.
 
Old 10-30-2008, 05:58 AM   #2
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 3 / CrunchBang Linux 10 Statler / Easy Peasy
Posts: 4,293

Rep: Reputation: 205Reputation: 205Reputation: 205
The command lsusb will show you the device id. Depending on your system you may be able to run that command without having to be root first. Try:
Code:
lsusb
or
Code:
/usr/sbin/lsusb
as a normal user. If both fail switch to root and do:
Code:
lsusb
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mass storage device USB xeebeeeeeee Linux - Hardware 10 02-13-2008 12:11 PM
USB Mass storage Device purefan Linux - Hardware 15 06-06-2005 01:56 PM
usb - mass storage device d1l2w3 Mandriva 7 01-10-2005 10:10 PM
USB Mass Storage Device ebasi Linux - Hardware 2 12-23-2004 02:06 PM
Usb mass storage device laguna Linux - Hardware 4 08-12-2002 02:16 AM


All times are GMT -5. The time now is 06:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration