libfuse

Linux FUSE(用户空间中的文件系统)接口的参考实现。「The reference implementation of the Linux FUSE (Filesystem in Userspace) interface」

  • 所有者: libfuse/libfuse
  • 平台: BSD, Linux
  • 許可證: Other
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

libfuse

简介

FUSE(Filesystem in Userspace)是用户空间程序向 Linux 内核输出文件系统的一个接口。FUSE 项目由两部分组成:fuse 内核模块(维护在常规的内核资源库中)和 libfuse 用户空间库(维护在这个资源库中)。libfuse 提供了与 FUSE 内核模块通信的参考实现。

FUSE 文件系统通常是作为一个独立的应用程序来实现的,它与 libfuse 相连接。libfuse 提供了一些函数来挂载文件系统、卸载文件系统、读取来自内核的请求以及发送响应。libfuse 提供了两个 API:"高级" 的同步 API 和 "低级" 的异步 API。在这两种情况下,从内核传入的请求都会通过回调传递给主程序。当使用高层次的 API 时,回调可以使用文件名和路径而不是 inodes,当回调函数返回时,请求的处理就结束了。当使用低级 API 时,回调必须使用 inodes,并且必须使用单独的 API 函数集明确发送响应。

开发状态

所有主要的 Linux 发行版都会提供 libfuse,并且多年来一直在广泛的系统中生产使用。然而,目前 libfuse 并没有任何活跃的定期贡献者。目前的维护者继续应用拉取请求并定期发布,但遗憾的是,除了解决影响较大的问题外,没有能力进行任何开发。当报告 bug 时,请理解,除非你包含一个拉取请求或报告一个关键问题,否则你可能不会得到回应。如果您正在使用 libfuse,请考虑为项目做出贡献。

支持的平台

  • Linux(完全)
  • BSD(大部分/尽力而为)
  • 对于 OS-X,请使用 OSXFUSE

安装

你可以从 https://github.com/libfuse/libfuse/releases 下载 libfuse。我们推荐使用 MesonNinja 来构建和安装。解压 libfuse 压缩包后,创建一个(临时)编译目录并运行 Meson。

$ mkdir build; cd build
$ meson ..

通常情况下,默认的联编选项可以正常工作。如果你还是想调整它们,你可以使用 meson configure 命令来实现。

$ meson configure # list options
$ meson configure -D disable-mtab=true # 设置一个选项

要构建、测试和安装 libfuse,你可以使用 Ninja。

$ ninja
$ sudo python3 -m pytest test/
$ sudo ninja install

运行测试需要使用 py.test Python 模块。如果先将 util/fusermount3 设为 setuid root,大部分测试也可以以普通用户的身份运行,而不是以 root 身份运行。

所涉安全问题

fusermount3 程序安装 setuid root。这样做的目的是为了让普通用户能够挂载自己的文件系统实现。

为了限制恶意用户通过这种方式造成的危害,fusermount3 执行了以下限制。

  • 用户只能挂载在他们有写权限的挂载点上。
  • 挂载点不能是一个不属于用户的粘性目录(比如/tmp通常是)。
  • 任何其他用户(包括 root)都不能访问被挂载的文件系统的内容(尽管可以通过在 /etc/fuse.conf 中使用 allow_other 和 allow_root 挂载选项来放宽限制)。

如果您打算使用 allow_other mount 选项,请注意 FUSE 有一个未解决的安全问题:如果不使用 default_permissions mount 选项,只要被访问的目录的 inode 在内核缓存中存在,文件系统对该目录的第一次权限检查的结果就会在后续的访问中被重新使用--即使权限已经改变,即使后续的访问是由不同的用户进行的。如果文件系统只被挂载用户访问(反正挂载用户对文件系统有完全的访问权),这个问题就不太重要了,但是当其他用户被允许访问文件系统时,这个问题就变成了一个安全问题(因为他们可以利用这个问题在文件系统上执行他们没有实际权限的操作)。

这个 bug 需要在 Linux 内核中进行修复,并且从 2006 年开始就已经知道了,但遗憾的是至今还没有修复。如果你依赖 FUSE 文件系统的正确权限处理,唯一的变通方法是使用 default_permissions(目前不支持 ACL),或者完全禁用目录条目属性的缓存。

构建你自己的文件系统

FUSE 在示例目录中自带了几个示例文件系统。例如,passthrough 例子镜像了挂载点下根目录的内容。从那里开始改编代码!

API 函数和必要的回调文档主要包含在文件 include/fuse.h(高级 API)和 include/fuse_lowlevel.h(低级 API)中。在 doc/html 目录下和 http://libfuse.github.io/doxygen,有一个自动生成的 html 版本的 API。

获得帮助

