Dan203
Posts: 3
Joined: Sun Aug 04, 2019 5:47 pm

Pi Zero W mass storage

Wed Aug 21, 2019 7:16 pm

OK I've read that when a Pi Zero W is in mass storage mode you can't actually write files to the drive over wifi while it's still connected to the host because the host won't recognize the new files and you could potentially corrupt the drive. However is there a way to safely write files to the drive over wifi while it's still physically connected to the host? Like is there a command you could execute via wifi to unmount the drive from the host, write the files, and then remount the drive?

For example say I have a Pi Zero W in mass storage mode connected to a 3D printer and I want to simply copy files to it from my PC using the wifi connection. Without physically pulling the USB cable from the Pi could you unmount it, write the files you need, then reconnect it so that the 3D printer now recognizes the new files you just wrote?

Also what about reading the files? Is it safe to read the files over wifi without unmounting the drive from the host first?

Thanks,
Dan

jdonald
Posts: 395
Joined: Fri Nov 03, 2017 4:36 pm

Re: Pi Zero W mass storage

Thu Aug 22, 2019 1:03 am

Dan203 wrote:
Wed Aug 21, 2019 7:16 pm
Like is there a command you could execute via wifi to unmount the drive from the host
Try:

Code: Select all

sudo modprobe -r g_mass_storage
Then run modprobe again without the -r to remount it.

I can't guarantee if this is safe without checking the kernel code, but it would be nice if they made it that way. Perhaps you could copy large files and run some tests doing the software disconnect in between.
Also what about reading the files? Is it safe to read the files over wifi without unmounting the drive from the host first?
This is block storage so imagine all the things that could go wrong if you are reading while a file or inodes are partially written. If you're willing to run file integrity checks, graceful behavior on a fatal error, and timeout detection I could see this working.

Dan203
Posts: 3
Joined: Sun Aug 04, 2019 5:47 pm

Re: Pi Zero W mass storage

Thu Aug 22, 2019 1:29 am

jdonald wrote:
Thu Aug 22, 2019 1:03 am
Dan203 wrote:
Wed Aug 21, 2019 7:16 pm
Like is there a command you could execute via wifi to unmount the drive from the host
Try:

Code: Select all

sudo modprobe -r g_mass_storage
Then run modprobe again without the -r to remount it.

I can't guarantee if this is safe without checking the kernel code, but it would be nice if they made it that way. Perhaps you could copy large files and run some tests doing the software disconnect in between.
Also what about reading the files? Is it safe to read the files over wifi without unmounting the drive from the host first?
This is block storage so imagine all the things that could go wrong if you are reading while a file or inodes are partially written. If you're willing to run file integrity checks, graceful behavior on a fatal error, and timeout detection I could see this working.


Thanks, I'll give that a try.

Return to “General discussion”