summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-11-13 16:25:01 (GMT)
committerGitHub <noreply@github.com>2023-11-13 16:25:01 (GMT)
commitdfdbfc548f45dc254844b71f77f03136c413b76b (patch)
treeabbc5a67bb397decec20ffcb701e48d9f00b2c6d /Python
parentc6aea46a71d158f993cc723c14b4bf7982b73a2a (diff)
downloadcpython-dfdbfc548f45dc254844b71f77f03136c413b76b.zip
cpython-dfdbfc548f45dc254844b71f77f03136c413b76b.tar.gz
cpython-dfdbfc548f45dc254844b71f77f03136c413b76b.tar.bz2
gh-111856: Fix os.fstat on windows with FAT32 and exFAT filesystem (GH-112038)
(cherry picked from commit 29af7369dbbbba8cefafb196e977bce8189a527d) Co-authored-by: AN Long <aisk@users.noreply.github.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/fileutils.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 610e729..c752175 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -1236,6 +1236,7 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
BY_HANDLE_FILE_INFORMATION info;
FILE_BASIC_INFO basicInfo;
FILE_ID_INFO idInfo;
+ FILE_ID_INFO *pIdInfo = &idInfo;
HANDLE h;
int type;
@@ -1268,15 +1269,19 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)
}
if (!GetFileInformationByHandle(h, &info) ||
- !GetFileInformationByHandleEx(h, FileBasicInfo, &basicInfo, sizeof(basicInfo)) ||
- !GetFileInformationByHandleEx(h, FileIdInfo, &idInfo, sizeof(idInfo))) {
+ !GetFileInformationByHandleEx(h, FileBasicInfo, &basicInfo, sizeof(basicInfo))) {
/* The Win32 error is already set, but we also set errno for
callers who expect it */
errno = winerror_to_errno(GetLastError());
return -1;
}
- _Py_attribute_data_to_stat(&info, 0, &basicInfo, &idInfo, status);
+ if (!GetFileInformationByHandleEx(h, FileIdInfo, &idInfo, sizeof(idInfo))) {
+ /* Failed to get FileIdInfo, so do not pass it along */
+ pIdInfo = NULL;
+ }
+
+ _Py_attribute_data_to_stat(&info, 0, &basicInfo, pIdInfo, status);
return 0;
#else
return fstat(fd, status);