Reputation: 33
I am using libusb to interact with pen drive. We have to use the function
int libusb_bulk_transfer(struct libusb_device_handle * dev_handle, unsigned char endpoint,
unsigned char * data,int length,int * transferred,unsigned int timeout)
But here we specify only the end point
So my question is that Is it actually possible to read write files(text or images) to pen drive. Or is it just for understanding?
Please help!
Code::
r = libusb_bulk_transfer(dev_handle, (2 | LIBUSB_ENDPOINT_OUT), data, 4, &actual, 0);
//my device's out endpoint was 2, found with trial- the device had 2 endpoints: 2 and 129
if(r == 0 && actual == 4) //we wrote the 4 bytes successfully
cout<<"Writing Successful!"<<endl;
else
cout<<"Write Error"<<endl;
Upvotes: 0
Views: 2088
Reputation: 8338
Libusb works at a lower level than the filesystem. You're reading or writing raw blocks of data to/from the device, not dealing with things at the file level. If you formatted the device, saved a few files to it, then used your program to read lots of data off starting from near the beginning you'd likely eventually see the filenames, then data from the files, among a lot of other "gibberish" looking things.
If you want to read and write files this way, you're going to have to write code that can read that other data to figure out where on the device your files are, how to create new files, etc.
If you're just playing around, you can start at any arbitrary point on the flash drive, write a whole file to it, then read it back. But that'll only be understandable to your program, putting your flash drive in your desktop PC isn't going to know where to look to find it because you're missing the filesystem parts that tell it where your file is.
Upvotes: 3