gh-111856: Fix os.fstat on windows with FAT32 and exFAT filesystem (G… · python/cpython@dfdbfc5

GitHub

GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources

Original file line numberDiff line numberDiff line change@@ -1236,6 +1236,7 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)

12361236BY_HANDLE_FILE_INFORMATIONinfo;

12371237FILE_BASIC_INFObasicInfo;

12381238FILE_ID_INFOidInfo;

1239+FILE_ID_INFO*pIdInfo=&idInfo;

12391240HANDLEh;

12401241inttype;

12411242@@ -1268,15 +1269,19 @@ _Py_fstat_noraise(int fd, struct _Py_stat_struct *status)

12681269 }

1269127012701271if (!GetFileInformationByHandle(h, &info) ||

1271- !GetFileInformationByHandleEx(h, FileBasicInfo, &basicInfo, sizeof(basicInfo)) ||

1272- !GetFileInformationByHandleEx(h, FileIdInfo, &idInfo, sizeof(idInfo))) {

1272+ !GetFileInformationByHandleEx(h, FileBasicInfo, &basicInfo, sizeof(basicInfo))) {

12731273/* The Win32 error is already set, but we also set errno for

12741274 callers who expect it */

12751275errno=winerror_to_errno(GetLastError());

12761276return-1;

12771277 }

127812781279-_Py_attribute_data_to_stat(&info, 0, &basicInfo, &idInfo, status);

1279+if (!GetFileInformationByHandleEx(h, FileIdInfo, &idInfo, sizeof(idInfo))) {

1280+/* Failed to get FileIdInfo, so do not pass it along */

1281+pIdInfo=NULL;

1282+ }

1283+1284+_Py_attribute_data_to_stat(&info, 0, &basicInfo, pIdInfo, status);

12801285return0;

12811286#else

12821287returnfstat(fd, status);