Incorrectly reporting free space
Posted: February 5th, 2009, 10:09 am
There is a bug on Windows which leads to SABnzbd+ incorrectly reporting the amount of free disk space. I have a NAS which has 4TB of space, with about 970GB used and SAB reported -908GB free (yes, a negative amount of free space). This was quite annoying because it kept auto-pausing. After a bit of investigation it appears it is because diskfree() uses GetDiskFreeSpace() to find the free space, which is quite an outdated function and doesn't work very well with very large volumes:
I found the way to fix it is to use GetDiskFreeSpaceEx() instead, which does work:
So to fix it I modified SABnzbd+ like so:
Code: Select all
>>> import win32api
>>> win32api.GetDiskFreeSpace('z:/')
(2, 512, -951626036, -1)
Code: Select all
>>> win32api.GetDiskFreeSpaceEx('z:/')
(3423581450240L, 4464200622080L, 3423581450240L)
Code: Select all
--- sabnzbd\interface.py.orig 2009-02-05 13:39:48.656250000 +0000
+++ sabnzbd\interface.py 2009-02-05 14:46:52.265625000 +0000
@@ -89,14 +89,14 @@
# windows diskfree
def diskfree(_dir):
try:
- secp, byteper, freecl, noclu = win32api.GetDiskFreeSpace(_dir)
- return (secp * byteper * freecl) / GIGI
+ available, disk_size, total_free = win32api.GetDiskFreeSpaceEx(_dir)
+ return available / GIGI
except:
return 0.0
def disktotal(_dir):
try:
- secp, byteper, freecl, noclu = win32api.GetDiskFreeSpace(_dir)
- return (secp * byteper * noclu) / GIGI
+ available, disk_size, total_free = win32api.GetDiskFreeSpaceEx(_dir)
+ return disk_size / GIGI
except:
return 0.0