Since [bugs:#105] DelDirTree refuses names that would empty a drive, volume or share. The check goes by the name: it knows the prefixes \\?\, \\.\ and \??\, the Global\ alias, UNC\, drive letters, volume names, and refuses all of GLOBALROOT. Every review so far found another spelling of a root that got past it (GLOBALROOT\Device\Mup\server\share, then \\?\Global\... and \??\..., closed in the follow-up revisions). The object manager can hold any number of symbolic links, so a check by name can never be complete. For example, a drive letter that DefineDosDevice(DDD_RAW_TARGET_PATH) links to \Device\Mup makes X:\server\share a share root, which no check by name can see. And refusing all of GLOBALROOT is inconsistent with \\?\Volume{guid}\..., the same directory under another name, which is allowed.
A check by what the directory is would cover every alias: open it with FILE_FLAG_BACKUP_SEMANTICS and ask for its path within the volume, NtQueryInformationFile with FileNameInformation, which returns \ for the root of a local volume. That is what GetFileInformationByHandleEx(FileNameInfo) wraps; calling ntdll directly keeps Windows XP, which lacks the kernel32 function.
To measure first, with a probe, on Windows XP and a current Windows:
DefineDosDevice drive, and \\?\GLOBALROOT\Device\HarddiskVolumeN.The name check would stay as a fallback for a name that cannot be opened.
Measured with a probe on Windows 10 (19045): it opens the directory with
FILE_FLAG_BACKUP_SEMANTICSand asks the handle. Samba ran in a WSL2 Debian instance with a shareprobe(containingsub, a symlinklink-to-suband a symlinklink-to-rootto the share root itself, both resolved by Samba) and a DFS rootdfswith a link to\\server\probe.NtQueryInformationFile(FileNameInformation)GetFinalPathNameByHandle(DOS)C:\,\\?\C:\,\??\C:\,\\?\GLOBALROOT\Device\HarddiskVolume3\\\\?\C:\C:\Windows\Windows\\?\C:\WindowsDefineDosDevicedrive to a subdirectory,Z:\\Device\Mup,Z:\localhost\C$\localhost\C$\\?\UNC\localhost\C$\\server\probe,\\server\probe\\server\probe(with\if opened with one)\\?\UNC\server\probe\\server\probe\link-to-root\server\probe\link-to-root\\?\UNC\server\probe\\server\probe\link-to-sub\server\probe\link-to-sub\\?\UNC\server\probe\subX:\\server\probe\\\?\UNC\server\probeX:\link-to-root\server\probe\link-to-root\\?\UNC\server\probe\\server\dfs\link\server\dfs\link\\?\UNC\server\probeFindings:
FileNameInformationonly repeats the path as it was opened (for a share\server\share\..., for a local volume the path below its root). It recognizes local roots in every spelling, a raw link to\Device\Mupand mapped drives, but not a root reached through a link the server resolves or through a DFS link.link-to-rootequals that of\\server\probe\(Samba's IDs are the inode numbers), so comparing with the share root named inFileNameInformationcatches the server-resolved link, also on Windows XP (GetFileInformationByHandle). For a DFS link it does not:FileNameInformationnames the DFS root, whose ID differs.GetFinalPathNameByHandleresolves every case above to the real path, so the existing name check applied to it decides correctly. It needs Windows Vista.GetVolumePathNameis no use: for\??\...it returned the root of the current drive, and for aDefineDosDevicedrive it failed (87, 123).FILE_REMOTE_DEVICE.Suggested design:
GetFinalPathNameByHandle(DOS form, the NT form for a volume without a drive letter).FileNameInformation; local: a root if it is\; remote: also a root if its file ID equals that of the share root it names. A DFS link to a share root is then not recognized on XP, which would be documented.Not measured yet: Windows XP itself, a share on another Windows computer, and a domain DFS namespace.
Decision: only what can be measured here (Windows 10) gets built.
GetFinalPathNameByHandle, loaded dynamically. Measured on Windows 10; the function exists unchanged since Vista.GetFinalPathNameByHandlethe name check alone stays, as now. TheFileNameInformationand file ID variant would be code nobody can run here, so it is dropped.Fixed in revision [r2543].
Related
Commit: [r2543]