mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Mar 21, 2018 10:23 am

Hi.

I have I great looking idea for many devices (Gotek / scanners with no network storage / music instruments like Yamaha / oscilloscopes and many others) hardware extension.

I'm looking for a solution that I could use "USB Flash Memory" looking (acting) device which (in fact) is a WiFi client of Samba shares existing in the LAN (WLAN). When you put it in some device (in Gotek for example) then for Gotek it looks as an ordinary Flash memory. Gotek doesn't know this is just network Samba shared folder :-)

It looks this is a really nice idea for many old devices with USB storage support, but with no network storage support.

And probably I found a way how to do it:
https://cdn-learn.adafruit.com/download ... gadget.pdf

What do you think about ?

fruitoftheloom
Posts: 23011
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Mar 21, 2018 10:42 am

mesmariusz wrote:
Wed Mar 21, 2018 10:23 am
Hi.

I have I great looking idea for many devices (Gotek / scanners with no network storage / music instruments like Yamaha / oscilloscopes and many others) hardware extension.

I'm looking for a solution that I could use "USB Flash Memory" looking (acting) device which (in fact) is a WiFi client of Samba shares existing in the LAN (WLAN). When you put it in some device (in Gotek for example) then for Gotek it looks as an ordinary Flash memory. Gotek doesn't know this is just network Samba shared folder :-)

It looks this is a really nice idea for many old devices with USB storage support, but with no network storage support.

And probably I found a way how to do it:
https://cdn-learn.adafruit.com/download ... gadget.pdf

What do you think about ?

There are other tutorials relating to RPi Zero Gadget Mode:

https://blog.gbaman.info/?p=791

https://blog.gbaman.info/?p=699
Rather than negativity think outside the box !
RPi 4B 4GB (SSD Boot)..
Asus ChromeBox 3 Celeron is my other computer...

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Mar 21, 2018 11:23 am

Unless its changed, the gadget mode MSD device needs a block device as source.
A samba share isn't a block device, a single file could be though.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

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

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Mar 21, 2018 1:09 pm

A bit hacky and not samba but what you want can be done (with some restrictions).

See here: http://www.instructables.com/id/NAS-Acc ... d-Devices/

This uses a storage area network protocol to present a block device over the network to the g_mass_storage module running ona pi zerow.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Apr 04, 2018 10:51 am

Hi.

I just set my Raspberry Pi Zero W in the USB Gadget mode.

Now I'm able to connect with my RPi zero using USB cable only (after RPi Zero is connected to a PC then in the device manager I can see new serial port, and I can connect via putty to this serial to RPi serial console.

Now I'm thinking how to make PC see it not l(not only) as a setial port, but as flash memory.

Could someone please help me somehow?

Thank you and best regards
Mariusz Ciszewski

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

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Apr 04, 2018 11:48 am

mesmariusz wrote:
Wed Apr 04, 2018 10:51 am
Now I'm thinking how to make PC see it not l(not only) as a setial port, but as flash memory.
At the same time as a showing as a serial port or just as "flash memory"?

If you want both at the same time, I'd use the method outlined here: http://isticktoit.net/?p=1383, there's also the g_multi module (that provides serial, ethernet, and mass storage but isn't always detected correctly on windows).

If you just want the storage function try

Code: Select all

g_mass_storage file=/path/to/storage
"storage" must be either a file (used to emulate a disk) or a disk partition. It can't be a directory, network share, etc.

Usual caveats about mounting as writeable apply (don't mount it writeable on PC and Pi at the same time, if mounted as writeable on one side and read only on the other the read only side will not see changes made by the writeable side).
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

drgeoff
Posts: 10618
Joined: Wed Jan 25, 2012 6:39 pm

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Apr 04, 2018 12:49 pm

Maybe not exactly the same as the OP's idea but these are already available:

1. Sandisk Wireless Stick https://www.sandisk.com/home/mobile-dev ... less-stick

2. Wi-Fi SD card: eg https://www.amazon.co.uk/s/ref=nb_sb_no ... B00V6XZOPG

mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Apr 04, 2018 1:35 pm

1). Mentioned pendrive can't act existing Samba client unfortunately. Probably even can't connect to an existing WiFi network.

2). Wireless SD cards available on the markt are quite stupid devices because this is not possible to connect to an existing WiFi networks for them. That's why they are unable to became an existing Samba shares clients. Such cards can only generate WiFi network (act as an AP). So to connect to such cards (from a notebook for example) you have to first disconnect existing network connection, which is really stupid, and uncomfortable.

