COPY fails to copy from \\wsl$

samintz

Scott Mintz
May 20, 2008
1,434
13
Solon, OH, USA
I cannot copy files from a WSL2 folder. I mapped drive W: to \\wsl$\Ubuntu-20.04. NET USE says it's a Plan 9 Network Provider.

Code:
$ copy * i:\.RaRecovery\
W:\git\Platform\Boot\ICE3\Utility\DebugJumper\ICE3_Eval\PostBuild_baremetal_lp64_el3_release\Firmware\PM.cms => I:\.RaRecovery\PM.cms
TCC: (Sys) The request was aborted.
W:\git\Platform\Boot\ICE3\Utility\DebugJumper\ICE3_Eval\PostBuild_baremetal_lp64_el3_release\Firmware\DebugJumper.cms => I:\.RaRecovery\DebugJumper.cms
TCC: (Sys) The request was aborted.
     0 files copied       2 failed

The copy succeeds from Explorer.
TCC 26.02.41 x64 Windows 10 [Version 10.0.19041.450]
TCC Build 41 Windows 10 Build 19041[/code]
 

samintz

Scott Mintz
May 20, 2008
1,434
13
Solon, OH, USA
You can copy data from Windows into your WSL environment because your drives show up in /mnt/. For example, drive C: is /mnt/c.

Copying in the other direction can be done by copying from \\wsl$. From your bash prompt, you can type "explorer.exe ." and it will launch Explorer with the path to your current folder.
 

samintz

Scott Mintz
May 20, 2008
1,434
13
Solon, OH, USA
WSL1 uses files that are directly accessible from Windows - e.g. C:\Users\mintz\AppData\Local\lxss. But WSL2 files are inside of a VHDX file.
C:\Users\mintz\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx
 

samintz

Scott Mintz
May 20, 2008
1,434
13
Solon, OH, USA
You can tell which WSL you're running by running: wsl -l -v
Code:
$ wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         2
  docker-desktop-data    Running         2
  Legacy                 Stopped         1
  Ubuntu                 Stopped         1
  docker-desktop         Running         2
 
May 20, 2008
10,780
83
Syracuse, NY, USA
I can do this (snipped) with TCC:

Code:
\\wsl$\ubuntu> dir

 Directory of  \\wsl$\ubuntu\*

2020-10-16  21:27         <DIR>    .
2020-10-16  21:27         <DIR>    ..
2019-07-04  00:51         <DIR>    bin
2019-05-21  10:42         <DIR>    boot
2020-10-16  21:27         <DIR>    dev

But I don't **SEE** WSL$\Ubuntu anywhere. l should I? And If I issue explorer.exe in bash (from any directory) explorer opens in my documents folder.
 
May 20, 2008
10,780
83
Syracuse, NY, USA
Here, this is cmd;

Code:
v:\> copy \\wsl$\ubuntu\home\vefatica\.bashrc
        1 file(s) copied.

And these are TCC.

Code:
\\wsl$\ubuntu\home\vefatica> copy .bashrc v:\
\\wsl$\ubuntu\home\vefatica\.bashrc => V:\.bashrc
TCC: (Sys) The request was aborted.
     0 files copied       1 failed

\\wsl$\ubuntu\home\vefatica> v:

v:\> copy \\wsl$\ubuntu\home\vefatica\.bashrc v:\
\\wsl$\ubuntu\home\vefatica\.bashrc => V:\.bashrc
TCC: (Sys) The request was aborted.
     0 files copied       1 failed
 
  • Like
Reactions: samintz

samintz

Scott Mintz
May 20, 2008
1,434
13
Solon, OH, USA
1602901191591.png

1602901144982.png
 
May 20, 2008
10,780
83
Syracuse, NY, USA
Mine's a tad different but it is WSL2.

Windows 10 Linux Subsystem
vefatica@jj
BUILD: 18363
BRANCH: 19h1_release
RELEASE: Ubuntu 18.04.2 LTS
KERNEL: Linux 4.19.128-microsoft-standard
UPTIME: 0d 0h 3m

I can get here:

1602901672051.png


