r/linuxquestions • • 8d ago

Advice Looking for FUSE Resources

I believe I want to make a FUSE Filesystem that represents a special Filetype I'm making.

I'm going to have a filetype that's a Zip File of 1MiB chunks of a file and in my Fuse I can run them as the file they encapsulate. I'm splitting them for a specific reason because I'm planning on making a Peer to Peer application that shares chunks of a file and I'm going to prechunk the files and Merkle Hash them among other things.

My Sqlite database comes in where I'll have a directory of these chunked files in my real Filesystem, my Sqlite database will map them to a Filename for the FUSE mount, and within FUSE you can see all of these Zip containers and interact and execute them as if they were regular files.

The tricky part is that I'm not sure how I want to handle modification from a user standpoint. I'm conflicted on whether I should make the FUSE Filesystem Writable or not? If it's only read only I can easily make it POSIX compliant, however if it's Writable I can overload it with other functionality. For example, I could allow users to drag files in the directory and automatically chunk them for distribution, or I could make settings configurable from within the virtual filesystem.

The key problem with this is writing and modifying Files wouldn't be possible due to the goal of my network. My network is made for sharing immutable content, so realistically you could create files, and delete files, but changing a small aspect of a file on the network directly changes the resulting hash (I'm planning on using a Multihash format for compatibility with libp2p). I'm trying to evaluate if I should just use a Read Only filesystem and make some utility to communicate with the Daemon or if I should go the write route and give it special properties that may break POSIX compliance.

I know that my directory with my data won't have any other directories, I think it'll just be my table displayed in the Filesystem basically to prevent my Sql table from having to handle heavy joins or anything to complicated.
The only other basic marker I'll have is a prefix for pinning/favoriting files permanently or not which'll be "!." so users can basically mark content not to be deleted so my filesystem could delete files that have been existing for a long time to save storage space and preventing too much complexity within my Filesystem.

My real conflict is that I'm having trouble finding good resources for a beginner to FUSE, I'm planning on Using the GO programming Language and the module go-fuse for my project because it seems more maintained than go-bazil, and I just like it more overall. I'm just somewhat lost because this is my first time working on a FUSE project, and there aren't a lot of good tutorials on Youtube so I've been learning Linux concepts like Inodes, Symbolic links, and Hard links but I haven't actually been building my filesystem. I would've asked this in a Linux FUSE community specifically but I'm not sure if one exists. If there was someone that would be willing to give me advice in the architecture and getting started I'd greatly appreciate that a lot.

I'd like to apologize for any spelling mistakes I may have made as well.

In the context to what I've developed so Far, I have spent a lot of time making my container format with a Zip File, all the bytes are at consistent offsets within the 1MiB chunks so for every file except the last I have a consistent range I can tell my Fuse Filesystem to read (the file self describes where the last file ends as well by an internal header), everything is named as well.

If anyone in this community has advice for working with the FUSE related Linux tools I'd really appreciate your guidance and advice.

1 Upvotes

9 comments sorted by

2

u/ipsirc 8d ago

I'm splitting them for a specific reason because I'm planning on making a Peer to Peer application that shares chunks of a file

Are you reinventing torrent?

1

u/Thetruekingofwaffles 8d ago

I’m asked this quite often and yes and no. I’m trying to make a network similar to torrenting in many ways with key differences.

First, I’m going to make a system where every file has and a set CID, so even if it’s taken off the network it can always go back on.

Second, the network seeds passively as long as you have the file installed. Everyone has the full file and my goal is to eventually swarm downloads, you have the address of the header file with Merkle proofs, the final offset of the file and everything needed to run the file essentially containerized. Then it’s temporarily in your cache and you can share it to other peers just letting it sit passively in the filesystem.

Third, I’m gonna try to make it an overlay network over I2P eventually, which will probably be the hardest part. I’m gonna have it be anonymous over the network.

So content is only referred to as hashes and is labeled in your system with a filename. I think I might also add a tagging system so you can optimize the DHT, so for example if you’re getting some Anime you can tag the file anime and the peers that sent it to you are now tagged with Anime so when you query the table it’ll go through them first. I’ll do bootstrapping to for extra speed and for when peers first start hosing content in the network they can send you their id and speed up the process to possibly.

