How do I hot-swap a mass storage LUN backing file in the Linux composite USB gadget?

fortyrod

Cutting to the Chase

Does the Linux composite USB gadget mass storage function support hot swapping of its LUN media backing files? If so, has anyone gotten it to work?

Background

The Linux USB composite gadget includes a Mass Storage function which can support multiple logical units, each of which maps to a drive image file (like FAT or ISO). From what I can tell, the Mass Storage function appears to inherit some or all of it's configuration interface from the previous standalone g_mass_storage gadget

The documentation implies that you can mount a storage image as a mass storage LUN, and then, at a later time, unmount it and remount a new storage image, in a manner similar to how a physical CD/DVD drive would work. It is this functionality that I am trying to access.

What I Have Tried

I am using insmod/modprobe and rmmod to mount and unmount a single LUN mapped to an ISO image. The modprobe parameters are modified version of the stock Edison config, which it uses to expose its "firmware update" drive image.

The USB slave is an Intel Edison board running a slightly modified Yocto build, the host is OS X 10.10.2:

# Step 1: mount an ISO
modprobe g_multi file=/home/root/first_image.iso removable=1 ro=1 stall=0 idVendor=0x8087 idProduct=0x0A9E iProduct=Edison iManufacturer=Intel

# at this point, the ISO appears on the host (I'm testing with OS X)

# Step 2, at some later time
rmmod g_multi

# The storage disappears from the OS X desktop. 
# It does not seem to complain unless you had files open on the media

# Step 3: mount a different ISO
modprobe g_multi file=/home/root/second_image.iso removable=1 ro=1 stall=0 idVendor=0x8087 idProduct=0x0A9E iProduct=Edison iManufacturer=Intel

# The operation appears to work on the device side, 
# but the new media does not appear in OS X.
# You can usually get it to work by unplugging the USB cable,
# which presumably resets the port somehow.

I have tried to find a way to reset the OTG device port under software control. That may be the ultimate solution.

I have not (yet) tried using the configfs interface to build and configure the device. That may also be an option, but I'm still working through the docs on that.

Thanks!

Alexandre Pereira Nunes

At least on:

$ uname -r
4.9.87

I've found this:

$ find /sys -type f -a -name file
/sys/devices/soc0/soc/2100000.aips-bus/2184000.usb/ci_hdrc.0/gadget/lun0/file
/sys/module/g_multi/parameters/file

The prefix will be heavily dependent on your hardware, but the gadget/lun0/file one is writable. You'd then:

echo "/where/is/your/file" >.../lun0/file

and voila. Of course, you need the removable=1 passed go g_file as the OP implied.

To "eject" the device, you simply do the following:

echo >.../lun0/file

This last one may fail if the filesystem is still mounted on the host.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Gadget mass storage passthrough

From Dev

No UDC shows up for USB mass storage gadget with configfs

From Dev

Linux USB Mass Storage Emulation

From Dev

How do I connect a USB mass storage device that has a custom pid and vid?

From Dev

How do I pass an attribute from composite component to backing bean by using backing component?

From Dev

What's the difference between USB_MASS_STORAGE and USB_FILE_STORAGE and how to best use it?

From Dev

How do I set up an encrypted swap file in Linux?

From Dev

Usb mass storage file system location on QNX

From Dev

How to automount an Android phone as USB mass storage?

From Dev

How to access usb mass storage in android NDK

From Dev

How do I add a swap (Not a swap file) after installation of Kali Linux?

From Dev

Can I make a USB port on my Linux computer look like a mass storage device?

From Dev

Can I make a USB port on my Linux computer look like a mass storage device?

From Dev

Disable usb mass storage

From Dev

Disable usb mass storage

From Dev

How to get the file path from a device acting as a usb mass storage in android

From Dev

How can I remove all drivers and other files related to a USB Mass Storage device?

From Dev

Disable read cache/buffer for USB mass storage device in Linux

From Dev

Disabling read buffering in Linux for USB mass storage device

From Dev

How do I setup an encrypted swap file?

From Dev

How do I replace zram swap with a swap file?

From Dev

file is too large to copy on 8 giga USB Mass Storage Device

From Dev

How do I mass install apt packages conditionally from a file?

From Dev

How to install CentOS 6 via USB mass storage device?

From Dev

Only use Mass Storage devices on a selected USB port - how?

From Dev

How to install CentOS 6 via USB mass storage device?

From Dev

Only use Mass Storage devices on a selected USB port - how?

From Dev

How to share a folder as an USB mass storage device (from a raspberry pi)

From Dev

How to auto-sync with a plugged-in USB mass storage device?

Related Related

  1. 1

    Gadget mass storage passthrough

  2. 2

    No UDC shows up for USB mass storage gadget with configfs

  3. 3

    Linux USB Mass Storage Emulation

  4. 4

    How do I connect a USB mass storage device that has a custom pid and vid?

  5. 5

    How do I pass an attribute from composite component to backing bean by using backing component?

  6. 6

    What's the difference between USB_MASS_STORAGE and USB_FILE_STORAGE and how to best use it?

  7. 7

    How do I set up an encrypted swap file in Linux?

  8. 8

    Usb mass storage file system location on QNX

  9. 9

    How to automount an Android phone as USB mass storage?

  10. 10

    How to access usb mass storage in android NDK

  11. 11

    How do I add a swap (Not a swap file) after installation of Kali Linux?

  12. 12

    Can I make a USB port on my Linux computer look like a mass storage device?

  13. 13

    Can I make a USB port on my Linux computer look like a mass storage device?

  14. 14

    Disable usb mass storage

  15. 15

    Disable usb mass storage

  16. 16

    How to get the file path from a device acting as a usb mass storage in android

  17. 17

    How can I remove all drivers and other files related to a USB Mass Storage device?

  18. 18

    Disable read cache/buffer for USB mass storage device in Linux

  19. 19

    Disabling read buffering in Linux for USB mass storage device

  20. 20

    How do I setup an encrypted swap file?

  21. 21

    How do I replace zram swap with a swap file?

  22. 22

    file is too large to copy on 8 giga USB Mass Storage Device

  23. 23

    How do I mass install apt packages conditionally from a file?

  24. 24

    How to install CentOS 6 via USB mass storage device?

  25. 25

    Only use Mass Storage devices on a selected USB port - how?

  26. 26

    How to install CentOS 6 via USB mass storage device?

  27. 27

    Only use Mass Storage devices on a selected USB port - how?

  28. 28

    How to share a folder as an USB mass storage device (from a raspberry pi)

  29. 29

    How to auto-sync with a plugged-in USB mass storage device?

HotTag

Archive