jetwhiz / encfs4win

Windows port of EncFS
https://encfs.win
Other
399 stars 41 forks source link

GetFinalPathNameByHandle fails with ERROR_FILE_NOT_FOUND #130

Closed rustyx closed 4 years ago

rustyx commented 4 years ago

Environment

Description

For some reason Git isn't working with a repo mounted via encfs4win (I remember it did before, but don't know what/where changed).

I traced the issue down to the call to GetFinalPathNameByHandle which on my system fails with error 2, ERROR_FILE_NOT_FOUND.

Here's a test program to reproduce the issue.

#include <stdio.h>
#include <Windows.h>

int main(int argc, char**argv) {
    char buf[512];
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <some path>\n", argv[0]);
        return 1;
    }
    HANDLE hnd = CreateFileA(
        argv[1], 0,
        FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
        NULL, OPEN_EXISTING, 0, NULL);
    if (hnd == INVALID_HANDLE_VALUE) {
        fprintf(stderr, "CreateFile(%s) failed, LastError %d\n", argv[1], GetLastError());
        return 1;
    }
    if (!GetFinalPathNameByHandleA(hnd, buf, sizeof(buf), 0)) {
        fprintf(stderr, "GetFinalPathNameByHandle(%s) failed, LastError %d\n", argv[1], GetLastError());
        return 1;
    }
    printf("OK: %s\n", buf);
}

It works for any path outside encfs4win and fail for any path inside encfs4win. Any idea how to debug this further?

Also tried with Dokan 0.7.4, same issue.

rustyx commented 4 years ago

Just to add to this, I got it working again by disabling symlinks in Git settings and removing the MSYS environment variable (when MSYS=winsymlinks:nativestrict, symlinks are enabled again).

Nevertheless,it seems GetFinalPathNameByHandle never worked, and it would be nice to have it working finally.

jetwhiz commented 4 years ago

Are you running this inside Cygwin/MSYS, or natively in Windows?

jetwhiz commented 4 years ago

If I'm understanding your issue correctly, I expect this is related to the known upstream issue in Dokany, since it does not support symlinks: https://github.com/dokan-dev/dokany/issues/343

rustyx commented 4 years ago

I'm running natively and there are no symlinks in the picture; GetFinalPathNameByHandle simply always fails for any file on the encrypted drive. Although the issue is probably in dokan code, I just don't know how to diagnose it.

jetwhiz commented 4 years ago

You can get Dokany to output debug information (though it is very verbose) by using:

encfs.exe path mountpoint -- -d

This might help to figure out what Dokany is doing and why that call is failing.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

rustyx commented 4 years ago

There isn't much to see in the encfs -d output unfortunately. Here's what I get:

###Create 0009
   CreateDisposition 0x00000001
CreateFile : \test.git
    AccessMode: SYNCHRONIZE|FILE_READ_ATTRIBUTES
    ShareMode: FILE_SHARE_DELETE|FILE_SHARE_WRITE|FILE_SHARE_READ
    Disposition: OPEN_EXISTING (3)
    Flags: 0 (0x0)
CreateFile status = 0
###Cleanup 0009
Cleanup: \test.git

At the same time the output from the test program is: GetFinalPathNameByHandle(Z:\test.git): The system cannot find the file specified.

How to debug this further?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

rustyx commented 4 years ago

Bump.

jetwhiz commented 4 years ago

Did you say this worked after you disabled symlinks in Git? Or does it not work even in that case? encfs4win cannot handle symbolic links if that is the case.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.