Search code examples
winapintfs

WinAPI and NTFS : reading longer paths


NTFS allows for up to 32k characters in a fully-qualified path. WinAPI only allows for up to 248 characters for the full path minus the filename for compatibility reasons, and 255 total characters. Is there any way to use DeviceIOControl() to bypass this limitation and read any potentially-longer path strings? If that is possible, is there any way then to get a handle to a file whose full path name is longer than 255 characters?


Solution

  • Most wide versions of file/path based functions in kernel32 has supported longer paths since at least Windows 2000 if you use the \\?\ path prefix.

    If you look at CreateFile on MSDN for example it says:

    In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.

    Windows 10, version 1607 (Anniversary Update) and later allows you to access longer paths without a prefix if you add <ws2:longPathAware>true</ws2:longPathAware> to your manifest AND change the machine group policy/set registry key HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled to 1 (REG_DWORD type).

    Parts of the shell, CreateProcess and LoadLibrary does not support > MAX_PATH no matter what you do.