1

My application needs to access files on a usb stick from a rooted Nexus7 tablet over an OTG cable. I have been looking into this extensively and found a few related posts but no real answer.

I know this is possible, because I can mount it with stickmount though I can't use third party software, so I need to somehow re-implement this myself.

When I plug in the USB stick it appears as 001 in /dev/bus/usb/001, so I was hoping it would be as simple as:

Runtime.getRuntime().exec("su -c \"mount /dev/bus/usb/001/001 /sdcard/test\"");

but that doesn't work. A little toast pops up with

    myApp has been given superuser permissions:

    mount /dev/bus/usb/001/001 /sdcard/test

But it isn't mounted.

Am I formatting the command wrong, or is this the completely wrong way to go with it? Any ideas on how I could get this thing to mount?

Thanks

  • You are trying to mount a raw USB device, but that won't work. You need to mount a device exported by the USB Mass Storage driver. On a traditional linux this would be /dev/sda1 or similar, but who knows what it would be on your device. The appropriate /dev node may not even exist, so you might have to create it first. Look in dmesg and perhaps /proc/partitions to see if the kernel is recognizing it as a storage device and if so what major and minor numbers the corresponding device node will need to have. – Chris Stratton Apr 10 '14 at 21:41
  • So I've found that when a usb stick is plugged in I get two raw files in /dev/bus/usb/001 (001 and 002) I also get 2 files in /dev/usb (dont know how I missed that one before) called bsg1-1:1.0 and scsi_generic1-1. In /proc/partitions there are entries for sda and sda 1 with maj-minor 8-0 and 8-1. How do I use that to create the node? – user3280117 Apr 11 '14 at 15:23
  • The usb stick will have one file on it and I just need to pull it off... Is there any way I could just use the raw USB device for that if I don't mount it? – user3280117 Apr 11 '14 at 16:52
  • Yes, but then you have to implement (at least part of) a file system against raw USB Mass Storage operations, ie, issuing the actual USB requests yourself (which has the advantage of working on stock Android, without root). If you really control what is on the stick, you could skip having a file system and just write your data starting from the beginning, but that's tricky for ordinary users to accomplish. – Chris Stratton Apr 11 '14 at 17:42
  • I just need to pull a single file from the stick. It will be the only thing on there. Can I just read from the raw files using an inputstream from my app? or is it a bit more complicated than that. – user3280117 Apr 11 '14 at 17:47
  • Thanks for all of your help by the way – user3280117 Apr 11 '14 at 17:49
  • If the kernel recognizes it as a USB mass storage device, then something running as root (or anything if you chmod the node) could read the raw block node, but would have to decode the filesystem. So at that point you might as well mount it. It doesn't sound like you've yet used dmesg to see if the kernel is recognizing it as a storage device. Since you have a Nexus device you shouldn't have trouble obtaining the actual kernel sources and configuration either. – Chris Stratton Apr 11 '14 at 17:50

0 Answers0