tags:

views:

108

answers:

2

Can you show me some C code to detect a pendrive and retrieve the data present in it. I'm working on Linux.

+2  A: 

If by "the pendrive" you mean an USB memory stick, it depends a lot on your environment.

In a typical full Linux desktop install, the USB device will be automatically mounted, and generally will appear somewhere in the /media hierarchy. You can set the name of the drive to affect the name of the mountpoint, this makes it easy to find.

Opening files on the USB device is just like opening files anywhere else, from C or any other programming language.

unwind
A: 

Have a look at the article about "Developing Linux Device Drivers using libusb" on Linux Questions. It has the basic examples and explanation of USB using libusb API

Developing Linux Device Drivers using libusb

TuxGeek