Results 1 to 7 of 7
How can I detect if there are USB sticks on the machine and how is it possible to mount them?
I did use a libusb for detection of MASS_STORAGE_DEVICE but ...
- 07-16-2007 #1Just Joined!
- Join Date
- Oct 2006
- Posts
- 6
detect and mount usb stick with C?
How can I detect if there are USB sticks on the machine and how is it possible to mount them?
I did use a libusb for detection of MASS_STORAGE_DEVICE but it can also be a DVD-Player...not only USB stick... and I still have no idea how to get data from the USB stick??
Please, help!
Thanks in advance.
- 07-16-2007 #2
dmesg -> after plugin
lsusb -> after plugin
cat /etc/fstab
mount /dev/usb -> may be called differently, like /mnt/memory or /media/memory or ...
My system would work if I type: mount /dev/sda1Can't tell an OS by it's GUI
- 07-17-2007 #3
Well, I'm not sure how to go about identifying a USB stick with libusb, unfortunately. Maybe someone else will have thoughts on that.
Anyway, once you have identified it, you can use the mount() function. Check "man 2 mount" for the documentation on it. Once it's mounted, you can access the data just as you would any file.DISTRO=Arch
Registered Linux User #388732
- 07-17-2007 #4Just Joined!
- Join Date
- Oct 2006
- Posts
- 6
This is the problem
I have no idea how to get information if my usb stick is sda, sda1, sdb, sdd...or something else... and I don't know which filesystem on it...
If I could get this information, I could surely mount it using mount().
I can only get info if there is some MASS_STORAGE_DEVICE on the machine, but it can also be a DVD/CDROM or HARDDRIVE...and it still doesn't give me any info about /dev/sd*...so I'm sitll unable to mount it...
- 07-17-2007 #5You'll find mounting is very easy and can't go wrong. But you'll need to combine the output from the commands I gave you.
Originally Posted by charmik24
Some commands need rot:
<dmesg> gives the kernel response to the plugging in of a new device. The kernel assigns it with an address.
<lsusb> gives a list of all plugged in USB devices, mounted or not (optional to the process).
<cat /etc/fstab> assigns who may mount where. Therefore contains useful information on where certain devices are expected.
And mount of course. To do the valuable stuff.Can't tell an OS by it's GUI
- 07-18-2007 #6
Freston, the problem is that he's trying to do this through C, not Bash.
However, Freston does give me an idea. Assuming that you have a USB stick mount point in your /etc/fstab and that you know the block name or mount point name, you can actually search your fstab and check for the existence of that device with libusb (or just mount it straightaway). Check "man getfsent" for the documentation of these functions.DISTRO=Arch
Registered Linux User #388732
- 07-18-2007 #7Just Joined!
- Join Date
- Oct 2006
- Posts
- 6


Reply With Quote
