FUSE makes it possible to implement a filesystem in a userspace program. Features include: simple yet comprehensive API, secure mounting by non-root users, support for 2.4 and 2.6 Linux kernels, multi-threaded operation. etc…

FUSE是一个内核文件系统的接口,通过该接口可以在用户空间实现一个文件系统,将其mount到内核;这样说可能比较抽象,形象一点就是可以把任何东西都做成本地文件系统来用,例如:gmailfs(将gmail当本地硬盘来用), blogfs(将wordpress放到本地), sshfs……更多

linux2.6内核已经默认支持fuse模块,通过modprobe fuse加载。安装很简单,下载,configure/make/make install即可。 FUSE支持很多语言接口,我使用的是python:FusePython,安装过程如下: <pre class=php name=code>linux-cjfq:~/fusepy/python # python setup.py build running build running build_py creating build creating build/lib.linux-i686-2.4 copying fuse.py -> build/lib.linux-i686-2.4 creating build/lib.linux-i686-2.4/fuseparts copying fuseparts/setcompatwrap.py -> build/lib.linux-i686-2.4/fuseparts copying fuseparts/subbedopts.py -> build/lib.linux-i686-2.4/fuseparts copying fuseparts/init.py -> build/lib.linux-i686-2.4/fuseparts running build_ext building ‘fuseparts._fusemodule’ extension creating build/temp.linux-i686-2.4 creating build/temp.linux-i686-2.4/fuseparts gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -fPIC -I/usr/local/include/fuse -I/usr/include/python2.4 -c fuseparts/_fusemodule.c -o build/temp.linux-i686-2.4/fuseparts/_fusemodule.o -D_FILE_OFFSET_BITS=64 gcc -pthread -shared build/temp.linux-i686-2.4/fuseparts/_fusemodule.o -L/usr/local/lib -lfuse -lrt -ldl -o build/lib.linux-i686-2.4/fuseparts/_fusemodule.so </pre> FusePython的example中带了两个例子,

  1. hello.py: 虚拟一个只带hello文件的文件系统

<pre class=php name=code># python hello.py /mnt

cat /mnt/hello

Hello World!</pre>

  1. xmp.py 将根目录虚拟成一个文件系统,执行后可以看到/mnt目录下的内容与/下相同

<pre class=php name=code># python xmp.py /mnt</pre>


Simon Lee

My blog