diff --git a/dll/win32/kernel32/client/file/disk.c b/dll/win32/kernel32/client/file/disk.c index 12751c6b1ad..8a09de7e180 100644 --- a/dll/win32/kernel32/client/file/disk.c +++ b/dll/win32/kernel32/client/file/disk.c @@ -237,12 +237,12 @@ GetDiskFreeSpaceW(IN LPCWSTR lpRootPathName, /* If we're to overflow output, make sure we return the maximum */ if (FileFsSize.TotalAllocationUnits.HighPart != 0) { - FileFsSize.TotalAllocationUnits.LowPart = -1; + FileFsSize.TotalAllocationUnits.LowPart = MAXLONG; } if (FileFsSize.AvailableAllocationUnits.HighPart != 0) { - FileFsSize.AvailableAllocationUnits.LowPart = -1; + FileFsSize.AvailableAllocationUnits.LowPart = MAXLONG; } /* Return what user asked for */ @@ -268,7 +268,7 @@ GetDiskFreeSpaceW(IN LPCWSTR lpRootPathName, DWORD FreeClusters; /* Compute how many clusters there are in less than 2GB: 2 * 1024 * 1024 * 1024- 1 */ - FreeClusters = 0x7FFFFFFF / (FileFsSize.SectorsPerAllocationUnit * FileFsSize.BytesPerSector); + FreeClusters = MAXLONG / (FileFsSize.SectorsPerAllocationUnit * FileFsSize.BytesPerSector); /* If that's higher than what was queried, then return the queried value, it's OK! */ if (FreeClusters > FileFsSize.AvailableAllocationUnits.LowPart) { @@ -291,7 +291,7 @@ GetDiskFreeSpaceW(IN LPCWSTR lpRootPathName, DWORD TotalClusters; /* Compute how many clusters there are in less than 2GB: 2 * 1024 * 1024 * 1024- 1 */ - TotalClusters = 0x7FFFFFFF / (FileFsSize.SectorsPerAllocationUnit * FileFsSize.BytesPerSector); + TotalClusters = MAXLONG / (FileFsSize.SectorsPerAllocationUnit * FileFsSize.BytesPerSector); /* If that's higher than what was queried, then return the queried value, it's OK! */ if (TotalClusters > FileFsSize.TotalAllocationUnits.LowPart) { @@ -348,7 +348,7 @@ GetDiskFreeSpaceExW(IN LPCWSTR lpDirectoryName OPTIONAL, NTSTATUS Status; HANDLE RootHandle; UNICODE_STRING FileName; - DWORD BytesPerAllocationUnit; + DWORDLONG BytesPerAllocationUnit; IO_STATUS_BLOCK IoStatusBlock; OBJECT_ATTRIBUTES ObjectAttributes; FILE_FS_SIZE_INFORMATION FileFsSize; @@ -407,21 +407,25 @@ GetDiskFreeSpaceExW(IN LPCWSTR lpDirectoryName OPTIONAL, NtClose(RootHandle); /* Compute the size of an AU */ - BytesPerAllocationUnit = FileFsFullSize.SectorsPerAllocationUnit * FileFsFullSize.BytesPerSector; + BytesPerAllocationUnit = UInt32x32To64(FileFsFullSize.SectorsPerAllocationUnit, + FileFsFullSize.BytesPerSector); /* And then return what was asked */ if (lpFreeBytesAvailableToCaller != NULL) { - lpFreeBytesAvailableToCaller->QuadPart = FileFsFullSize.CallerAvailableAllocationUnits.QuadPart * BytesPerAllocationUnit; + lpFreeBytesAvailableToCaller->QuadPart = + FileFsFullSize.CallerAvailableAllocationUnits.QuadPart * BytesPerAllocationUnit; } if (lpTotalNumberOfBytes != NULL) { - lpTotalNumberOfBytes->QuadPart = FileFsFullSize.TotalAllocationUnits.QuadPart * BytesPerAllocationUnit; + lpTotalNumberOfBytes->QuadPart = + FileFsFullSize.TotalAllocationUnits.QuadPart * BytesPerAllocationUnit; } /* No need to check for nullness ;-) */ - lpTotalNumberOfFreeBytes->QuadPart = FileFsFullSize.ActualAvailableAllocationUnits.QuadPart * BytesPerAllocationUnit; + lpTotalNumberOfFreeBytes->QuadPart = + FileFsFullSize.ActualAvailableAllocationUnits.QuadPart * BytesPerAllocationUnit; return TRUE; } @@ -439,22 +443,26 @@ GetDiskFreeSpaceExW(IN LPCWSTR lpDirectoryName OPTIONAL, } /* Compute the size of an AU */ - BytesPerAllocationUnit = FileFsSize.SectorsPerAllocationUnit * FileFsSize.BytesPerSector; + BytesPerAllocationUnit = + UInt32x32To64(FileFsSize.SectorsPerAllocationUnit, FileFsSize.BytesPerSector); /* And then return what was asked, available is free, the same! */ if (lpFreeBytesAvailableToCaller != NULL) { - lpFreeBytesAvailableToCaller->QuadPart = FileFsSize.AvailableAllocationUnits.QuadPart * BytesPerAllocationUnit; + lpFreeBytesAvailableToCaller->QuadPart = + FileFsSize.AvailableAllocationUnits.QuadPart * BytesPerAllocationUnit; } if (lpTotalNumberOfBytes != NULL) { - lpTotalNumberOfBytes->QuadPart = FileFsSize.TotalAllocationUnits.QuadPart * BytesPerAllocationUnit; + lpTotalNumberOfBytes->QuadPart = + FileFsSize.TotalAllocationUnits.QuadPart * BytesPerAllocationUnit; } if (lpTotalNumberOfFreeBytes != NULL) { - lpTotalNumberOfFreeBytes->QuadPart = FileFsSize.AvailableAllocationUnits.QuadPart * BytesPerAllocationUnit; + lpTotalNumberOfFreeBytes->QuadPart = + FileFsSize.AvailableAllocationUnits.QuadPart * BytesPerAllocationUnit; } return TRUE;