You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the FUSE API for Cygwin v1.2POST1 / 2017.2 in EncFS port, I spent many hours trying to make Cygwin absolute symlinks to correctly show-up though FUSE EncFS.
Here is what I get :
Then I discovered and tested -o rellinks :
And going through the code, I found this, fuse_intf.c#L511 : /* we do not support absolute paths without the rellinks option */
Why can't we support absolute symlinks without -o rellinks ?
(I should have recorded more of my thoughts when I wrote that code comment. It is hard to recall all the details.)
Symbolic links in Windows (the file system kind, not the NTOS object manager kind) come in 3 different flavors:
Absolute cross-device symlinks (i.e. from one drive to another).
Device-relative symlinks (i.e. symlinks that are absolute within the drive, but not across drives).
Relative symlinks.
It is not obvious what an absolute POSIX symlink should map to when on Windows.
It cannot map to a cross-device symlink, because that is a Windows-only concept.
It cannot cleanly map to a device-relative symlink, because this would make it relative to the root of the mounted file system rather than the overall file system root as it is the intent on POSIX.
Consider a file system mounted on /mnt in UNIX and a symlink in it that points to /mnt/data. Absolute symlinks in POSIX are interpreted from /, so this points to the /data subdirectory of our file system.
On Windows there is no overall file system root (no \). If we choose to encode /mnt/data as a device-relative symlink, we end up pointing to the \mnt\data directory in our file system. Even if we mount the file system at C:\mnt the directory this resolves to is C:\mnt\mnt\data and not the desired C:\mnt\data.
As the POSIX symlinks are created on a POSIX system (for instance Cygwin), they are certainly intended to be used through a POSIX system (once again Cygwin in this case).
Perhaps we could then think about a "passthrough" mode for POSIX links ?
They would fail to resolve on Windows, but would succeed in Cygwin.
Or improve -o rellinks with a path parameter ? -o rellinks : would keep the current default behavior -o rellinks=/ -o rellinks=/cygdrive/c -o rellinks=/cygdrive/x
I think this solution would suit all needs.
Let us consider your proposal of -o rellinks=/cygdrive/x.
Suppose that at some point there is a symbolic link foo -> /cygdrive/x/bar on the FUSE file system (/cygdrive/x). An application opens foo. Here is what happens next:
NtCreateFile("\Device\Volume{GUID}\foo"). An internal NT API that the application calls (directly or indirectly).
IRP_MJ_CREATE: The WinFsp FSD receives a request to "create" (open) a file object for \foo.
FspFileSystemCreate: The WinFsp DLL receives the request in user-mode. It queries the FUSE file system using getattr('/foo') and finds out that this is a symlink. It reads the symlink using readdir. It converts the received symlink (/cygdrive/x/bar) to a Windows reparse point and returns it to the FSD together with a special status code STATUS_REPARSE. (This is currently disallowed without the -o rellinks option.)
The FSD sees the STATUS_REPARSE and rewrites the file path from \foo to \cygdrive\x\bar and then resends the request to user mode. Inevitably this will fail, because \cygdrive\x is not a real directory in the file system.
The problem here is that the /cygdrive prefix does not mean anything outside Cygwin. The FSD does not know how to resolve it.
There are ways that some of this could be made to work, but it raises the question. Why is -o rellinks not good enough?
The -o rellinks option "promises" that absolute symlinks found in the file system really point inside the file system. So if you see a /cygdrive/x symlink in your file system, there is supposed to be a file called /cygdrive/x in that file system.
The switch works well for most purposes, except for programs that deeply care that they can retrieve using readlink what they put there using symlink. The only programs I have seen that really care are usually file system test suites. Do you have any other examples?
Bill, thank you for your detailed comment once again 👍
Note that I just "discovered" that -o rellinks is a FUSE option, not a specific WinFsp option. I never used it before. So of course my proposal above to modify this option is pointless... Sorry for this...
I have no other example of programs which would care about absolute symlink consistency, but perhaps some programs running in Cygwin only.
I made some further testing, as shown in the picture below :
So here we have a FUSE FS (EncFS) mounted on X: (/cygdrive/x) which gives a decrypted view of what is crypted on C: (/cygdrive/c). -o rellinks is on.
We have a file ben.txt and rellink.txt pointing to /ben.txt, which has been translated to /cygdrive/c/ben.txt.
I'm still surprised it is not translated to /cygdrive/x/ben.txt instead, as we work on x, not on c.
I'm also surprised that Windows manages to correctly show (and open) rellink.txt, as /cygdrive/c/ben.txt itself does not exist (but its encrypted filename).
Cygwin however fails following / opening this link.
We also have link.txt pointing to //ben.txt.
Sounds like here -o rellinks does not translate this link, but at least allows WinFsp to display it, this is what I was trying to do.
And here, Windows also correctly displays (and opens) this link.
So tu sum-up these "findings" :
I would say -o rellinks does not point to the correct drive ?
what about allowing absolute links without -o rellinks (through a new option for example) ? Sounds like this condition would just have to be relaxed ?
Thank you again, sounds like this is quite a tricky subject !
Sorry, I should have began with this... I'm more a UNIX user than a Windows one, so certainly forgot some basis things...
So links are created with ln -s on Cygwin.
FUSE FS (EncFS in this example) sees them as links (S_ISLNK(stat->st_mode)), and then shows them as links. If their target is absolute, the links will not show-up if -o rellinks is not used.
So I think they could, showing their original/raw target.
And sounds like (but I may be wrong as I don't master everything here), that -o rellinks, when used, does not point to the correct device (for instance it points to /cygdrive/c instead of /cygdrive/x).
Ok, I suspect that some of what you are seeing has to do with the mismatch of Cygwin symlinks (which are POSIX compatible) and Windows symlinks (which are not).
Suppose that you create a Cygwin symlink with ln -s /cygdrive/x/foo bar. Cygwin knows how to interpret this, but Windows and WinFsp do not. They simply assume that /cygdrive/x/foo means a file foo inside a directory x inside a directory cygdrive under the mounted file system root; they do not give any special interpretation to /cygdrive/x.
I do not think that EncFS can be used with absolute Cygwin symlinks currently. The -o rellinks switch cannot help, because it includes the promise that all absolute symlinks point inside the file system (i.e. the file system acts as the overall system root) and that is not the case with /cygdrive/x.
It could be argued that we should change WinFsp-FUSE to allow some limited absolute symlinks and allow paths such as /cygdrive/x and /proc/cygdrive/x when on Cygwin. I believe it is possible to use Cygwin API's to determine the correct cygdrive prefix and strip if it is there. But this is a non-trivial change and IMO rather low priority.
Thank you Bill.
I agree this is clearly not a priority.
Goal was also to understand how it works / where the "issue" comes from.
Thanks for all, closing this for now until this is really needed.
Thx 👍
For completeness, I discovered that Cygwin may handle symlinks in different ways thanks to the winsymlinks value of the CYGWIN environment variable.
And I also found that the absolute dir pointed by -o rellinks depends on the active/current directory.
Activity
billziss-gh commentedon Mar 25, 2018
(I should have recorded more of my thoughts when I wrote that code comment. It is hard to recall all the details.)
Symbolic links in Windows (the file system kind, not the NTOS object manager kind) come in 3 different flavors:
It is not obvious what an absolute POSIX symlink should map to when on Windows.
Consider a file system mounted on
/mntin UNIX and a symlink in it that points to/mnt/data. Absolute symlinks in POSIX are interpreted from/, so this points to the/datasubdirectory of our file system.On Windows there is no overall file system root (no
\). If we choose to encode/mnt/dataas a device-relative symlink, we end up pointing to the\mnt\datadirectory in our file system. Even if we mount the file system atC:\mntthe directory this resolves to isC:\mnt\mnt\dataand not the desiredC:\mnt\data.benrubson commentedon Mar 26, 2018
Bill, thank you for your detailed answer.
As the POSIX symlinks are created on a POSIX system (for instance Cygwin), they are certainly intended to be used through a POSIX system (once again Cygwin in this case).
Perhaps we could then think about a "passthrough" mode for POSIX links ?
They would fail to resolve on Windows, but would succeed in Cygwin.
Or improve
-o rellinkswith a path parameter ?-o rellinks: would keep the current default behavior-o rellinks=/-o rellinks=/cygdrive/c-o rellinks=/cygdrive/xI think this solution would suit all needs.
Ben
billziss-gh commentedon Mar 26, 2018
Let us consider your proposal of
-o rellinks=/cygdrive/x.Suppose that at some point there is a symbolic link
foo->/cygdrive/x/baron the FUSE file system (/cygdrive/x). An application opensfoo. Here is what happens next:NtCreateFile("\Device\Volume{GUID}\foo"). An internal NT API that the application calls (directly or indirectly).IRP_MJ_CREATE: The WinFsp FSD receives a request to "create" (open) a file object for\foo.FspFileSystemCreate: The WinFsp DLL receives the request in user-mode. It queries the FUSE file system usinggetattr('/foo')and finds out that this is a symlink. It reads the symlink usingreaddir. It converts the received symlink (/cygdrive/x/bar) to a Windows reparse point and returns it to the FSD together with a special status codeSTATUS_REPARSE. (This is currently disallowed without the-o rellinksoption.)STATUS_REPARSEand rewrites the file path from\footo\cygdrive\x\barand then resends the request to user mode. Inevitably this will fail, because\cygdrive\xis not a real directory in the file system.The problem here is that the
/cygdriveprefix does not mean anything outside Cygwin. The FSD does not know how to resolve it.There are ways that some of this could be made to work, but it raises the question. Why is
-o rellinksnot good enough?The
-o rellinksoption "promises" that absolute symlinks found in the file system really point inside the file system. So if you see a/cygdrive/xsymlink in your file system, there is supposed to be a file called/cygdrive/xin that file system.The switch works well for most purposes, except for programs that deeply care that they can retrieve using
readlinkwhat they put there usingsymlink. The only programs I have seen that really care are usually file system test suites. Do you have any other examples?benrubson commentedon Mar 27, 2018
Bill, thank you for your detailed comment once again 👍
Note that I just "discovered" that
-o rellinksis a FUSE option, not a specific WinFsp option. I never used it before. So of course my proposal above to modify this option is pointless... Sorry for this...I have no other example of programs which would care about absolute symlink consistency, but perhaps some programs running in Cygwin only.
I made some further testing, as shown in the picture below :
So here we have a FUSE FS (EncFS) mounted on
X:(/cygdrive/x) which gives a decrypted view of what is crypted onC:(/cygdrive/c).-o rellinksis on.We have a file
ben.txtandrellink.txtpointing to/ben.txt, which has been translated to/cygdrive/c/ben.txt.I'm still surprised it is not translated to
/cygdrive/x/ben.txtinstead, as we work onx, not onc.I'm also surprised that Windows manages to correctly show (and open)
rellink.txt, as/cygdrive/c/ben.txtitself does not exist (but its encrypted filename).Cygwin however fails following / opening this link.
We also have
link.txtpointing to//ben.txt.Sounds like here
-o rellinksdoes not translate this link, but at least allows WinFsp to display it, this is what I was trying to do.And here, Windows also correctly displays (and opens) this link.
So tu sum-up these "findings" :
-o rellinksdoes not point to the correct drive ?-o rellinks(through a new option for example) ? Sounds like this condition would just have to be relaxed ?Thank you again, sounds like this is quite a tricky subject !
billziss-gh commentedon Mar 27, 2018
@benrubson can you please let me know how you create those symlinks? What command did you use? (
ln -s,mklink, etc.)EDIT: If you post a shell script (
ln -s) or batch file (mklink) that demonstrates how these links are created, I will be able to comment better.benrubson commentedon Mar 27, 2018
Sorry, I should have began with this... I'm more a UNIX user than a Windows one, so certainly forgot some basis things...
So links are created with
ln -son Cygwin.FUSE FS (EncFS in this example) sees them as links (
S_ISLNK(stat->st_mode)), and then shows them as links. If their target is absolute, the links will not show-up if-o rellinksis not used.So I think they could, showing their original/raw target.
And sounds like (but I may be wrong as I don't master everything here), that
-o rellinks, when used, does not point to the correct device (for instance it points to/cygdrive/cinstead of/cygdrive/x).billziss-gh commentedon Mar 27, 2018
Ok, I suspect that some of what you are seeing has to do with the mismatch of Cygwin symlinks (which are POSIX compatible) and Windows symlinks (which are not).
Suppose that you create a Cygwin symlink with
ln -s /cygdrive/x/foo bar. Cygwin knows how to interpret this, but Windows and WinFsp do not. They simply assume that/cygdrive/x/foomeans a filefooinside a directoryxinside a directorycygdriveunder the mounted file system root; they do not give any special interpretation to/cygdrive/x.I do not think that EncFS can be used with absolute Cygwin symlinks currently. The
-o rellinksswitch cannot help, because it includes the promise that all absolute symlinks point inside the file system (i.e. the file system acts as the overall system root) and that is not the case with/cygdrive/x.It could be argued that we should change WinFsp-FUSE to allow some limited absolute symlinks and allow paths such as
/cygdrive/xand/proc/cygdrive/xwhen on Cygwin. I believe it is possible to use Cygwin API's to determine the correctcygdriveprefix and strip if it is there. But this is a non-trivial change and IMO rather low priority.benrubson commentedon Mar 28, 2018
Thank you Bill.
I agree this is clearly not a priority.
Goal was also to understand how it works / where the "issue" comes from.
Thanks for all, closing this for now until this is really needed.
Thx 👍
benrubson commentedon Apr 5, 2018
For completeness, I discovered that Cygwin may handle symlinks in different ways thanks to the
winsymlinksvalue of the CYGWIN environment variable.And I also found that the absolute dir pointed by
-o rellinksdepends on the active/current directory.