via a back door ... go there with TCC and do "explorer ." or (plugin) "shellex ." and also by typing the location in explorer's location bar. But I can't find a way to get there from "This PC" by pushing buttons.

I don't have WSL$ or Ubuntu in explorer's Network folder. Do you?
 
May 20, 2008
10,780
83
Syracuse, NY, USA
After those commands, I see this. But there's nothing **IN** Network. I never see anything in Network, even when my old computer is on (and networked).

1602955982454.png
 
May 20, 2008
10,780
83
Syracuse, NY, USA
File copies in TCC are done with the Windows API (CopyFileEx), so that's apparently either broken or deliberately doesn't support wsl copies. Only Microsoft knows for sure, and they didn't document it.
It works in this very simple form.

Code:
    BOOL bCancel;
    if ( CopyFileEx(L"\\\\wsl$\\ubuntu\\home\\vefatica\\.bashrc", L"v:\\.bashrc", NULL, 0, &bCancel, 0) == 0 )
        wprintf(L"LE = %lu\n", GetLastError());

That's in a project called "Sleep" and

Code:
d:\projects2019\sleep\x64\release> dir /k /m v:\.bashrc
TCC: (Sys) The system cannot find the file specified.
 "V:\.bashrc"

d:\projects2019\sleep\x64\release> Sleep.exe

d:\projects2019\sleep\x64\release> dir /k /m v:\.bashrc
2020-10-17  14:53           3,789  .bashrc
 
May 20, 2008
10,780
83
Syracuse, NY, USA
I'm getting really bizarre results. In a nutshell ...

1. This works.

Code:
BOOL bCancel;
CopyFileEx(L"\\\\wsl$\\ubuntu\\home\\vefatica\\.bashrc", L"v:\\.bashrc", NULL, NULL, &bCancel, 0);

2. This fails.

Code:
    WCHAR    szSrc[MAX_PATH]  = L"\\\\wsl$\\ubuntu\\home\\vefatica\\.bashrc",
            szDest[MAX_PATH] = L"v:\\.bashrc";
    BOOL bCancel;
    CopyFileEx(szSrc, szDest, NULL, NULL, &bCancel, 0)'

3. And (most bizarre) if both of the above appear in the source, both fail!

In all failing cases, GetLastError() is 1235 ("The request was aborted.").

Here's some source in case anyone wan't to play with it.

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

INT wmain(INT argc, WCHAR **argv)
{
    WCHAR    szSrc[MAX_PATH]  = L"\\\\wsl$\\ubuntu\\home\\vefatica\\.bashrc",
            szDest[MAX_PATH] = L"v:\\.bashrc";
    BOOL bCancel;

    if ( CopyFileEx(L"\\\\wsl$\\ubuntu\\home\\vefatica\\.bashrc", L"v:\\.bashrc", NULL, NULL, &bCancel, 0) == 0 )
        wprintf(L"1 - LE = %lu\n", GetLastError());

    //if ( CopyFileEx(szSrc, szDest, NULL, NULL, &bCancel, 0) == 0 )
    //    wprintf(L"2 - LE = %lu\n", GetLastError());

    return 0;
}
 
May 20, 2008
10,780
83
Syracuse, NY, USA
Hmmm! My fault, I guess. If I set bCancel = FALSE before each call to CopyFileEx, everything works (makes sense, eh?).

This little test works fine with wsl$ paths.

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

INT wmain(INT argc, WCHAR **argv)
{
    if ( argc < 3 )
        return 1;
    BOOL bCancel;
    if ( !CopyFileEx(argv[1], argv[2], NULL, NULL, &(bCancel = FALSE), 0) )
        wprintf(L"LE = %lu\n", GetLastError());
    return 0;
}
 
Aug 23, 2010
595
8
Microsoft treating network names ending with $ as "system" names and won't show them in explorer.
F.e. you could create a network share named "mystuff$" and it will never appear in explorer, but will be visible in more honest programs (Far manager's Network browser plugin will show them as "hidden shares", for example).
"\\wsl$\" is another example of the same principle. This is a fake/special name for a local network service provided by the WSL2 host process, which exports all running VMs' root filesystems as network shares.