0

I need to read and write bytes to a mass storage USB FLASH drive, but I dont want to use any file system, or files. I just want to have a blank unformatted USB flash drive, then start writing raw bytes to it using libUsb.

I read that mass storage can read and write raw bytes and its up to you to create your own file system like FAT etc using raw read/write USB commands.

However I dont want any file system, I just want to be able to command it to write a byte or read a byte from particular locations on the flash, and possibly get the size of the flash also.

Does anybody know how to do that, or know of any examples I can look at?

Please let me know if my question is not clear, or too broad, or not enough information, so I can rephrase or change the question all together.

Thanks very much!

user5199516
  • 27
  • 3
  • 9

2 Answers2

0

Your USB flash drive probably is a USB Mass Storage Device. You should start off by looking at the official documents that specify the Mass Storage class, which are available here:

http://www.usb.org/developers/docs/devclass_docs/

These documents will explain what kind of descriptors a mass storage device will have and what kind of USB requests /transfers it accepts. Then you can use libusb to implement those requests/transfers.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • Thanks David, I started using WinUSB and also libusb, now I can at least do raw reads from the mass storage device with libusb. But since I installed WinUSB, windows file exporer no longer sees the usb flash drive when i plug it into the usb port on the PC. So it seems if WinUSB driver installed, libusb will work, but windows mass storage doesnt, and if i uninstall WinUSB, then windows works, but libUSB doesnt. Is there a way I can have both working somehow, both libusb mass storage, and also windows mass storage? – user5199516 May 26 '16 at 00:35
  • That's cool that you got it working. You might be able to use the libusb-win32 filter driver or something like that. But why would you want to have both options working at the same time? Your raw reads and writes will most likely confuse the higher-level Windows drivers that expect to see a valid filesystem on the USB drive. – David Grayson May 26 '16 at 00:56
  • Because if the user plugs in a regular flash drive, they wont be able to use it. But at the same time if I plug in a flash drive with my custom file system, i want to be able to access it too, but it seems both cant work at the same time. Why in the world would anybody use libusb if they have to give up using the built in mass storage, cant both work at the same time? I just want to be able to have low level read/write access to my custom file system, if thats plugged in, but if a regular FATxxx is plugged in then that should work too. – user5199516 May 26 '16 at 11:54
  • I have a contract job where i have to create a custom encrypted USB mass storage file system. When a regular USB drive is plugged in, then it works normally, but when my custom mass storage drive is plugged in, windows should not be able to read it. Only my custom application can read the information form the custom drive, windows cant read it.when the user runs my custom application they will be able to read the usb d – user5199516 May 26 '16 at 12:07
  • I have a job to create a custom encrypted USB file system. When regular USB drive is plugged in it should work normally. When my custom mass storage drive is plugged in it should seem like an unformatted drive to windows. Only my custom APPLICATION can read the information from the custom drive.This same deal also has to work for Android, so I thought to use libusb since it supposed to be cross platform. But libusb prevents the regular USB drive from working. Any idea how to do it without writing a driver? – user5199516 May 26 '16 at 12:18
  • Why not just store your custom encrypted file inside a file on the normal filesystem? Veracrypt is an example of some software that does that. – David Grayson May 26 '16 at 16:06
0

There is a drive which uses a regular FAT32 partition in Windows and on that partition is a "login" app. When the correct credentials are entered a completely new partition is mounted to the operating system, which was previously invisible to the operating system before. This is a hardware solution so it's impossible to format or erase the drive and remove the content. In addition the "login" partition is write protected, so it's impossible to remove that element as well. Sounds like what you are looking to do, has been done before by nexcopy a company which makes the above ↑