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 |
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:
|
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. |
All times are GMT -5. The time now is 10:45 AM. |