Skip to content

Commit b1c21a6

Browse files
committed
Add test program for GetFinalPathNameByHandle()
1 parent 9c1997e commit b1c21a6

7 files changed

Lines changed: 279 additions & 0 deletions

File tree

realpath/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM microsoft/nanoserver
2+
FROM microsoft/windowsservercore
3+
COPY realpath.exe realpath.exe
4+
CMD [ "/realpath.exe" ]

realpath/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# realpath
2+
3+
Example program how to retrieve the real path of a file or directory that
4+
may be bind mounted into a Windows container.
5+
6+
But the function `GetFinalPathNameByHandle()` doesn't seem to retrieve us
7+
at least the absolute path of the file/directory given.
8+
It just returns with error 53 ERROR_BAD_NETPATH: The network path was not found.
9+
10+
```
11+
$ docker run -v C:$(pwd):C:/code -it realpath cmd
12+
13+
Microsoft Windows [Version 10.0.14393]
14+
(c) 2016 Microsoft Corporation. All rights reserved.
15+
16+
C:\>dir
17+
Volume in drive C has no label.
18+
Volume Serial Number is C4ED-1909
19+
20+
Directory of C:\
21+
22+
05/08/2017 07:51 AM <SYMLINKD> code [\\?\ContainerMappedDirectories\F79F703B-1A2E-408F-BA7E-77AB162E2F77]
23+
11/22/2016 03:45 PM 1,894 License.txt
24+
07/16/2016 06:18 AM <DIR> PerfLogs
25+
04/10/2017 02:13 PM <DIR> Program Files
26+
07/16/2016 06:18 AM <DIR> Program Files (x86)
27+
05/08/2017 07:46 AM 119,808 realpath.exe
28+
05/08/2017 07:51 AM <DIR> Users
29+
05/08/2017 07:51 AM <DIR> Windows
30+
2 File(s) 121,702 bytes
31+
6 Dir(s) 21,239,640,064 bytes free
32+
33+
C:\>realpath.exe code
34+
Opening code
35+
Could not get final path (error 53)
36+
37+
C:\>exit
38+
```

realpath/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
docker run -v C:$(pwd):C:/code msbuild msbuild realpath.sln /p:Configuration=Release /p:Platform=x64
3+
docker build -t realpath .

realpath/realpath.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <windows.h>
2+
#include <tchar.h>
3+
#include <stdio.h>
4+
5+
#define BUFSIZE MAX_PATH
6+
7+
void __cdecl _tmain(int argc, TCHAR *argv[])
8+
{
9+
TCHAR Path[BUFSIZE];
10+
HANDLE hFile;
11+
DWORD dwRet;
12+
13+
if( argc != 2 )
14+
{
15+
printf("ERROR:\tIncorrect number of arguments\n\n");
16+
_tprintf(TEXT("%s <file_name>\n"), argv[0]);
17+
return;
18+
}
19+
20+
_tprintf(TEXT("Opening %s\n"), argv[1]);
21+
hFile = CreateFile(argv[1], // file to open
22+
GENERIC_READ, // open for reading
23+
FILE_SHARE_READ, // share for reading
24+
NULL, // default security
25+
OPEN_EXISTING, // existing file only
26+
FILE_FLAG_BACKUP_SEMANTICS, // open also directories
27+
NULL); // no attr. template
28+
29+
if( hFile == INVALID_HANDLE_VALUE)
30+
{
31+
printf("Could not open file (error %d\n)", GetLastError());
32+
return;
33+
}
34+
35+
dwRet = GetFinalPathNameByHandle( hFile, Path, BUFSIZE, VOLUME_NAME_DOS );
36+
if(dwRet < BUFSIZE)
37+
{
38+
if (dwRet)
39+
{
40+
_tprintf(TEXT("\nThe final path is: %s\n"), Path);
41+
}
42+
else
43+
{
44+
printf("Could not get final path (error %d)\n", GetLastError());
45+
}
46+
}
47+
else printf("\nThe required buffer size is %d.\n", dwRet);
48+
49+
CloseHandle(hFile);
50+
}

realpath/realpath.exe

74.5 KB
Binary file not shown.

realpath/realpath.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "realpath", "realpath.vcxproj", "{93CAEB43-19C2-4494-A548-2735BA281997}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Win32 = Debug|Win32
9+
Debug|x64 = Debug|x64
10+
Release|Win32 = Release|Win32
11+
Release|x64 = Release|x64
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{93CAEB43-19C2-4494-A548-2735BA281997}.Debug|Win32.ActiveCfg = Debug|Win32
15+
{93CAEB43-19C2-4494-A548-2735BA281997}.Debug|Win32.Build.0 = Debug|Win32
16+
{93CAEB43-19C2-4494-A548-2735BA281997}.Debug|x64.ActiveCfg = Debug|x64
17+
{93CAEB43-19C2-4494-A548-2735BA281997}.Debug|x64.Build.0 = Debug|x64
18+
{93CAEB43-19C2-4494-A548-2735BA281997}.Release|Win32.ActiveCfg = Release|Win32
19+
{93CAEB43-19C2-4494-A548-2735BA281997}.Release|Win32.Build.0 = Release|Win32
20+
{93CAEB43-19C2-4494-A548-2735BA281997}.Release|x64.ActiveCfg = Release|x64
21+
{93CAEB43-19C2-4494-A548-2735BA281997}.Release|x64.Build.0 = Release|x64
22+
EndGlobalSection
23+
GlobalSection(SolutionProperties) = preSolution
24+
HideSolutionNode = FALSE
25+
EndGlobalSection
26+
EndGlobal