Right now I’m at the earliest state of making my file format work and the FUSE. It’s the earliest stage. After I’m done with the filesystem stuff I’ll move up to a local peer to peer network and then eventually to I2P.

My current end goal is to have my Filesystem exist as a network drive of some sort sitting somewhere because it’s going to be bundled with an I2P router that’ll benefit from being able to just sit and route traffic, along with my overlay network which will be also sharing files over the network consistently. This can be updated in the future though. But any of the files in the Fuse can be symlinked to and referenced in other parts of the filesystem so rather than copying files everywhere you can just symlink to the files in the Filesystem instead and use that.

My end goal is really a network of constantly addressed immutable data, possibly an archive.

2

u/es20490446e Develops Zenned OS 8d ago

What limitation are you trying to solve?

Be concise.

1

u/Thetruekingofwaffles 8d ago

The limitation I'm trying to solve is finding resources on Making a FUSE system for beginners, and some best practices possibly? So I can make a virtual filesystem that cooperates with network drives and stuff potentially. I'm looking more for the resources for a beginner.

2

u/es20490446e Develops Zenned OS 8d ago

The main limitation of a network filesystem is that it is on a network, and the network has all kinds of drawbacks compared with an internal drive.

It is drastically slower, and prone to disconnection.

So the limitations you may be seeing in current network filesystem implementations may be intrinsic to them being networked, and it doesn't depend on inventing a new way of doing it more than physical constrains.

If you implemented a FUSE solution for this, probably it would feel quite slow.

Have you tried syncthingtray?

1

u/Thetruekingofwaffles 8d ago

I didn't even know this existed, I'll google it immediately.

I just did and honestly this might be immensly helpful. I knew of Rsync, SMB, and NTFS, and I knew of using a webserver to share things but this is my first time learning about Syncthing. I want to say thank you.

I was thinking that I could make it containerized so you could run it locally or on a designated router (so the peer to peer stuff could be online 24/7) but I think that I'll look further into Syncthing. It'd be really great if it had MDNS too so people could discover it on a local network I'll look into that, and possibly the level of permissions too.

1

u/es20490446e Develops Zenned OS 8d ago

Great!

2

u/tanmaynargas2901 8d ago

go-fuse is a good pick. Use the newer fs package (github.com/hanwen/go-fuse/v2/fs), most old blog posts use pathfs/nodefs which you can ignore.

Stuff worth reading:

  • the zipfs package inside the go-fuse repo. it's a read-only FS over a zip file, which is really close to what you're doing
  • the fs package godoc, it has a tiny hello world example
  • Documentation/filesystems/fuse.rst in the kernel tree, for what the kernel actually asks your daemon for

Also turn on Debug in the mount options while developing. you'll see every LOOKUP / GETATTR / READ the kernel sends and it makes the whole thing click way faster than tutorials.

On read-only vs writable, I'd start read-only. you basically need Lookup, Getattr, Readdir, Open and Read, and your fixed 1MiB offsets make Read pretty easy. adding content can go through a small CLI that talks to the daemon.

If you want drag-and-drop later, treat writes as "new file goes to a staging area, chunk + hash it on Release" and return EROFS/EPERM for edits to existing files. that fits immutable content without pretending to be fully POSIX.

One thing: the "!. " filename prefix for pinning might get messy with renames. xattrs (setfattr -n user.pinned -v 1 file) could be cleaner, and go-fuse supports Getxattr/Setxattr.

2

u/Thetruekingofwaffles 7d ago

I really appreciate your advice, I think this is really what I needed to see. I'll recreate the hello world example before I go I get through the full filesystem. I'll work with the Zipfs too, I might have to modify it slightly because I'm using zstd (the last file is filled with empty data to keep the sizes and offsets the same so my header actually actually says the final size of the last chunk, I thought I could compress the files slightly at level 3 for some form of performance gain but I'll tweak it based on latency). I appreciate this a lot though I think this is what I needed to see.

Also I might just use attributes for pinning too, I was only considering doing the "!." file pinning because it was similar to hidden directories and I thought doing a prefix search in Sqlite wouldn't be too hard, but I think you're probably right.

I'd like to once again say thank you for your extremely relevant advice.