Skip to content

Preserve explicit drive letters in GetFullPathName - #156

Merged
simonlindholm merged 3 commits into
decompals:mainfrom
miried:fix/fullpath-preserve-drive
Oct 27, 2026
Merged

simonlindholm merged 3 commits into
decompals:mainfrom
miried:fix/fullpath-preserve-drive

Conversation

@miried

@miried miried commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

In Wibo 1.2.0, passing an already absolute Windows path changes its drive:

Input: C:\Code\game\main\foo.pdb
Expected: C:\Code\game\main\foo.pdb
Actual: Z:\Code\game\main\foo.pdb

Both ANSI and Unicode variants are affected, and the target file does not need to exist. The same reproduction preserves C: under Wine 11.19.

The cause is the Windows → host → Windows conversion in computeFullPath(): pathFromWindows() strips the drive prefix, and pathToWindows() always adds Z: for absolute host paths. This loses the caller’s original drive.

This affects MSVC6 LINK: /PDB:C:\Code\game\main\foo.pdb embeds a Z: path in the output DLL’s NB10 CodeView record.

Comment thread dll/kernel32/fileapi.cpp Outdated
Comment on lines +128 to +129
std::string hostInput = hasDriveRoot ? input.substr(2) : input;
std::filesystem::path hostPath = files::pathFromWindows(hostInput.c_str());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::filesystem::path hostPath = files::pathFromWindows(input.c_str()); still works here, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for C:/Z: — pathFromWindows only strips those two prefixes. For D:\foo it'd return the relative path D:/foo, which absolute() then joins onto the cwd. Stripping any X:\ first handles every drive letter (covered by the D:/d: cases in test_fullpath.c). hostInput still goes through pathFromWindows, so case-insensitive resolution etc. is unchanged.

Maybe we could make pathFromWindows strip any drive letter instead. That would change how every file API maps other drives (for example, CreateFile("D:\x") would open /x). It's broader than this fix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, I see. This feels like a very subtle workaround for a kinda broken pathFromWindows, and a sketchy one at that: it assumes that you can drop the drive letter and expect behavior to be unchanged. Which I think is true right now, because we map z: and c: to the same thing, but if we changed that it would do case insensitive file system lookups in the wrong place.

Suggestion: preserve only c:.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternative suggestions:

  • change pathFromWindows to handle other drive letters, returning e.g. /mnt/d/...
  • assert that only c: or z: appear

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just change pathFromWindows to resolve all drive letters the same way as c: I guess

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise we could make GetFullPathName not touch the filesystem at all. The docs (https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamea) say

  • "merges the name of the current drive and directory with a specified file name",
  • "does not verify that the resulting path and file name are valid, or that they see an existing file", and
  • "does not convert the specified file name" (that's what GetLongPathName is for).

We currently do convert it. Even for C:, C:\USR\BIN..\LIB comes back as C:\usr\lib because pathFromWindows matches it against /usr. Wine returns C:\USR\LIB.

I would suggest we make computeFullPath purely lexical on the Windows path: resolve against the Windows cwd, collapse ./.., strip trailing dots, and never call pathFromWindows. That avoids the drive-mapping question.

what do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sounds good to me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a new commit as suggested. It has a set of tests that pass on wibo and wine. Let me know what you think.

Comment thread dll/kernel32/fileapi.cpp Outdated

std::string windowsPath = files::pathToWindows(absPath);
if (hasDriveRoot) {
// The host path has no drive; retain the caller's instead of the default Z:.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I was not sure about that one. I removed it.

Resolve against the Windows cwd, collapse . and .., strip trailing dots
and spaces, and never map through pathFromWindows, so arbitrary drive
letters and component case are preserved as Windows does.
@simonlindholm
simonlindholm merged commit d394386 into decompals:main Oct 27, 2026
12 checks passed
@miried

miried commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

@simonlindholm thank you for your review and guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants