LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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
  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 6, KDE Neon
Posts: 4,313

Rep: Reputation: 212Reputation: 212Reputation: 212
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



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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 05:54 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration