Skip to content

Migrate from Dokany/DokanNet to WinFsp#43

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/migrate-dokany-to-winfsp
Draft

Migrate from Dokany/DokanNet to WinFsp#43
Copilot wants to merge 4 commits into
mainfrom
copilot/migrate-dokany-to-winfsp

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 4, 2026

Replace DokanNet driver layer with WinFsp (winfsp.net). Includes a comprehensive migration plan for future zero-heap read path using IMemoryOwner<byte> and memory-mapped files.

Driver swap

  • DokanNet 2.3.0.3 → winfsp.net 2.1.25156 in Directory.Packages.props
  • WinFspFileSystemAdapter extends Fsp.FileSystemBase — maps Open/Read/ReadDirectoryEntry/GetFileInfo/GetVolumeInfo to IVirtualFileSystem, all write ops → STATUS_ACCESS_DENIED
  • WinFspHostedService manages FileSystemHost mount lifecycle — FileSystemWatcher/ArchiveChangeConsolidator/reconciliation logic ported unchanged
  • FileContext carries per-handle path + isDirectory through WinFsp's FileNode/FileDesc pattern
// WinFsp Read: IntPtr buffer from kernel, Marshal.Copy from ArrayPool (transitional)
public override Int32 Read(Object FileNode, Object FileDesc,
    IntPtr Buffer, UInt64 Offset, UInt32 Length, out UInt32 BytesTransferred)
{
    var ctx = (FileContext)FileNode;
    byte[] rentedArray = ArrayPool<byte>.Shared.Rent((int)Length);
    try {
        int read = _vfs.ReadFileAsync(ctx.Path, rentedArray, (long)Offset).GetAwaiter().GetResult();
        Marshal.Copy(rentedArray, 0, Buffer, Math.Min(read, (int)Length));
        BytesTransferred = (uint)Math.Min(read, (int)Length);
        return STATUS_SUCCESS;
    } finally { ArrayPool<byte>.Shared.Return(rentedArray); }
}

Telemetry

  • DokanTelemetryFileSystemTelemetry, meter ZipDrive.DokanZipDrive.FileSystem

Migration plan (src/Docs/WINFSP_MIGRATION_PLAN.md)

Documents future phases:

  • Phase 2: IBufferHandle / ReadFileDirectAsync for zero-copy read path through IVirtualFileSystem
  • Phase 3: MmapStorageStrategy replacing MemoryStorageStrategy's byte[] with anonymous MemoryMappedFile + MmapMemoryManager for pointer-backed Memory<byte> — eliminates per-read GC allocation
  • Phase 5: mmap over ChunkedDisk sparse files for large file zero-copy

Target read path (cache hit): mmap pointer → Unsafe.CopyBlock → WinFsp IntPtr — zero managed heap allocations.

Removed

  • DokanFileSystemAdapter.cs, DokanHostedService.cs, DokanTelemetry.cs
  • All Dokan references in source comments, CLAUDE.md, test files

Copilot AI and others added 3 commits April 4, 2026 05:17
…Tests

Replace all references to the renamed class across 10 endurance test
files to fix build errors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: hooyao <659145+hooyao@users.noreply.github.com>
Replace all remaining Dokan/DokanNet references with their WinFsp equivalents:
- DokanFileSystemAdapter → WinFspFileSystemAdapter
- DokanHostedService → WinFspHostedService
- DokanTelemetry → FileSystemTelemetry (meter: ZipDrive.FileSystem)
- IDokanOperations2 → Fsp.FileSystemBase
- Dokany driver → WinFsp driver
- dokan2.dll → winfsp-x64.dll

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: hooyao <659145+hooyao@users.noreply.github.com>
Copilot AI changed the title [WIP] Plan migration from Dokany to WinFsp with zero heap location Migrate from Dokany/DokanNet to WinFsp Apr 4, 2026
Copilot AI requested a review from hooyao April 4, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants