authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-08-05 19:10:10+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-08-06 23:56:37+02:00
loge8abfef2aa8579121fbd13b8df84e8f68b533fa4
treeb3427503852de66426cb319831a7b5815f89c54e
parent2628a8846e429ba7f51927985733f8e33f3b6a65

Add docs


1 files changed, 18 insertions(+), 6 deletions(-)

lib/std/os/windows.zig+18-6
......@@ -898,7 +898,6 @@ pub fn SetFilePointerEx_CURRENT_get(handle: HANDLE) SetFilePointerError!u64 {
898898
899899pub const GetFinalPathNameByHandleError = error{
900900 FileNotFound,
901 SystemResources,
902901 NameTooLong,
903902 Unexpected,
904903};
......@@ -963,9 +962,19 @@ pub fn GetFinalPathNameByHandle(hFile: HANDLE, out_buffer: []u16) GetFinalPathNa
963962 break :blk @as([*]const u16, object_name.Name.Buffer)[0..object_name.Name.Length / 2];
964963 };
965964
966 // Since `NtQueryObject` returns a fully-qualified NT path, we need to translate
967 // the result into a Win32/DOS path (e.g., \Device\HarddiskVolume4\foo would become
968 // C:\foo).
965 // By now, we got a a fully-qualified NT path, which we need to translate
966 // into a Win32/DOS path, for instance:
967 // \Device\HarddiskVolume4\foo => C:\foo
968 //
969 // NOTE:
970 // I couldn't figure out a better way of doing this unfortunately...
971 // This snippet below is in part based around `QueryDosDeviceW` implementation
972 // found in Wine. The trick with `NtQueryDirectoryObject` for some reason
973 // only lists `\DosDevices\Global` as the only SymblinkObject available, which
974 // means it's not possible to query the kernel for all available DOS volume name
975 // symlinks.
976 // TODO investigate!
977 // Wine source: https://source.winehq.com/git/wine.git/blob/HEAD:/dlls/kernelbase/volume.c#l1009
969978 const dos_drive_letters = &[_]u16{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
970979 var query_path = [_]u16{ '\\', 'D', 'o', 's', 'D', 'e', 'v', 'i', 'c', 'e', 's', '\\', 'C', ':' };
971980 for (dos_drive_letters) |drive_letter| {
......@@ -1010,14 +1019,17 @@ pub fn GetFinalPathNameByHandle(hFile: HANDLE, out_buffer: []u16) GetFinalPathNa
10101019 const link_path = @as([*]const u16, link.Buffer)[0..link.Length / 2];
10111020 const idx = std.mem.indexOf(u16, object_path, link_path) orelse continue;
10121021
1013 // TODO check the provided buffer is actually big enough.
1022 // TODO is this the most appropriate error here?
1023 if (out_buffer.len < drive.len + object_path.len) return error.NameTooLong;
1024
10141025 std.mem.copy(u16, out_buffer[0..], drive[0..]);
10151026 std.mem.copy(u16, out_buffer[2..], object_path[link_path.len..]);
10161027
10171028 return out_buffer[0..object_path.len - link_path.len + 2];
10181029 }
10191030
1020 // If we're here, that means there was no match so error out!
1031 // If we're here, that means there was no match so we panic!
1032 // TODO should we actually panic here or return an error instead?
10211033 unreachable;
10221034}
10231035