How FUSE works (lib level)

FUSE ( Filesystem in USEr space) is a loadable kernel module for Unix-like computer operating systems that lets non-privileged users create their own file systems without editing kernel code. This is achieved by running file system code in user space while the FUSE module provides only a “bridge” to the actual kernel interfaces.

So, with FUSE, we can implement our own file system without deep understanding of kernel or lower-level file operations. Generally speaking, FUSE includes three parts: (1) a kernel module (fuse.ko); (2) a userspace library (libfuse.*); (3) a mount utility (fusermount).

First, we analyze how fuse works on the library level.

(1)  Fuse_main()

When a user mode program calls fuse_main () (lib/helper.c), fuse_main parses the arguments like mountpoint and multithreaded and then calls the function fuse_mount() (lib/mount.c); meanwhile, fuse_main() calls fuse_new() (lib/fuse.c) to allocate spaces to store and maintain a cached image of the filesystem data;  further, it calls fuse_loop() (lib/fuse.c) or fuse_loop_mt() (lib/fuser_mt.c) to achieve receiving and processing sessions;

(2)  Fuse_mount()

Fuse_mount creates a UNIX domain socket pair , then forks and execs fusermount (util/fusermount.c); besides, fuse_mount() will return file handle of fuse module to fuser_main() after getting from fusermount;

(3)  Fusermount

Fusermount makes sure that the fuse module is loaded and then opens /dev/fuse and send the file handle over a UNIX domain socket back to fuse_mount();

(4)  Fuse_loop()

Reads system calls from /dev/fuse, calls functions defined in struct fuse_operation and then returns the result to /dev/fuse.

References:

  1. http://my.debugman.net/program/fuse-180.html
  2. http://fuse.sourceforge.net/
  3. http://www.digital-experts.de/doc/libfuse2/how-fuse-works
  4. http://en.wikipedia.org/wiki/Filesystem_in_Userspace

Leave a comment