So both are not a solution unfortunalety, shats why I need to build it my my own. Please belive me if such device exists on the markt then I would like to buy a few.

Best regards
Mariusz Ciszewski

mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Apr 04, 2018 7:01 pm

thagrol wrote:
Wed Apr 04, 2018 11:48 am
At the same time as a showing as a serial port or just as "flash memory"?

If you want both at the same time, I'd use the method outlined here: http://isticktoit.net/?p=1383, there's also the g_multi module (that provides serial, ethernet, and mass storage but isn't always detected correctly on windows).
The best if in case I would like to upgrade something I have also access via serial on USB.

But the most important is all old devices equiped with USB port (like a scanner, Roland (musical instrument), oscilloscopes) see this device as flash drive. So the point is that most of devices see the USB flash correctly.

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

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Apr 04, 2018 7:15 pm

What you want probably isn't going to be doable in the way you're trying though there ways to get something approaching it.

I'll try to explain but first let me define some terms:
  • host: PC/device acting as the USB host
  • gadget: Pi zero/zeroW running as USB mass storage gadget
  • NAS: storage device on your network (Network Attached Storage)
  • Backing store: block device or file passed to g_mass_storage
g_mass_storage (gadget)
  • Requires a block device (e.g. /dev/sd??) or a file that can be treated as a block device (e.g. /foo.img)
  • It's essentially a translation layer between the USB mass storage API and the driver for the linux block device.
  • Provides low level access to its backing store to the host.
  • Backing store must be formatted with a filesystem the host understands
  • Does not provide any mechanism for the host to notify the OS on the gadget that the backing store's content has changed or vice a versa
  • Backing store does not need to be mounted on the gadget's OS to be usable by the host.
Samba
  • Client/server file sharing protocol originating on MS Windows
  • Does not provide a block device to clients
  • Shares the contents of a directory to clients.
  • NAS filesystem is irrelevent to clients and clients may not be told what it is.
host
  • Must be able to act as a USB host (most old devices can't)
  • Expects to have exclusive access to the gadget's backing store
  • May only support a limited range of filesystems (often just FAT32)
So...
  • Your "old USB device" must be capable of working as a USB host.
  • A samba share cannot act as the backing store as it is neither a block device nor a file.
  • You can use a file located on a samba share as the backing store.
  • Backing store must be formatted with a filesystem the device understands. This can often be done on the device.
  • You can cause real damage to your files by having the backing store mounted on the host and gadget OS at the same time.
Workarounds
  • See the link I posted above.
  • Use a file on the samba share rather than the share itself as your backing store
  • Only mount the backing store on one device (host or gadget) at a time.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

drgeoff
Posts: 10618
Joined: Wed Jan 25, 2012 6:39 pm

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Wed Apr 04, 2018 10:57 pm

mesmariusz wrote:
Wed Apr 04, 2018 1:35 pm
Probably even can't connect to an existing WiFi network.
It can.

mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Thu Apr 05, 2018 9:32 am

As I understood the most difficult is the "storage" can't be connected to two devices in the same time. For example such "WiFi pseudo-flash Samba client" can't be connected in the same time into the Gotek (USB FDD emulator -> http://www.gotek.in/) and into the Samba server @LAN.

So. If this is not possible, then feel I'm forced to change my concept a bit.

I think for gotek (and many other devices) it's enough if Raspberry Pi Zero W when powered up (eg. insteted into Gotek):

1). At first: RPi Zero starts in a normal mode (USB gadget mode disabled) and connect to a WiFi network and synchronize dedicated folder on RPi SD card with a Samba shered content (Samba server in LAN) .
2). Then if SD folder and Samba content are fully synchronized RPi Zero disconnect from a Samba share and start USB Gadget mode (if possible to enable USB gadget mode). Then Gotek start see USB device is connected and have a access for content previously synchronized with a Samba share.

Now, ewen is you save something into Gotek (into SD on RPI Zero in fact) then it will be synchronized with a Samba server during next RPi Zero reboot (before it switch to USB Gadget again).

Is my thinking correct?

Because as I understood well, there is no chance to introduce real time and bidirectional access to Samba svare via such "WiFi pseudo-flash Samba client". Correct?

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

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Thu Apr 05, 2018 11:35 am

It looks like that device doesn't work the way you may think it does.

From their website "A simple application is also provided at Zero of cost on purchase of floppy disk to usb converter which assists in formatting a USB Pen drive into 100 blocks of 1.44/1.2/720 kb capacity each or as per user requirements. This application is must to create boot function work , which is must must requirement in many industrial machines"

This suggests that it either uses a custom. non-standard format for the USB drive or that the only files visible to an OS are a 100 floppy disk images.

Either way you'll need a seperate backing store for each device if they need to write to the emulated floppy disk.

Your revised approach may work. Don't load the g_mass_storage module (remove it from /boot/cmdline.txt, /etc/modules, etc) perform your sync then load the g_mass_storage module (sudo modprobe g_mass_storage file=/path/to/backing/store). How you do the sync depends on how the gotek device formats the USB stick.

You can have simultaneous access to a shared backing store provided all devices connected to it do so in a read only mode. That can be set in mount options, samba options and in options passed to g_mass_storage at boot time. (I didn't mention it earlier as you seemed to want write access)

Something else to consider: how are you going to get existing data from floppy disks on to your backing store?
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

mesmariusz
Posts: 57
Joined: Fri Feb 15, 2013 6:07 am

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Thu Apr 05, 2018 12:23 pm

---------> Gotek topic <---------

If we are talking about Gotek (I have it one, I use this, so I know exactly how it works).

Please note I uploaded FlashFloppy firmware ( https://github.com/keirf/FlashFloppy ) into my Gotek ( https://www.aliexpress.com/item/Free-Sh ... 69272.html )

So to close "how Gotek works" topic:

Pendrive needs to be formatted as FAT32. Then you can copy into this pendrive, for example *.ima files (IBM PC diskettes images) or *.adf (Commodore Amiga diskettes images).

FlashFloppy firmware (during startup) read the pendrive structure and "put image files" into slots (000-999) you can swith them using switch buttons).

You can put-out a pendrive from a Gotek in any time, and when you put-in it again, then Gotek read the filesystem structure again and put all diskette images into the slots 000-999 again.

---------> End of Gotek topic <---------


Solution I'm talking about:

1). Raspberry Pi Zero W inserted into Gotek.
2). During Power-Up Raspberry Pi Zero W connect via WiFi with SMB server located @LAN, to synhronize folder on SD card with external Samba (located @LAN) folder content.
3). After sync disconnect from WiFi / Samba
4). Switch Raspberry Pi Zero W to USB Gadget to be visible as pendrive for Gotek
5). Gotek see files previously synchronized with Samba content @LAN.

