#697·winfsp

FUSE maps read + append access to write-only on SSHFS-Win, resulting in bad reads

Author: CherryDTCreated Sep 29, 2026Updated Sep 29, 2026

Bug Report

Opening a file on an SSHFS-Win mount for read + append makes reads return EOF, even though the file is nonempty. I first hit this when Codex tried to resume a rollout file, but a small standalone file reproduces it. I couldn't find an existing report for this read + append combination.

This looks like a side effect of #261. In the FUSE open code, FILE_READ_DATA selects fi.flags = 0 (O_RDONLY). The append check then treats zero as if no mode was selected and changes it to 1 (O_WRONLY), despite the requested read access. The same code is present in v2.2B4, the latest beta; I have only tested the v2.1 binary.

How to Reproduce

With an SSHFS-Win drive mounted as U:, set $sshfsDir to a writable directory on that drive and run this in PowerShell. It creates and removes uniquely named test files on the mount and on local NTFS.

powershell
$ErrorActionPreference = 'Stop'
$sshfsDir = 'U:\path\to\writable\folder' # change this
Add-Type @'
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

public static class ReadProbe {
    [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    static extern SafeFileHandle CreateFileW(string path, uint access, uint share,
        IntPtr security, uint disposition, uint flags, IntPtr templateFile);
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern bool ReadFile(SafeFileHandle file, byte[] buffer, uint count,
        out uint bytesRead, IntPtr overlapped);

    public static string Run(string path, int mode) {
        uint access = mode == 0 ? 0x80000000U :
                      mode == 1 ? 0x80000004U : 0xC0000004U;
        using (var file = CreateFileW(path, access, 7, IntPtr.Zero, 3, 0x80, IntPtr.Zero)) {
            if (file.IsInvalid) return "open error=" + Marshal.GetLastWin32Error();
            uint bytesRead;
            bool ok = ReadFile(file, new byte[1], 1, out bytesRead, IntPtr.Zero);
            return "ok=" + ok + " bytes=" + bytesRead;
        }
    }
}
'@

foreach ($root in @($sshfsDir, (Join-Path $env:LOCALAPPDATA 'Temp'))) {
    $path = Join-Path $root ("winfsp-probe-" + [guid]::NewGuid().ToString('N') + '.txt')
    [IO.File]::WriteAllText($path, 'test')
    try {
        foreach ($mode in 0..2) {
            $name = @('read', 'read+append', 'read+write+append')[$mode]
            "$root $name $([ReadProbe]::Run($path, $mode))"
        }
    } finally {
        Remove-Item -LiteralPath $path
    }
}

Behaviors

  • Expected: all three opens can read one byte at offset 0 from the nonempty file.
  • Actual on U:: read returns bytes=1, read + append returns ok=True bytes=0, and read + write + append returns bytes=1. All three return bytes=1 on local NTFS. A 20 MB file gives the same result, so it isn't specific to small files.
  • In the Codex case, ProcMon showed the same EOF result when reading the last valid byte of the rollout file.

Possible fix

The fi.flags == 0 check cannot distinguish O_RDONLY from "no mode selected". One possible fix is to preserve read access when FILE_APPEND_DATA is present:

c
if ((GrantedAccess & FILE_APPEND_DATA) && fi.flags == 0)
    fi.flags = (GrantedAccess & FILE_READ_DATA)
        ? 2/*O_RDWR*/
        : 1/*O_WRONLY*/;

This would keep append-only opens write-only while making read + append opens readable. I haven't built or tested the change. It needs tests for both cases, including an actual append write. POSIX O_RDWR may not preserve Windows' narrower read + append-only permissions exactly, so a different approach may be needed for that case.

Environment

  • OS version and build: Windows 11 Pro, 10.0.26200
  • WinFsp version and build: WinFsp 2025, 2.1.25156
  • SSHFS-Win: 2021, 3.5.20357
  • Mount: U: is a mounted path to an SSH server via SSHFS-Win