realpath/realpath.vcxproj

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|x64">
9+
<Configuration>Debug</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Release|Win32">
13+
<Configuration>Release</Configuration>
14+
<Platform>Win32</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{93CAEB43-19C2-4494-A548-2735BA281997}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<RootNamespace>realpath</RootNamespace>
25+
</PropertyGroup>
26+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>true</UseDebugLibraries>
30+
<PlatformToolset>v140</PlatformToolset>
31+
<CharacterSet>Unicode</CharacterSet>
32+
</PropertyGroup>
33+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
34+
<ConfigurationType>Application</ConfigurationType>
35+
<UseDebugLibraries>true</UseDebugLibraries>
36+
<PlatformToolset>v140</PlatformToolset>
37+
<CharacterSet>Unicode</CharacterSet>
38+
</PropertyGroup>
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
40+
<ConfigurationType>Application</ConfigurationType>
41+
<UseDebugLibraries>false</UseDebugLibraries>
42+
<PlatformToolset>v140</PlatformToolset>
43+
<WholeProgramOptimization>true</WholeProgramOptimization>
44+
<CharacterSet>Unicode</CharacterSet>
45+
</PropertyGroup>
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
47+
<ConfigurationType>Application</ConfigurationType>
48+
<UseDebugLibraries>false</UseDebugLibraries>
49+
<PlatformToolset>v140</PlatformToolset>
50+
<WholeProgramOptimization>true</WholeProgramOptimization>
51+
<CharacterSet>Unicode</CharacterSet>
52+
</PropertyGroup>
53+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
54+
<ImportGroup Label="ExtensionSettings">
55+
</ImportGroup>
56+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
57+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
58+
</ImportGroup>
59+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<PropertyGroup Label="UserMacros" />
69+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
70+
<LinkIncremental>true</LinkIncremental>
71+
</PropertyGroup>
72+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
73+
<LinkIncremental>true</LinkIncremental>
74+
</PropertyGroup>
75+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
76+
<LinkIncremental>false</LinkIncremental>
77+
</PropertyGroup>
78+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
79+
<LinkIncremental>false</LinkIncremental>
80+
</PropertyGroup>
81+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
82+
<ClCompile>
83+
<PrecompiledHeader>
84+
</PrecompiledHeader>
85+
<WarningLevel>Level3</WarningLevel>
86+
<Optimization>Disabled</Optimization>
87+
<PreprocessorDefinitions>UNICODE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
88+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
89+
</ClCompile>
90+
<Link>
91+
<SubSystem>Console</SubSystem>
92+
<GenerateDebugInformation>true</GenerateDebugInformation>
93+
<AdditionalDependencies>kernel32.lib;user32.lib</AdditionalDependencies>
94+
</Link>
95+
</ItemDefinitionGroup>
96+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
97+
<ClCompile>
98+
<PrecompiledHeader>
99+
</PrecompiledHeader>
100+
<WarningLevel>Level3</WarningLevel>
101+
<Optimization>Disabled</Optimization>
102+
<PreprocessorDefinitions>UNICODE;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
103+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
104+
</ClCompile>
105+
<Link>
106+
<SubSystem>Console</SubSystem>
107+
<GenerateDebugInformation>true</GenerateDebugInformation>
108+
<AdditionalDependencies>kernel32.lib;user32.lib</AdditionalDependencies>
109+
</Link>
110+
</ItemDefinitionGroup>
111+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
112+
<ClCompile>
113+
<WarningLevel>Level3</WarningLevel>
114+
<PrecompiledHeader>
115+
</PrecompiledHeader>
116+
<Optimization>MaxSpeed</Optimization>
117+
<FunctionLevelLinking>true</FunctionLevelLinking>
118+
<IntrinsicFunctions>true</IntrinsicFunctions>
119+
<PreprocessorDefinitions>UNICODE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
121+
</ClCompile>
122+
<Link>
123+
<SubSystem>Console</SubSystem>
124+
<GenerateDebugInformation>true</GenerateDebugInformation>
125+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
126+
<OptimizeReferences>true</OptimizeReferences>
127+
<AdditionalDependencies>kernel32.lib;user32.lib</AdditionalDependencies>
128+
</Link>
129+
</ItemDefinitionGroup>
130+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
131+
<ClCompile>
132+
<WarningLevel>Level3</WarningLevel>
133+
<PrecompiledHeader>
134+
</PrecompiledHeader>
135+
<Optimization>MaxSpeed</Optimization>
136+
<FunctionLevelLinking>true</FunctionLevelLinking>
137+
<IntrinsicFunctions>true</IntrinsicFunctions>
138+
<PreprocessorDefinitions>UNICODE;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
139+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
140+
</ClCompile>
141+
<Link>
142+
<SubSystem>Console</SubSystem>
143+
<GenerateDebugInformation>true</GenerateDebugInformation>
144+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
145+
<OptimizeReferences>true</OptimizeReferences>
146+
<AdditionalDependencies>kernel32.lib;user32.lib</AdditionalDependencies>
147+
</Link>
148+
</ItemDefinitionGroup>
149+
<ItemGroup>
150+
<Text Include="ReadMe.txt" />
151+
</ItemGroup>
152+
<ItemGroup>
153+
<ClCompile Include="realpath.cpp" />
154+
</ItemGroup>
155+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
156+
<ImportGroup Label="ExtensionTargets">
157+
</ImportGroup>
158+
</Project>

0 commit comments

Comments
 (0)