Please note this is my second scenario, because as it was mentioned (as I understood) this is not possible to make a real time bidirectional connection between Samba server and "pendrive" connected into a Gotek.

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

Re: USB Flash / Pendrive looking - WiFi network storage (Samba) client

Thu Apr 05, 2018 1:29 pm

If you'd given us the info about the gotek earlier it would have helped...

To confirm we're on the same page:
  • You have multiple floppy disk images on a samba server
  • You want to make these available via a zeroW to a gotek device installed in some machine
  • Said machine will update these images
  • Updated images must be written back to the server
  • Your aim is to have multiple gotek equipped machines talking to the samba server
The two main issues we need to work with this are
  1. Your insistance on samba
  2. Your need for write access
OK...

Configure your zeroW like this:
  • Three paritions on the SD card:
    • /boot
    • /
    • gadget's backing store
  • Format the backing store partition as FAT32
  • Create a mount point for the samba share
  • Create a mount point for the backing store partition
  • Add

    Code: Select all

    dtoverlay=dwc2
    to /boot/config.txt
Write a script that:
  1. Mounts the samba share
  2. Mounts the backing store
  3. Syncs the samba share and the backing store (hint: rsync)
  4. Unmounts the backing store
  5. Optionally unmounts the samba share
  6. Loads the mass sotrage gadget:

    Code: Select all

    sudo modprobe g_mass_storage file=/backing/store/partition
You'll need to find a way to handle conflicts between gotek equiped devices yourself. A keyboard and a camera might both ahve files called 001.img but with wildly different contents. If you sync both to the same share you'll loose one of them.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

Return to “Networking and servers”