分类:
2008-09-10 16:10:04
With FUSE it is possible to implement a fully functional filesystem in a userspace program. Features include:
FUSE was originally developed to support but it has since became a separate project. Now quite a few other are using it. Implementing a filesystem is simple, a filesystem is less than a 100 lines long. Here's a sample session:
~/fuse/example$ mkdir /tmp/fuse |
Some projects include the whole FUSE package (for simpler installation). In other cases or just to try out the examples FUSE must be installed first. The installation is simple, after unpacking enter:
> ./configure |
If this produces an error, please read on.
The configure script will try to guess the location of the kernel source. In case this fails, it may be specified using the --with-kernel parameter. Building the kernel module needs a configured kernel source tree matching the running kernel. If you build your own kernel this is no problem. On the other hand if a precompiled kernel is used, the kernel headers used by the FUSE build process must first be prepared. There are two possibilities:
After installation, you can try out the filesystems in the example directory. To see what is happening try adding the -d option. This is the output produced by running cat /tmp/fuse/hello in another shell:
~/fuse/example> ./hello /tmp/fuse -d |
More operations can be tried out with the fusexmp example filesystem. This just mirrors the root directory similarly to mount --bind / /mountpoint. This is not very useful in itself, but can be used as template for creating a new filesystem.
By default FUSE filesystems run multi-threaded. This can be verified by entering the mountpoint recursively in the fusexmp filesystem. Multi-threaded operation can be disabled by adding the -s option.
Some options can be passed to the FUSE kernel module and the library. See the output of fusexmp -h for the list of these options.
The following figure shows the path of a filesystem call (e.g. stat) in the above hello world example:
The FUSE kernel module and the FUSE library communicate via a special file descriptor which is obtained by opening /dev/fuse. This file can be opened multiple times, and the obtained file descriptor is passed to the mount syscall, to match up the descriptor with the mounted filesystem.