USB Gadget Mass Storage

A Balloon can expose itself as a standard mass storage device via the slave (UDC) port. It can appear, for example, as a memory stick under Linux, Windows and other OSs. Note that this exports a virtual partition that is managed by the remote host and is unavailable to the balloon kernel vfs while mounted by the remote host. Multiple partitions can be exported simultaneously. Note that if the device is disconnected before the host device has flushed all changes to the backing store then the resulting filesystem may be unstable. This seems to be particularly true for (V)FAT.

To export the balloon block device /dev/foo (foo can be sda, sda2, mmcblk0 for example) as a SCSI mass storage device, insert the module using

modprobe g_mass_storage file=/dev/foo

This will produce an entry under /sys/devices/platform/pxa27x-udc/gadget/lun0/file. If you cat this entry you will see /dev/foo. For kernels from2.6.35, this will refelect the mounted state of the device. If the remote host "ejects" the device, the contents of the file will become empty. When all luns are unmounted, it is safe to rmmod g_mass_storage and, for example, mount it into the balloon's fs for local access. You MUST only have the device mounted by one host at one time. If you need simultaneous access to a device, you should use a file based access protocol such as PTP or MTP. An unmounted lun can be made available to the remote host by removing and re-installing the module.

Multiple block devices (and multiple luns) can be exposed by

modprobe g_mass_storage file=/dev/foo,/dev/bar,/dev/baz

A file can be used as a device so long as it has a valid partition table (and probably a formatted fs). This can be acheived via a loopback device. See for details. One could make a small file device in ram for exchanging data with a host OS without having to use persistant storage. I am told that use of sparse data in this mode can be "interesting"


Balloonboard: USBMassStorageHowto (last edited 2011-04-22 22:02:02 by HectorOron)