Skip to content
Liryna edited this page Aug 25, 2023 · 27 revisions

Dokan FUSE

Dokan Fuse is a wrapper library that makes Dokan compatible with FUSE API. Now available by default in main source repository and installers, Dokan Fuse comes from an original work of Alex Besogonov, fuse4win project.

To use it, you only have to link with the dynamic library dokanfuse.dll.

TODO

  • Currently special entries '.' and '..' in walk_directory/walk_directory_getdir are not processed correctly. Particularly, they have incorrect timestamps. Fix this.
  • Try to emulate Unix permissions using Windows ACLs.
  • Fix symlink handling.

FUSE / Dokan map

The table bellow describes the approximate mapping required if you attempt to port your FUSE application manually without Dokan Fuse.

FUSE Dokan
fuse_operations::mknod
fuse_operations::create
fuse_operations::open
fuse_operations::mkdir
fuse_operations::opendir
DOKAN_OPERATIONS::ZwCreateFile
fuse_operations::release
fuse_operations::releasedir
DOKAN_OPERATIONS::Cleanup
fuse_operations::read DOKAN_OPERATIONS::ReadFile
fuse_operations::write DOKAN_OPERATIONS::WriteFile
fuse_operations::flush DOKAN_OPERATIONS::FlushFileBuffers
fuse_operations::readdir DOKAN_OPERATIONS::FindFiles
fuse_operations::utimens DOKAN_OPERATIONS::SetFileAttributes
fuse_operations::getattr DOKAN_OPERATIONS::GetFileInformation
fuse_operations::access DOKAN_OPERATIONS::GetFileSecurity
fuse_operations::unlink DOKAN_OPERATIONS::DeleteFile
fuse_operations::rmdir DOKAN_OPERATIONS::DeleteDirectory
fuse_operations::rename DOKAN_OPERATIONS::MoveFile
fuse_operations::truncate
fuse_operations::ftruncate
DOKAN_OPERATIONS::SetEndOfFile
fuse_operations::lock DOKAN_OPERATIONS::LockFile
DOKAN_OPERATIONS::UnlockFile
fuse_operations::chmod
fuse_operations::chown
DOKAN_OPERATIONS::SetFileSecurity
fuse_operations::statfs DOKAN_OPERATIONS::GetDiskFreeSpace
DOKAN_OPERATIONS::GetVolumeInformation

Rename & Remove issue

Depending of your FUSE implementation, it is possible that you have an error when you try to rename or remove a file. This is happening because Linux & Windows handle differently how a file is rename & removed. See https://github.com/dokan-dev/dokany/issues/178#issuecomment-187881947 for more informations.

Compiler

You need to use the same toolchain to compile your own dokanfuse and your FUSE program to make it compatible. Neglect of doing so will result in mysterious problems like stack overflows and BSOD.

MSVC

If you use MSVC to compile your FUSE program you have to use struct FUSE_STAT instead of struct stat in the source code. The dokanfuse1.dll distributed is compiled by MSVC, which means it's not compatible with other compilers for types used in other compilers are not all the same.

Cygwin

The cygdokanfuse1.dll distributed is compiled by cygwin gcc. You can also build it yourself with:

cd dokan_fuse/
cmake .
make

Be aware that cygdokanfuse1.dll has dependencies to cygwin1.dll, cyggcc_s-seh-1.dll and cygstdc++-6.dll.

As a sample, to build fusexmp (mirror sample on libfuse project or /samples/fuse_mirror/) use the following command line:

gcc fusexmp.c -I../../include -D_FILE_OFFSET_BITS=64 -L. -lcygdokanfuse1 -o fuxexmp.exe

Run

./fusexmp.exe m       # Mount a clone of Cygwin / as drive M:\

mingw-w64

mingw-w64 compilers are available on many linux distributions and can be used to cross-compile Dokan FUSE. If you compile your FUSE program with mingw-w64, you have to use struct FUSE_STAT instead of struct stat in your FUSE program.

You may need a cmake Toolchain file for cross-compilation, here is an example for x86_64-w64-mingw32:

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# The following line links the shared library libdokanfuse1.dll statically, so it won't depend on any additional dlls.
set(CMAKE_SHARED_LINKER_FLAGS "-static -static-libgcc -static-libstdc++" CACHE STRING "" FORCE)

set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

For other mingw32-w64 compilers, just adjust TOOLCHAIN_PREFIX.

Then, you can build it as follows:

cd dokan_fuse/
cmake -DCMAKE_TOOLCHAIN_FILE="your_toolchain_file.cmake"
make

Using FUSE in other languages

Language Project
Python fusepy
Javascript fuse-bindings, fuse4js
Java fuse-jna, jnr-fuse
Ruby rfusefs
.NET (C#, VB.NET ...) mono-fuse