Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DokanInstanceBuilder.Build returns before file system is ready #1210

Open
lostmsu opened this issue Apr 18, 2024 · 1 comment
Open

DokanInstanceBuilder.Build returns before file system is ready #1210

lostmsu opened this issue Apr 18, 2024 · 1 comment

Comments

@lostmsu
Copy link
Contributor

lostmsu commented Apr 18, 2024

Trying to access the new file system immediately after it is built fails with ERROR_INVALID_FUNCTION or ERROR_INVALID_PARAMETER (depending on type of access).

IMHO, Build by default should wait for the file system to be ready.

Workaround

const uint ERROR_INVALID_PARAMETER = 0x0057;
bool done = false;
while(!done) {
    try {
        mountDir.EnumerateFileSystemInfos().Any();
        done = true;
    } catch (IOException e)
        when (GetWin32Error(e.HResult) == ERROR_INVALID_PARAMETER) {
        await Task.Delay(TimeSpan.FromMilliseconds(25), cancel)
                  .ConfigureAwait(false);
    }
}

static uint GetWin32Error(int hResult)
    => unchecked((uint)hResult) & 0xFFFF;

See also dokan-dev/dokan-dotnet#356

@Liryna
Copy link
Member

Liryna commented Apr 19, 2024

This might be due to DokanCreateFileSystem returning before DispatchDedicatedIoCallback worker threads (which fully enable the device when they first reach the kernel and register themselves).
We would need to add a logic that they signal they get there.

dokany/dokan/dokan.c

Lines 824 to 826 in 69e3d88

QueueIoEvent(ioEvent, allowIpcBatching
? DispatchBatchIoCallback
: DispatchDedicatedIoCallback);

Moving to dokany repository since it is a native improvement.

@Liryna Liryna transferred this issue from dokan-dev/dokan-dotnet Apr 19, 2024
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

No branches or pull requests

2 participants