LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-29-2008, 08:09 AM   #1
poomas
LQ Newbie
 
Registered: Apr 2008
Posts: 1

Rep: Reputation: 0
Linux API to find out the number of USB disks connected to the machine and the files


Hi,

I have to write a Linux Program to write a file to USB disks connected to a machine.

Steps:
->Find out the number of USB disks connected to the machine and the filesystem/partition corresponding to the USB disks
->Mount all the USB disks
->Write the file

I have followed the following approach:

-> dmesg | grep 'removable disk'

The output will be as follows:

“Attached scsi removable disk sdb at scsi8, channel 0, id 0, lun 0”

From this take out fifth field to get the Device name(sda) of Usb disk

-> From /proc/partitions file get the corresponding filesystem name say "/dev/sdb1"

But, I got to know that “dmesg” output may sometimes have different formats(?) and its better to use any available standard Linux API.

The APIs with Libusb library are used to find out the details of USB disk such as bus-name/device-name , device-id/product-id, manufacturer etc.,
I didnt find any API to find out the Usb disk filesystem.

Is there any API or any other standard way for doing this?

Thanks,
Poomathi
 
Old 04-29-2008, 08:55 AM   #2
fancylad
Member
 
Registered: Mar 2008
Distribution: slackware
Posts: 175

Rep: Reputation: 19
Is this program just for your machine, or is it supposed to be portable? I'm not a programmer so I can't help you with any libraries or functions, but I'm you want to know the filesystem on an unmounted device use either fdisk or sfdisk.

Quote:
matt@matt-laptop:~$ /sbin/fdisk -l /dev/sda

Disk /dev/sda: 1998 MB, 1998585856 bytes
16 heads, 32 sectors/track, 7624 cylinders
Units = cylinders of 512 * 512 = 262144 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 7624 1951728 e W95 FAT16 (LBA)
This will tell you the partition type which should be the same as the file system format.
 
Old 04-29-2008, 10:04 AM   #3
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,425

Rep: Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159
The general approach would be to execute a suitable command (mount, perhaps?), pipe its output and grep it to extract the meaningful lines. Then pipe that output to the next stage whatever-it-is.

Or perhaps you want to read "/etc/fstab" which gives a list of all the filesystems that could be mounted.

General-purpose scripting languages like Perl, Python and PHP are commonly used for these tasks. "Shell scripting" can be used too, but with these other more-powerful tools at your beck and call I see little reason to do so.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Find out number of users connected to my sftp server procfs Linux - Newbie 5 01-10-2008 11:47 PM
Find out the number of files currently opened closet geek Linux - Kernel 4 12-22-2006 02:45 PM
cannot find usb port of my connected printer kpachopoulos Debian 1 08-10-2006 08:29 AM
Find Serial Number of Machine zael Programming 4 10-27-2003 01:39 PM
how do i find number of cpus in one machine? doublefailure Linux - General 3 03-26-2002 03:52 PM


All times are GMT -5. The time now is 04:28 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