Installation You can download libfuse from https://github.com/libfuse/libfuse/releases. To build and install, we recommend to use Meson and Ninja. After extracting the libfuse tarball, create a (temporary) build directory and run Meson: $ mkdir build; cd build $ meson .. Normally, the default build options will work fine. If you nevertheless want to adjust them, you can do so with the meson configure command: $ meson configure # list options $ meson configure -D disable-mtab=true # set an option To build, test and install libfuse, you then use Ninja: $ ninja $ sudo ninja install
root@cloud:~/virtio-fs/fuse-3.6.0/build# ls /lib/aarch64-linux-gnu/libf libfdisk.so.1 libfdisk.so.1.1.0 libfuse.so.2 libfuse.so.2.9.7 root@cloud:~/virtio-fs/fuse-3.6.0/build# ls /usr/local/lib/aarch64-linux-gnu/libfuse3.so libfuse3.so libfuse3.so.3 libfuse3.so.3.0.0 root@cloud:~/virtio-fs/fuse-3.6.0/build# ls /usr/local/lib/aarch64-linux-gnu/libfuse3.so
安装使用fuse
软件包下载https://github.com/libfuse/libfuse/releases:
下载软件包,解压后,编译安装。
./configure
make
make install
解压后的目录中有名为example的目录,其中有fuse自带的几种fuse用户态实现例子,可以运行其进行测试。
fuse安装完后,该目录中的文件也已经编译成功,只需运行即可(目录dir为挂载点,挂载成功后,在该目录中对文件的操作就会调用fuse自己实现的操作函数):
//example/hello.c 部分代码,主要实现文件系统的取文件属性、打开目录、读文件、打开文件
static struct fuse_operations hello_oper = { //文件操作函数,为回调函数
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
int main(int argc, char *argv[])
{
return fuse_main(argc, argv, &hello_oper, NULL); //主函数,会调用文件操作结构体
}
ty@ubuntu:~/program/fuse/fuse-2.9.6/example/dir$ mkdir dir //创建挂载点
ty@ubuntu:~/program/fuse/fuse-2.9.6/example/dir$ ./hello dir //将hello fuse文件系统挂载在dir目录上
根据目前实现的四个功能进行测试如下:
ty@ubuntu:~/program/fuse/fuse-2.9.6/example/dir$ ls
hello
ty@ubuntu:~/program/fuse/fuse-2.9.6/example/dir$ cat hello
Hello World!
ty@ubuntu:~/program/fuse/fuse-2.9.6/example/dir$ ls -l hello
-r--r--r-- 1 root root 13 12月 31 1969 hello
ty@ubuntu:~/program/fuse/fuse-2.9.6/example/dir$ rm -fr hello
rm: cannot remove ‘hello’: Function not implemented
ty@ubuntu:~/program/fuse/fuse-2.9.6/example/dir$ touch test
touch: cannot touch ‘test’: Function not implemented
ty@ubuntu:~/program/fuse/fuse-2.9.6/example/dir$ mkdir test
mkdir: cannot create directory ‘test’: Function not implemented
由测试可以发现在dir目录中只能对文件进行实现的四个功能的操作,其他的操作都无法完成,会提示用户函数没有实现。 ty@ubuntu:~/program/fuse/fuse-2.9.6/example/$ dirfusermount -u dir //卸载fuse文件系统dir