File System in User space example

shashank Jain
3 min readAug 25, 2018

--

As covered in previous blog on the basics of FUSE. We in this blog take a simple example to write a FUSE based filesystem.

In the example we write a hello world FUSE file system which exposes the following operations

1. hello_readaddr — returns the exact structure of the directory read.

2. hello_open — We just have a memory resident file and nothing to be read from disk, we just return 0

3. hello_getattr — This is the callback made whenever the call to read the meta-data about a file(dir or file is made) . In our example if we encounter / then we declare it as a dir and return. If we read the file (hello in our example), we return the filesize

4. hello_read — We return the content of the file opened

Here are screenshots of the hello-world FUSE filesystem

The fuse operations is where all callback functions are defined.

Launching the program does the mount of the fuse file system on /tmp/example

Doing a ls in the directory /tmp/example

And the logs on mounted filesystem side show

Reading the file via cat hello

And filesystem logs show

We can see the operation read being called and the file exposed via the filesystem is read.

In the blog we took a very simplistic example on how simple filesystem operations are exposed as callbacks with a userspace based filesystem. Its left to the user imagination to define a filesystem of their choice . Some of the examples can be exposing the AWS Cloud operations APIs over the filesystem API. The enduser in this case can create a VM by creating a file with attributes like memory size,cpus etc. For the user a VM appears as a file. There can be many such examples.

Code sample explained is taken from https://github.com/JulesWang/helloworld-fuse/blob/master/hello.c

In further blogs I will try to see if I can cover the NUSE (Network in userspace) part.

If you are looking for more in-depth coverage of virtualization and container internals, please check this book from the blog author

https://leanpub.com/linuxcontainersandvirt

https://www.amazon.com/dp/1080299424?ref_=pe_3052080_397514860

Disclaimer : The views expressed above are personal and not of the company I work for.

--

--