From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 911AE3858D35; Sun, 24 Mar 2024 19:02:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 911AE3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1711306962; bh=TipvEwWky3g55uzfgtm/k5G0zkZFSnvWUitphbkCIok=; h=From:To:Subject:Date:From; b=Ln6ypTJvYTeHbYVH/HmPz7cps1haKgFnSAM5naaN27hGoCU7fvw5gnfx1oGRV2hKF jsSi96MXDG/SKeID6WhqTe+XAWvJ/Q7FNZBxNDCgLfAUy3WmsbMNdTedezR8LxPI5Z Xns4n/hrbS5UWvP2PYaAHrCZfblGtRkFvdUsbcI0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: // and //server: add support for WSL X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 18b8a104acd63dd81298fad82e3484bee0dc0434 X-Git-Newrev: 178a8fca15aab79e9f4d773e8b4834ffa03550a6 Message-Id: <20240324190242.911AE3858D35@sourceware.org> Date: Sun, 24 Mar 2024 19:02:42 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D178a8fca15a= ab79e9f4d773e8b4834ffa03550a6 commit 178a8fca15aab79e9f4d773e8b4834ffa03550a6 Author: Corinna Vinschen AuthorDate: Sun Mar 24 20:02:15 2024 +0100 Commit: Corinna Vinschen CommitDate: Sun Mar 24 20:02:15 2024 +0100 Cygwin: // and //server: add support for WSL =20 Root dirs of WSL installations are exposed via \\wsl$. Add support to expose \\wsl$. =20 While at it, check if TERMSRV and P9 provider exist before exposing them. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler/netdrive.cc | 53 +++++++++++++++++++++++++++++++---= ---- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/winsup/cygwin/fhandler/netdrive.cc b/winsup/cygwin/fhandler/ne= tdrive.cc index 5bcca539741a..799ae9cb8e0b 100644 --- a/winsup/cygwin/fhandler/netdrive.cc +++ b/winsup/cygwin/fhandler/netdrive.cc @@ -42,6 +42,12 @@ details. */ instead of the SMB shares. Un-be-lie-va-ble! FWIW, we reverted the SMB share enumeration using WNet. */ =20 +#ifndef WNNC_NET_9P +#define WNNC_NET_9P 0x00480000 +#endif +#define TERMSRV_DIR "tsclient" +#define PLAN9_DIR "wsl$" + /* Define the required GUIDs here to avoid linking with libuuid.a */ const GUID FOLDERID_NetworkFolder =3D { 0xd20beec4, 0x5ca8, 0x4905, @@ -319,10 +325,15 @@ thread_netdrive_wnet (void *arg) while ((wres =3D WNetEnumResourceW (dom, (cnt =3D 1, &cnt), nro, (size =3D NT_MAX_PATH, &size))) =3D=3D NO_ERROR) { - /* Skip server name and trailing backslash */ - wchar_t *name =3D nro->lpRemoteName + wcslen (srv_name) + 1; size_t cache_idx; =20 + /* Skip server name and trailing backslash */ + wchar_t *name =3D nro->lpRemoteName + 2; + name =3D wcschr (name, L'\\'); + if (!name) + continue; + ++name; + if (ndi->provider =3D=3D WNNC_NET_MS_NFS) { wchar_t *nm =3D name; @@ -367,12 +378,19 @@ create_thread_and_wait (DIR *dir) /* For the Network root, fetch WSD info. */ if (strlen (dir->__d_dirname) =3D=3D 2) { + WCHAR provider[256]; + DWORD size; + ndi.provider =3D WNNC_NET_SMB; ndi.sem =3D CreateSemaphore (&sec_none_nih, 0, 2, NULL); thr =3D new cygthread (thread_netdrive_wsd, &ndi, "netdrive_wsd"); if (thr->detach (ndi.sem)) ndi.err =3D EINTR; CloseHandle (ndi.sem); + /* Add wsl$ if Plan 9 is installed */ + if (WNetGetProviderNameW (WNNC_NET_9P, provider, (size =3D 256, &siz= e)) + =3D=3D NO_ERROR) + DIR_cache.add (__CONCAT(L,PLAN9_DIR)); goto out; } =20 @@ -394,10 +412,12 @@ create_thread_and_wait (DIR *dir) =20 } =20 - - /* Eventually, try SMB via WNet for share enumeration. */ - if (!strcmp (dir->__d_dirname + 2, "tsclient")) + /* Eventually, try TERMSRV/P9/SMB via WNet for share enumeration, + depending on "server" name. */ + if (!strcmp (dir->__d_dirname + 2, TERMSRV_DIR)) ndi.provider =3D WNNC_NET_TERMSRV; + else if (!strcmp (dir->__d_dirname + 2, PLAN9_DIR)) + ndi.provider =3D WNNC_NET_9P; else ndi.provider =3D WNNC_NET_SMB; ndi.sem =3D CreateSemaphore (&sec_none_nih, 0, 2, NULL); @@ -419,15 +439,28 @@ fhandler_netdrive::exists () wchar_t name[MAX_PATH]; struct addrinfoW *ai; INT ret; + DWORD protocol =3D 0; + + /* Handle "tsclient" (Microsoft Terminal Services) and + "wsl$" (Plan 9 Network Provider) explicitely. + Both obviously don't resolve with GetAddrInfoW. */ + if (!strcmp (get_name () + 2, TERMSRV_DIR)) + protocol =3D WNNC_NET_TERMSRV; + else if (!strcmp (get_name () + 2, PLAN9_DIR)) + protocol =3D WNNC_NET_9P; + if (protocol) + { + WCHAR provider[256]; + DWORD size =3D 256; =20 + if (WNetGetProviderNameW (protocol, provider, &size) =3D=3D NO_ERROR) + return virt_directory; + return virt_none; + } /* Hopefully we are allowed to assume an IP network with existing name resolution these days. Therefore, just try to resolve the name into IP addresses. This may take up to about 3 secs if the name - doesn't exist, or about 8 secs if DNS is unavailable. - - Don't ask for "tsclient", it doesn't resolve. Just assume it exists.= */ - if (!strcmp (get_name () + 2, "tsclient")) - return virt_directory; + doesn't exist, or about 8 secs if DNS is unavailable. */ sys_mbstowcs (name, CYG_MAX_PATH, get_name ()); ret =3D GetAddrInfoW (name + 2, NULL, NULL, &ai); if (!ret)