Skip to content

Instantly share code, notes, and snippets.

@osnr
Created January 25, 2021 07:51
Show Gist options
  • Save osnr/d5a7450065f488ea14d6f5a6a6fd44a3 to your computer and use it in GitHub Desktop.
Save osnr/d5a7450065f488ea14d6f5a6a6fd44a3 to your computer and use it in GitHub Desktop.

A few years ago, I tried to turn a Pi Zero into a ‘synthetic USB stick’ – where you’d plug it into your laptop and it’d appear like an ordinary flash drive, but the program on the Zero could intercept reads and writes and dynamically generate content. Like a FUSE filesystem, but as a piece of hardware, sort of.

So you could edit a Python file on your laptop, save it to the USB drive, and then the output of your Python code would magically appear as a sibling file on the drive; things like that. I thought it would be particularly cool as a way to get some dynamism and programmability into limited pseudo-computers (TVs, game consoles, phones, tablets) that know how to talk to USB sticks. (I did find a paper that uses this kind of fake USB stick as a way to hack a smart TV!)

I actually got it to work pretty quick (combine the Mass Storage Gadget built into Linux with BUSE), but I found that the results were disappointing: first, my Mac just refused to tell the flash drive when I did any write until it absolutely had to (e.g. when I ejected), and second (and worse), my Mac would pretty much never read the drive again after it had read it the first time, since it assumed nobody else would write to the drive. So my synthetic drive couldn’t, for example, make up a new file in a directory once my Mac had read the root directory listing, because it just wouldn’t show up.

@GoodClover
Copy link

Ah, seems I'm a bit wrong saying "streamed", (usually in-order, usually non-repeated) 512 byte packets is maybe more correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment