1UserlandFS: filesystems in userspace 2#################################### 3 4UserlandFS was initially designed as a development tool allowing to run existing filesystems in 5userspace. However, it turns out being able to do that is pretty useful outside of debugging 6sessions too. 7 8UserlandFS can load 3 types of filesystems, which are loaded as add-ons in an userlandfs_server 9process. The process communicates with the kernel side of userlandfs to get the filesystem requests 10and send back the responses. 11 12UserlandFS exposes three different APIs to filesystem add-ons: one compatible with the Haiku kernel, 13one compatible with the BeOS one, and one compatible with FUSE. 14 15The communication between the kernel and userlandfs_server is identical no matter which filesystem 16API is being used. The only differences are in the server itself, which will create an instance of 17the correct subclass of Volume and forward the requests to it. 18 19The FUSE API 20============ 21 22FUSE is a similar tool to UserlandFS. It was initially designed for Linux, but, because there are 23many filesystems written for it, it was later ported to MacOS and FreeBSD. The FUSE project in 24itself defines a network-like communication protocol between the kernel and the filesystem, however, 25this is not what is implemented in UserlandFS (which already has its own way to do this part). 26Instead, the provided API is compatible with libfuse (version 2.9.9, since most filesystems 27available for FUSE have not migrated to libfuse 3.x yet). 28 29This means only filesystems using libfuse can easily be ported. Those implementing the FUSE protocol 30in other ways (for example because they are not written in C or C++ and need a different library) 31will not be ported to Haiku as easily. 32 33The libfuse API is actually two different APIs. One is called "fuse_operations". It is a quite 34high level API, where all functions to access files receive a path to the file to operate on, and 35the functions are synchronous. The other API (called "low level") is asynchronous and the files 36are identified by their inode number. Of course, the low level API allows to get better performance, 37because the kernel and userlandfs already work with inode numbers internally. With the high level 38API, the inode number has to be converted back to a filepath everytime a function is called. 39 40Each FUSE filesystem uses one of these two APIs. UserlandFS implements both of them and will 41automatically detect which one to use. 42 43Because of the Linux FUSE design, normally each filesystem is a standalone application, that 44directly establishes communication with the kernel. When built for UserlandFS, the filesystems are 45add-ons instead, so their main() function is called from userlandfs_server after loading the add-on. 46 47We have found that this works reasonably well and it will be possible to run most filesystems 48without any changes to their sourcecode. 49 50When they initialize, FUSE filesystems provide userlandfs with a struct containing function pointers 51for the various FUSE operations they implement. From this table, userlandfs_server detects which 52features are supported, and reports this back to the kernel. Then the kernel-side of userlandfs 53knows to not forward to userspace requests that wouldn't be handled by the filesystem anyway. 54 55FUSE filesystems also usually need some command line options (both custom ones, and standard ones 56forwarded to FUSE initialization options). In Haiku, these are passed as mount options which are 57forwarded to the filesystem add-on when starting it. The add-on main function will be called only 58when a filesystem of the corresponding type is being mounted. 59 60Extensions to the FUSE API 61-------------------------- 62 63The FUSE API is missing some things that are possible in Haiku native filesystems. Specifically, 64there is no possibility to implement the "get_fs_info" call, and in particular use it to set 65volume flags. This is especially annoying for networked filesystems, where it is important to mark 66the filesystem as "shared". 67 68Therefore, an extra FUSE "capability" has been added to mark support for this. Capabilities are the 69way FUSE negociates features between the kernel and the filesystem. The kernel tells the filesystem 70which capabilities are supported, and the filesystem tells the kernel which one it wants to use. 71 72If the FUSE_CAP_HAIKU_FUSE_EXTENSIONS capability is enabled, userlandfs will query the filesystem 73info using the ioctl hook of the filesystem, with a command value FUSE_HAIKU_GET_DRIVE_INFO. It 74expects the filesystem to then fill the fs_info structure passed in the ioctl pointer. 75 76Debugging userlandfs 77==================== 78 79Because a lot of the code is in userspace, you can simply start userlandfs_server in a terminal to 80get its output, or attach a Debugger to it. There is no timeout for userlandfs requests, so if you 81are debugging something in userlandfs_server, all calls to the filesystem mounted through it will 82simply block until the request thread is running again. 83