prasanthg
Posts: 16
Joined: Mon Aug 13, 2018 1:28 pm

RPI Zero g_usb_mass_storage

Thu Dec 06, 2018 9:10 am

Hi All,

I have configured RPI Zero- OTG- (Stretch Lite ) feature using g_mass_storage and able to connect windows and windows detects RPI Zero's FAT32 partition as removable disk.
My problem is, i am able to add/delete files in FAT32 partition from windows but not from RPI. i want create/modify/delete files from both RPI Zero and windows side ... How to achieve this?

i have read below link, since RPI Zero uses USB_MASS_STORAGE Feature its not possible to modify files from RPI Zero side...i this is true how can i implement MTP in RPI so ican add/delete/modify files from both windows and RPI side
Link : https://www.howtogeek.com/192732/androi ... s-storage/

Thank you.

tqhien
Posts: 19
Joined: Thu Feb 02, 2012 10:07 am

Re: RPI Zero g_usb_mass_storage

Thu Dec 06, 2018 10:45 am

Did you try to mount the file on your system file ?

With your g_mass_storage file being /home/rpi/piusb.bin

Code: Select all

sudo mount -t vfat /home/rpi/piusb.bin /mnt/piusb 
But it is not advised to have 2 writeable systems at the same time...

DirkS
Posts: 9804
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: RPI Zero g_usb_mass_storage

Thu Dec 06, 2018 11:21 am

tqhien wrote:
Thu Dec 06, 2018 10:45 am
Did you try to mount the file on your system file ?

With your g_mass_storage file being /home/rpi/piusb.bin

Code: Select all

sudo mount -t vfat /home/rpi/piusb.bin /mnt/piusb 
But it is not advised to have 2 writeable systems at the same time...
As I read it OP does not use a file, but a live partition, so you would expect access from both is possible.
Still not recommended though because changes made on one system will not be seen by the other. Perfect recipe for file corruption

tqhien
Posts: 19
Joined: Thu Feb 02, 2012 10:07 am

Re: RPI Zero g_usb_mass_storage

Thu Dec 06, 2018 2:20 pm

I found a link for what seems adequate :

https://github.com/viveris/uMTP-Responder

I'll try it on a project where for now I mount a file, stops Pi's activity while connected as USB and dismount/remount after disconnection.

User avatar
thagrol
Posts: 1461
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: RPI Zero g_usb_mass_storage

Thu Dec 06, 2018 3:48 pm

tqhien wrote:
Thu Dec 06, 2018 2:20 pm
I found a link for what seems adequate :

https://github.com/viveris/uMTP-Responder

I'll try it on a project where for now I mount a file, stops Pi's activity while connected as USB and dismount/remount after disconnection.
That appears to be using MTP not mass storage.

It's not recommended to have write access enabled on both sides of the g_mass_storage link at the same time and,, while it can be done, write access on one side and read only on the other is also not recommended. Unseen changes can lead to accessing the wrong data.

As you've seen changes do not propogate between sides so the only way to see them is to unmount and remount on the side the didn't make the changes. There are ways to force this on the host but the devil is in the timing. It has to be done at a time when the host has nothing open and there is no way for the Pi to know when that is. And without a secondary channel (and software mods on the host) there is no way for the host to trigger the Pi to unmount/remout.

To do things by hand:
  1. Unmount side that won't be changed
  2. Make changes
  3. Sync changes to file system
  4. Remount other side
Root cause: both sides expect exclusive low level access to the backing storage. Both sides use caching. Neither side can tell the other what it's doing.

Having both sides writing to the storage will lead to lost data and corruption.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

tqhien
Posts: 19
Joined: Thu Feb 02, 2012 10:07 am

Re: RPI Zero g_usb_mass_storage

Fri Dec 07, 2018 9:55 am

Well, OP asked how he could implement MTP, so I thought the link I provided may be suitable for him...

User avatar
thagrol
Posts: 1461
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: RPI Zero g_usb_mass_storage

Fri Dec 07, 2018 1:20 pm

tqhien wrote:
Fri Dec 07, 2018 9:55 am
Well, OP asked how he could implement MTP, so I thought the link I provided may be suitable for him...
So he did. I missed that. Appologies if my comments caused any offense.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

prasanthg
Posts: 16
Joined: Mon Aug 13, 2018 1:28 pm

Re: RPI Zero g_usb_mass_storage

Mon Dec 10, 2018 6:49 am

Hi

Thank you for your Quick reply...
i have seen uMTP-Responder and tried to build in my RPI Zero i got this error
unable to open /dev/gadget/20980000.usb.
Init_usb_mtp_gadget error.

I have tried below link also
Link : viewtopic.php?t=152801

i have a another Query in case if i am sucessfully able to configure mtp, will i be able to copy/modify/delete files between windows PC and RPI over OTG ??

Thank you.
Attachments
Capture.PNG
Capture.PNG (43.88 KiB) Viewed 444 times

User avatar
thagrol
Posts: 1461
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: RPI Zero g_usb_mass_storage

Mon Dec 10, 2018 1:38 pm

Lets get the obvious things out of the way first:
  • Have you loaded the dwc2 module? (by adding "dtoverlay=dwc2" to /boot/config.txt)
  • Is the required moduel for gadget_fs running?
  • Does /dev/gadget/20980000.usb exist?
  • Does it have the expected permissions?
  • Is your zero currently acting as a USB device or USB host? With nothing connected it will be acting as a device provided the dwc2 module is running and has not been forced into host mode.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

prasanthg
Posts: 16
Joined: Mon Aug 13, 2018 1:28 pm

Re: RPI Zero g_usb_mass_storage

Tue Dec 11, 2018 5:18 am

Hi Thagrol

Thanks for your reply.
Have you loaded the dwc2 module? (by adding "dtoverlay=dwc2" to /boot/config.txt)
- Yes, it is loaded by editing /boot/config.txt
Is the required moduel for gadget_fs running?
- Yes, i used sudo modprobe gadgetfs
Does /dev/gadget/20980000.usb exist?
- i have created Directory inside dev,(like /dev/gadgetfs) but how to create 20980000.usb ??
Does it have the expected permissions?
- Since 20980000.usb does not exist in /dev/gadgetfs, Answer is none
Is your zero currently acting as a USB device or USB host? With nothing connected it will be acting as a device provided the dwc2 module is running and has not been forced into host mode.
- My PI Zero connected to windows pc via OTG port, so i guess it is operating in device mode and windows PC is operating in Host mode.


i have already configured g_mass_storage and it it working fine...
Good Day
Attachments
usb_mass_storage.PNG
usb_mass_storage.PNG (17.5 KiB) Viewed 370 times

User avatar
thagrol
Posts: 1461
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: RPI Zero g_usb_mass_storage

Tue Dec 11, 2018 12:14 pm

prasanthg wrote:
Tue Dec 11, 2018 5:18 am
Does /dev/gadget/20980000.usb exist?
- i have created Directory inside dev,(like /dev/gadgetfs) but how to create 20980000.usb ??
Does it have the expected permissions?
- Since 20980000.usb does not exist in /dev/gadgetfs, Answer is none
There's your problem. Not sure what the fix is but from the thread you linked did you run

Code: Select all

mount -t gadgetfs none /dev/gadget
as root/with sudo?
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

Return to “General discussion”