Windows drive letters are not limited to A-Z

https://news.ycombinator.com/rss Hits: 26
Summary

Windows drive letters are not limited to A-Z 2025-11-30 - Programming - Windows On its own, the title of this post is just a true piece of trivia, verifiable with the built-in subst tool (among other methods). Here's an example creating the drive +:\ as an alias for a directory at C:\foo: subst +: C:\foo The +:\ drive then works as normal (at least in cmd.exe, this will be discussed more later): > cd /D +:\ +:\> tree . Folder PATH listing Volume serial number is 00000001 12AB:23BC +:\ └───bar However, understanding why it's true elucidates a lot about how Windows works under the hood, and turns up a few curious behaviors. What is a drive letter, anyway?🔗 The paths that most people are familiar with are Win32 namespace paths, e.g. something like C:\foo which is a drive-absolute Win32 path. However, the high-level APIs that take Win32 paths like CreateFileW ultimately will convert a path like C:\foo into a NT namespace path before calling into a lower level API within ntdll.dll like NtCreateFile. This can be confirmed with NtTrace, where a call to CreateFileW with C:\foo ultimately leads to a call of NtCreateFile with \??\C:\foo: NtCreateFile( FileHandle=0x40c07ff640 [0xb8], DesiredAccess=SYNCHRONIZE|GENERIC_READ|0x80, ObjectAttributes="\??\C:\foo", IoStatusBlock=0x40c07ff648 [0/1], AllocationSize=null, FileAttributes=0, ShareAccess=7, CreateDisposition=1, CreateOptions=0x4000, EaBuffer=null, EaLength=0 ) => 0 NtClose( Handle=0xb8 ) => 0 Test code, reproduction info createfilew.zig: const std = @import("std"); const windows = std.os.windows; const L = std.unicode.wtf8ToWtf16LeStringLiteral; pub extern "kernel32" fn CreateFileW( lpFileName: windows.LPCWSTR, dwDesiredAccess: windows.DWORD, dwShareMode: windows.DWORD, lpSecurityAttributes: ?*windows.SECURITY_ATTRIBUTES, dwCreationDisposition: windows.DWORD, dwFlagsAndAttributes: windows.DWORD, hTemplateFile: ?windows.HANDLE, ) callconv(.winapi) windows.HANDLE; pub fn main() !void { const path = L("C:\\foo"); const dir_ha...

First seen: 2025-11-30 14:47

Last seen: 2025-12-01 15:50