How to use Fuse

by: burt rosenberg
at: university of miami
date: oct 2021

     A FUSE
NAME
    hello
    
SYNOPSIS	
    hello _mount_directory_
    
DESCRIPTION
    Implements a File System in UsEr space that contains 
    one file, called hello, with fixed contents, Hello World.
    
OPTIONS
    To be or not to be, those are the options.

HISTORY
    A FUSE test program.

BUGS

FUSE

Unix has mountable file systems. This means that the overall file tree can be comprised of different file systems. The passage from one file system to another is at an object that looks to the user like a directory, but it is a mount point. A mount point node is marked with the root of the filesystem which should begin at that directory.

FUSE allows user programs to be the destination of a mount point. By registering on a directory, FUSE intercepts all file requests on a path passing through that directory and packages up the request as a call into the user program. The user program provides a response by call-by-reference parameters, and the return value.

The hello world file system is an example. It mounts on a particular mount location, and answers all queries from the program. There is no disk or other memory system involved, other than the memory of the program implementing the hello world file system. When asked, it responds with a completely fixed directory contents; and when the hello file is read, it responds with the contents of a string defined in the program.

This still seems like a file system, just a file system that has exactly one file with an unchangeable contents. FUSE can be used to build other file systems, including those that have more customary semantics. Or to build file systems with very different semantics than is customary.

FUSE and Files

User-program <-----> Kernel <-----> FUSE <-----> hello.c <-----> RAM memory

                filesystem                 FUSE callbacks     filesystem
            
            
User-program <-----> Kernel <-----> FUSE <-----> leveldbd.c <-----> normal files

            filesystem                 FUSE callbacks     filesystem

Registering Callbacks

FUSE requires a continuously running program to service the filesystem calls that get routed to the Fuse File System. This is a sort of server, for the service of the filesystem, that the operating system contacts when there is work to do in the FUSE file system.

The calls into the FUSE server are done by a main program providing the kernel with a menu of functions. When there is work to do, the kernel calls the function associated with the sort of work required. There is a call back for read a file, or write a file, as well as to list a directory, remove a file from a directory. Every operation that can be done on a filesystem is represented by a function in the callback table.

The FUSE Callback table
static struct fuse_operations fuse_oper = {
	// call backs for fuse
	.getattr = fs_getattr,
	.readdir = fs_readdir,
	.mkdir   = fs_mkdir,
	.rmdir   = fs_rmdir,
	.create  = fs_create,
	.unlink  = fs_unlink,
	.utimens = fs_utimens,
	.truncate = fs_truncate,
	.open    = fs_open,
	.write   = fs_write,
	.read    = fs_read,
} ;

To get started with FUSE, copy the class/proj4 directory to your proj4 directory. The Makefile has an install target that you run to install the FUSE development package. The test target will compile and run the hello-world file system. This is a file system that contains only single file in the root directory with a fixed content.

For the project, implement hello_write that allows a short string to be "written" to the hello file (you just have to remember the string in some static variable). Then when you cat the mnt/hello file, this string appears.

The documentation on FUSE is scarce. Here are some resources:

Note: For students having trouble with virtual box (M1) and have not found a substitute, this can be down with a EC2 cloud computing instance. We can discuss in class if needed.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

author: burton rosenberg
created: 19 oct 2020
update: 29 oct 2021