Menu ▾ ▴

#109 TFileSystem.DelDirTree: refuse a root by what the directory is, not by how its name is spelled

closed
nobody
2026-11-07
2026-11-07
No

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:

  • what it returns for a share root and a directory below it, on Windows SMB, on Samba and through DFS;
  • for a mount point, a junction to a root, a subst'ed or DefineDosDevice drive, and \\?\GLOBALROOT\Device\HarddiskVolumeN.

The name check would stay as a fallback for a name that cannot be opened.

Related

Bug Reports: #105
Bug Reports: #110

Discussion

  • Thomas Mueller

    Thomas Mueller - 2026-11-07

    Measured with a probe on Windows 10 (19045): it opens the directory with FILE_FLAG_BACKUP_SEMANTICS and asks the handle. Samba ran in a WSL2 Debian instance with a share probe (containing sub, a symlink link-to-sub and a symlink link-to-root to the share root itself, both resolved by Samba) and a DFS root dfs with a link to \\server\probe.

    Path NtQueryInformationFile(FileNameInformation) GetFinalPathNameByHandle (DOS) is a root
    C:\, \\?\C:\, \??\C:\, \\?\GLOBALROOT\Device\HarddiskVolume3\ \ \\?\C:\ yes
    C:\Windows \Windows \\?\C:\Windows no
    a DefineDosDevice drive to a subdirectory, Z:\ the real path below the root the real path no
    a drive linked raw to \Device\Mup, Z:\localhost\C$ \localhost\C$ \\?\UNC\localhost\C$ yes
    \\server\probe, \\server\probe\ \server\probe (with \ if opened with one) \\?\UNC\server\probe yes
    \\server\probe\link-to-root \server\probe\link-to-root \\?\UNC\server\probe yes
    \\server\probe\link-to-sub \server\probe\link-to-sub \\?\UNC\server\probe\sub no
    mapped drive X:\ \server\probe\ \\?\UNC\server\probe yes
    X:\link-to-root \server\probe\link-to-root \\?\UNC\server\probe yes
    DFS \\server\dfs\link \server\dfs\link \\?\UNC\server\probe yes

    Findings:

    • FileNameInformation only 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\Mup and mapped drives, but not a root reached through a link the server resolves or through a DFS link.
    • The file ID of a directory reached through link-to-root equals that of \\server\probe\ (Samba's IDs are the inode numbers), so comparing with the share root named in FileNameInformation catches the server-resolved link, also on Windows XP (GetFileInformationByHandle). For a DFS link it does not: FileNameInformation names the DFS root, whose ID differs.
    • GetFinalPathNameByHandle resolves every case above to the real path, so the existing name check applied to it decides correctly. It needs Windows Vista.
    • GetVolumePathName is no use: for \??\... it returned the root of the current drive, and for a DefineDosDevice drive it failed (87, 123).
    • The device of a share reports FILE_REMOTE_DEVICE.

    Suggested design:

    • Vista and later: open the directory and apply the name check to the path from GetFinalPathNameByHandle (DOS form, the NT form for a volume without a drive letter).
    • Windows XP: 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.
    • The name check stays as the fallback for a name that cannot be opened.

    Not measured yet: Windows XP itself, a share on another Windows computer, and a domain DFS namespace.

     
  • Thomas Mueller

    Thomas Mueller - 2026-11-07

    Decision: only what can be measured here (Windows 10) gets built.

    • Vista and later: open the directory and apply the existing name check to the path from GetFinalPathNameByHandle, loaded dynamically. Measured on Windows 10; the function exists unchanged since Vista.
    • Windows XP: no new code path. Without GetFinalPathNameByHandle the name check alone stays, as now. The FileNameInformation and file ID variant would be code nobody can run here, so it is dropped.
    • The name check alone also stays the fallback for a name that cannot be opened.
     
  • Thomas Mueller

    Thomas Mueller - 2026-11-07

    Fixed in revision [r2543].

     

    Related

    Commit: [r2543]


Log in to post a comment.