Monday | 15 APR 2024
[ previous ]
[ next ]

FUSE Tutorial - 01 Baby's First Filesystem in Userspace

Date: 2023-02-01

Table of Contents

  1. TLDR
  2. The Why

  1. Baby's First Filesystem in Userspace
  2. Getting Started
  3. getattr - The First Avenger
  4. readdir - Slowly
  5. sqlite - but
  6. readdir - Surely
  7. read - Learning to Read
  8. write - Learning to Write
  9. Conclusion


Warning! No code here, this is an overview of why I wanted to write a fuse driver for sqlite.

The only thing to make sure is that you have the c headers for fuse and sqlite.

sudo yum install fuse-devel
sudo yum install sqlite-devel

The Why

SQLite is wonderful and one reason why I consider it wonderful is that it maps to my thoughts perfectly. The idea that a database can live in just a single file scratches an itch that I have to keep things simple. I already prefer writing my code in a single file even if it would be easier to break things apart. Due to this proclivity, you can see why I enjoy using sqlite as it keeps the data in a single place as well.

This idea is what I want to exploit. I want to use the simple sqlite database but also expose it so I can use it like a file system. In my eyes a file system and a database are two sides of the same coin, especially a database where typing isn't a real thing. I want to be able to navigate my database as if it was a folder.

This is where FUSE or Filesystem in UserSpacE comes in, FUSE will let you fake a file system. You simply mount something onto a directory and from that point on any syscalls that get called will be piped to your mounting program. In the mounting program, you can specify what a directory will look like, how files are to be opened, how they are to be read and how they are written.

Now we can use FUSE to make sqlite look like a regular file. A table will become a folder, cd'ing inside that folder will simply set the table we are working on. Doing ls will need show a listing of the ids in our table. If we open one of these ids, it will contain the data which we can use a select to get. We can then use an insert or add new records or we can use and update to modify existing data.

I haven't done any FUSE or sqlite programming before so we are going to go slowly and stupidly. The goal is to see if this idea of getting sqlite to look like a filesystem will work which I imagine it will but how useful will it be? Who knows!

Reader beware: I'm not trying to learn FUSE or sqlite programming, I simply want something that does what I want it to. I spent a day looking for something to use off the shelf or even modify but found nothing.

I'm going to take a stab at writing the tutorial while also putting the pieces together, so don't take anything here as gospel.

Feel free to take the below link however as gospel. With a domain like osdev I imagine they know what they're doing!

Now on to the next chapter where we will actually write our first line of code!