From 551ef36517f0b0cd0c0428f67bf29dfa98fb7e79 Mon Sep 17 00:00:00 2001 From: Rein Klazes Date: Thu, 20 Oct 2005 11:36:40 +0000 Subject: [PATCH] In GetDiskFreeSpace: - only cap the total size and available size to 2GB in Win3.x thru WinME; - in that case adjust number of clusters to be less then 65536 by increasing the cluster size; - add corresponding tests. --- dlls/kernel/tests/drive.c | 17 +++++++++++++++++ dlls/kernel/volume.c | 19 ++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/dlls/kernel/tests/drive.c b/dlls/kernel/tests/drive.c index 3a789780bda..c0f9d22a7e4 100644 --- a/dlls/kernel/tests/drive.c +++ b/dlls/kernel/tests/drive.c @@ -114,10 +114,27 @@ static void test_GetDiskFreeSpaceA(void) "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%ld\n", drive, ret, GetLastError()); else + { ok(ret || (!ret && (GetLastError() == ERROR_NOT_READY || GetLastError() == ERROR_INVALID_DRIVE)), "GetDiskFreeSpaceA(%s): ret=%d GetLastError=%ld\n", drive, ret, GetLastError()); + if( GetVersion() & 0x80000000) + /* win3.0 thru winME */ + ok( total_clusters <= 65535, + "total clusters is %ld > 65535\n", total_clusters); + else { + /* NT, 2k, XP : GetDiskFreeSpace shoud be accurate */ + ULARGE_INTEGER totEx, tot, d; + tot.QuadPart = sectors_per_cluster; + tot.QuadPart = (tot.QuadPart * bytes_per_sector) * total_clusters; + ret = GetDiskFreeSpaceExA( drive, &d, &totEx, NULL); + ok( ret, "GetDiskFreeSpaceExA( %s ) failed. GetLastError=%ld\n", drive, GetLastError()); + ok( bytes_per_sector == 0 || /* empty cd rom drive */ + totEx.QuadPart <= tot.QuadPart, + "GetDiskFreeSpaceA should report at least as much bytes on disk %s as GetDiskFreeSpaceExA\n", drive); + } + } } logical_drives >>= 1; } diff --git a/dlls/kernel/volume.c b/dlls/kernel/volume.c index e4c17bd4c88..e68f00e4543 100644 --- a/dlls/kernel/volume.c +++ b/dlls/kernel/volume.c @@ -1333,11 +1333,20 @@ BOOL WINAPI GetDiskFreeSpaceW( LPCWSTR root, LPDWORD cluster_sectors, units = info.SectorsPerAllocationUnit * info.BytesPerSector; - /* cap the size and available at 2GB as per specs */ - if (info.AvailableAllocationUnits.QuadPart * units > 0x7fffffff) - info.AvailableAllocationUnits.QuadPart = 0x7fffffff / units; - if (info.TotalAllocationUnits.QuadPart * units > 0x7fffffff) - info.TotalAllocationUnits.QuadPart = 0x7fffffff / units; + if( GetVersion() & 0x80000000) { /* win3.x, 9x, ME */ + /* cap the size and available at 2GB as per specs */ + if (info.TotalAllocationUnits.QuadPart * units > 0x7fffffff) { + info.TotalAllocationUnits.QuadPart = 0x7fffffff / units; + if (info.AvailableAllocationUnits.QuadPart * units > 0x7fffffff) + info.AvailableAllocationUnits.QuadPart = 0x7fffffff / units; + } + /* nr. of clusters is always <= 65335 */ + while( info.TotalAllocationUnits.QuadPart > 65535 ) { + info.TotalAllocationUnits.QuadPart /= 2; + info.AvailableAllocationUnits.QuadPart /= 2; + info.SectorsPerAllocationUnit *= 2; + } + } if (cluster_sectors) *cluster_sectors = info.SectorsPerAllocationUnit; if (sector_bytes) *sector_bytes = info.BytesPerSector;