如果您需要帮助,请在 fuse-devel@lists.sourceforge.net 邮件列表中询问(在 https://lists.sourceforge.net/lists/listinfo/fuse-devel 订阅)。

请在 GitHub 问题跟踪器上报告任何错误,网址为:
https://github.com/libfuse/libfuse/issues

(vz Revised on 2020.12.27)

主要指標

概覽
名稱與所有者libfuse/libfuse
主編程語言C
編程語言C (語言數: 7)
平台BSD, Linux
許可證Other
所有者活动
創建於2015-12-19 20:27:34
推送於2025-06-22 16:15:28
最后一次提交2025-06-22 20:00:39
發布數146
最新版本名稱fuse-3.17.2 (發布於 2025-04-24 01:20:09)
第一版名稱start (發布於 )
用户参与
星數5.7k
關注者數163
派生數1.2k
提交數2.2k
已啟用問題?
問題數547
打開的問題數43
拉請求數503
打開的拉請求數16
關閉的拉請求數130
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

libfuse

About

FUSE (Filesystem in Userspace) is an interface for userspace programs
to export a filesystem to the Linux kernel. The FUSE project consists
of two components: the fuse kernel module (maintained in the regular
kernel repositories) and the libfuse userspace library (maintained
in this repository). libfuse provides the reference implementation
for communicating with the FUSE kernel module.

A FUSE file system is typically implemented as a standalone
application that links with libfuse. libfuse provides functions to
mount the file system, unmount it, read requests from the kernel, and
send responses back. libfuse offers two APIs: a "high-level",
synchronous API, and a "low-level" asynchronous API. In both cases,
incoming requests from the kernel are passed to the main program using
callbacks. When using the high-level API, the callbacks may work with
file names and paths instead of inodes, and processing of a request
finishes when the callback function returns. When using the low-level
API, the callbacks must work with inodes and responses must be sent
explicitly using a separate set of API functions.

Development Status

libfuse is shipped by all major Linux distributions and has been in
production use across a wide range of systems for many years. However,
at present libfuse does not have any active, regular contributors. The
current maintainer continues to apply pull requests and makes regular
releases, but unfortunately has no capacity to do any development
beyond addressing high-impact issues. When reporting bugs, please
understand that unless you are including a pull request or are
reporting a critical issue, you will probably not get a response. If
you are using libfuse, please consider to contribute to the project.

Supported Platforms

  • Linux (fully)
  • BSD (mostly/best-effort)
  • For OS-X, please use OSXFUSE

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 mesonconf
command:

$ mesonconf # list options
$ mesonconf  -D disable-mtab=true # set an option

To build, test and install libfuse, you then use Ninja:

$ ninja
$ sudo python3 -m pytest test/
$ sudo ninja install

Running the tests requires the py.test
Python module. Instead of running the tests as root, the majority of
tests can also be run as a regular user if util/fusermount3 is made
setuid root first:

$ sudo chown root:root util/fusermount3
$ sudo chmod 4755 util/fusermount3
$ python3 -m pytest test/

Security implications

The fusermount3 program is installed setuid root. This is done to
allow normal users to mount their own filesystem implementations.

To limit the harm that malicious users can do this way, fusermount3
enforces the following limitations:

  • The user can only mount on a mountpoint for which they have write
    permission

  • The mountpoint must not be a sticky directory which isn't owned by
    the user (like /tmp usually is)

  • No other user (including root) can access the contents of the
    mounted filesystem (though this can be relaxed by allowing the use
    of the allow_other and allow_root mount options in
    /etc/fuse.conf)

If you intend to use the allow_other mount options, be aware that
FUSE has an unresolved security
bug
: if the
default_permissions mount option is not used, the results of the
first permission check performed by the file system for a directory
entry will be re-used for subsequent accesses as long as the inode of
the accessed entry is present in the kernel cache - even if the
permissions have since changed, and even if the subsequent access is
made by a different user. This is of little concern if the filesystem
is accessible only to the mounting user (which has full access to the
filesystem anyway), but becomes a security issue when other users are
allowed to access the filesystem (since they can exploit this to
perform operations on the filesystem that they do not actually have
permissions for).

This bug needs to be fixed in the Linux kernel and has been known
since 2006 but unfortunately no fix has been applied yet. If you
depend on correct permission handling for FUSE file systems, the only
workaround is to use default_permissions (which does not currently
support ACLs), or to completely disable caching of directory entry
attributes.

Building your own filesystem

FUSE comes with several example file systems in the examples
directory. For example, the passthrough examples mirror the contents
of the root directory under the mountpoint. Start from there and adapt
the code!

The documentation of the API functions and necessary callbacks is
mostly contained in the files include/fuse.h (for the high-level
API) and include/fuse_lowlevel.h (for the low-level API). An
autogenerated html version of the API is available in the doc/html
directory and at http://libfuse.github.io/doxygen.

Getting Help

If you need help, please ask on the fuse-devel@lists.sourceforge.net
mailing list (subscribe at
https://lists.sourceforge.net/lists/listinfo/fuse-devel).

Please report any bugs on the GitHub issue tracker at
https://github.com/libfuse/libfuse/issues.

Professional Support

Professional support is offered via Rath
Consulting
.