Skip to content
Snippets Groups Projects
Commit d9d140af authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix disksize/space functions for Win32

Broken 11 months ago with commit ae44ab15: the unit argument was ignored (e.g. converting to kibibytes) and the free/total disk size/space checks were reversed.

Reported by Max (WESTLINE) via usage of JS properties: system.freediskspace and system.freediskspacek.

The JS global functions dir_freespace() and disk_size() were also broken due to this bug.
parent 18737ecc
No related branches found
No related tags found
No related merge requests found
Pipeline #5343 passed
...@@ -901,6 +901,7 @@ static uint64_t getdiskspace(const char* path, uint64_t unit, bool freespace) ...@@ -901,6 +901,7 @@ static uint64_t getdiskspace(const char* path, uint64_t unit, bool freespace)
DWORD NumberOfFreeClusters; DWORD NumberOfFreeClusters;
DWORD BytesPerSector; DWORD BytesPerSector;
DWORD SectorsPerCluster; DWORD SectorsPerCluster;
uint64_t total;
ULARGE_INTEGER avail; ULARGE_INTEGER avail;
ULARGE_INTEGER size; ULARGE_INTEGER size;
static HINSTANCE hK32; static HINSTANCE hK32;
...@@ -919,7 +920,10 @@ static uint64_t getdiskspace(const char* path, uint64_t unit, bool freespace) ...@@ -919,7 +920,10 @@ static uint64_t getdiskspace(const char* path, uint64_t unit, bool freespace)
NULL)) /* receives the free bytes on disk */ NULL)) /* receives the free bytes on disk */
return(0); return(0);
return freespace ? size.QuadPart : avail.QuadPart; total = freespace ? avail.QuadPart : size.QuadPart;
if (unit > 1)
total /= unit;
return total;
} }
/* Windows 95 (old way), limited to 2GB */ /* Windows 95 (old way), limited to 2GB */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment