On Sun, 31 Jul 2022 17:21:32 +0900
Takashi Yano wrote:
> On Sun, 31 Jul 2022 09:11:17 +0300
> Dimax wrote:
> > Hello.
> > I've never had much luck with Cygwin64 and used the 32 bit version before.
> > Today I have no choice and I've installed Cyg64 on my new Win11 PC.
> > 
> > Here is the first major issue I faced. I can not create symbolic links:
> > 
> > Alex@Alexo ~
> > $ ls /cygdrive/C/XOL/
> > 
> > Alex@Alexo ~
> > $ ln -s /cygdrive/C/XOL/ work
> > 
> > Alex@Alexo ~
> > $ ls -all work
> > lrwxrwxrwx 1 Alex None 11 Jul 31 09:09 work -> /mnt/C/XOL/
> > 
> > Alex@Alexo ~
> > $ cd ~/work/
> > -bash: cd: /home/Alex/work/: No such file or directory
> > 
> > The link is created but I can not use it.
> > The only thing that I did not standard was to call installation folder
> > C:\Cygwin instead of default C:\Cygwin64
> > 
> > Any help would be highly appreciated.
> 
> Thanks for the report. This seems to happen only when
> the drive letter is uppercase.
> 
> ln -s /cygdrive/c/XOL/ work
> works.
> 
> Anyway, I think this is a problem of cygwin1.dll.
> 
> This
> work -> /mnt/C/XOL/
> should be
> work -> /cygdrive/C/XOL/
> shouldn't it?
> 
> It guess this is a bug in the code added for WSL
> compatibility.

I found the patch attached solves the issue.

Corinna, WDYT?

-- 
Takashi Yano <takashi.y...@nifty.ne.jp>
From bb20db6a4995f5caeb269a82ab64e5cf474fab68 Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.y...@nifty.ne.jp>
Date: Mon, 1 Aug 2022 09:02:23 +0900
Subject: [PATCH] Cygwin: path: Make some symlinks to /cygdrive/* work.

- Previously, the some symbolic links to /cygdrive/* (/cygdrive/C,
  /cygdrive/./c, /cygdrive//c, etc.) did not work. This patch fixes
  the issue.
  Addresses: https://cygwin.com/pipermail/cygwin/2022-July/251994.html
---
 winsup/cygwin/path.cc | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index eceafbbcf..b530ca86d 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -1916,24 +1916,40 @@ symlink_wsl (const char *oldpath, path_conv 
&win32_newpath)
                          - offsetof (REPARSE_LX_SYMLINK_BUFFER,
                                      LxSymlinkReparseBuffer.PathBuffer);
   PWCHAR utf16 = tp.w_get ();
+  char *normpath = tp.c_get ();
   NTSTATUS status;
   IO_STATUS_BLOCK io;
   OBJECT_ATTRIBUTES attr;
   HANDLE fh;
   int len;
+  char *tail;
 
   rpl->ReparseTag = IO_REPARSE_TAG_LX_SYMLINK;
   rpl->Reserved = 0;
   rpl->LxSymlinkReparseBuffer.FileType = 2;
+  if (normalize_posix_path (oldpath, normpath, tail) != 0)
+    *stpncpy (normpath, oldpath, max_pathlen) = '\0';
   /* Convert cygdrive prefix to "/mnt" for WSL compatibility, but only if
      cygdrive prefix is not "/", otherwise suffer random "/mnt" symlinks... */
   if (mount_table->cygdrive_len > 1
-      && path_prefix_p (mount_table->cygdrive, oldpath,
+      && path_prefix_p (mount_table->cygdrive, normpath,
                        mount_table->cygdrive_len, false))
-    stpcpy (stpcpy (path_buf, "/mnt"),
-           oldpath + mount_table->cygdrive_len - 1);
+    {
+      if (strlen (normpath + mount_table->cygdrive_len - 1) >= 2
+         && (normpath[mount_table->cygdrive_len + 1] == '/'
+             || normpath[mount_table->cygdrive_len + 1] == '\0'))
+       {
+         char drive[] = "/x";
+         drive[1] = tolower (normpath[mount_table->cygdrive_len]);
+         stpcpy (stpcpy (stpcpy (path_buf, "/mnt"), drive),
+                 normpath + mount_table->cygdrive_len + 1);
+       }
+      else
+       stpcpy (stpcpy (path_buf, "/mnt"),
+               normpath + mount_table->cygdrive_len - 1);
+    }
   else
-    *stpncpy (path_buf, oldpath, max_pathlen) = '\0';
+    *stpncpy (path_buf, normpath, max_pathlen) = '\0';
   /* Convert target path to UTF-16 and then back to UTF-8 to make sure the
      WSL symlink is in UTF-8, independent of the current Cygwin codeset. */
   sys_mbstowcs (utf16, NT_MAX_PATH, path_buf);
-- 
2.37.1

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to