DEV Community

Cover image for A Filesystem in JavaScript 🐣
Adam Crockett πŸŒ€
Adam Crockett πŸŒ€

Posted on • Updated on

A Filesystem in JavaScript 🐣

It's Friday, it's nearly my Birthday, it's time to address some long running iterative projects (projects I never finish) LRIP for short πŸͺ¦.

What's my latest LRIP?

I have a bunch of these projects which I may one day finish.
One in particular which I really wanted to make possible but have been less experienced in previous iterations, a virtual file system.

In my mind Unix probably works in these easy to understand steps

The kernel πŸ£πŸ— is the entry point of an application (aka your computer) which a Filesystem sits on top of, the kernel provides syscalls to do things like change directories, write files and so on, these syscalls are usually C functions (that's it, no magic, although FYI Rust πŸ¦€ is entering the chat).

Okay so we got functions, an application and how do we use this application?

How do you use your computer without a GUI? That's a trick, don't answer that because terminal is graphical, kind of... But yes a terminal, but the shell, that's what we are talking about.

Think of the most basic shell... Shell not Bash, just Shell, it's just a parser really, type 'cd' and the shell parses your input, cd is not in your bin it's a syscall chdir(), cool right? 😴, Wake up ☺️

Okay sleepy head

Get to the point, what do I need a Filesystem written bin JavaScript for, it sounds useless. Precisely, this filesystem offers nothing more than the bear bones 🐻 to represent a Filesystem, it's going to have a lot of extension points (plug-in a function) allowing library authors to represent a Filesystem as a data structure.

Here are some ideas:

  • A web server / application with a limited and synced to phisical disk
  • Some sort of mock FS testing
  • Deploy a yeoman style template in node.js
  • Build an OS real or otherwise
  • Build the next docker πŸ˜…
  • Browser mock FS
  • Wasm FS thing
  • hybrid synchronized FS
  • some new build system concept
  • Port it to Rust
  • Make it work on a real disk (it's possible with Fuse)

So I'm on my phone, I can't go explaining the code because it's not done yet, BUT it's intuitive I feel, also it's locked down as much as possible so that only a new Shell() can actually interact with the FS just like the real thing.

Such a fun toy, want to help me, get in touch we can FOSS it πŸ¦„

Top comments (4)

Collapse
 
yjdoc2 profile image
YJDoc2

Hey, I'm not sure what exactly you want to do, but if you want to make a custom file system, try Fuse.... It basically mounts a dummy fs and intercepts calls like readdir, open etc and forward them to your program where your program can handle them.
I'm not sure if it's Linux only (it probably is) but npm seems to have few packages which provides binding for it...maybe it'll be useful for what you want to do :)

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€

Fuse was mentioned in the post, although it's nice to know thier are bindings, the post explains the motivation to write a filesystem with no purpose except to provide others with the skeleton to make it do stuff. Example you could take this approximation of a filesystem, extend it and maybe for your case, use Fuse to mount it.

For another use case, take the file system and extend it to do unit testing or something.

The point is it's a tool for writing other tools

Collapse
 
yjdoc2 profile image
YJDoc2

Hey , so sorry for the misread! I kind of went quickly through list and lost the fuse point πŸ˜… πŸ˜…
It seems a really nice idea to make a tool for writing other tools πŸ˜€

Thread Thread
 
adam_cyclones profile image
Adam Crockett πŸŒ€

Thank you, I think this tool for other tools reduces the scope and responsibilities, making a release more manageable πŸ‘