On 2025-02-18 Lasse Collin wrote:
> Python's stat.S_IFBLK and stat.S_ISBLK(mode) use the values from
> <sys/stat.h>. Thus, MSYS2-Python uses 0x6000 and UCRT64-Python
> uses 0x3000.
Python/fileutils.c hardcodes 0x6000:
https://github.com/python/cpython/blob/51d4bf1e0e5349090da72721c865b6c2b28277f3/Python/fileutils.c#L1194
_S_IFBLK (with leading underscore) isn't defined in Python. The code was
committed in 2023:
https://github.com/python/cpython/commit/0f175766e27642108c65bba04bbd54dcf8799b0e
Since Python's stat.S_IFBLK uses values from <sys/types.h>, things are
out of sync when Python is built with mingw-w64. The following prints
0x6000 and False even though it should print True.
import os
import stat
mode = os.stat("//./PHYSICALDRIVE0").st_mode
print("0x%x" % mode)
print(stat.S_ISBLK(mode))
It might be seen as a bug in Python, but mingw-w64's unusual S_IFBLK
makes the problem possible in the first place.
About lstat: It seems that os.lstat doesn't follow junctions. In case
you find it interesting, I think the code starts at win32_lstat() in
Modules/posixmodule.c. I don't plan to think about this detail further.
--
Lasse Collin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public