From 87ffa0b3d1342c6832632d392e6ac857f1831dd4 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 12 Apr 2014 20:33:45 +0200 Subject: fs_bsize support --- module/utils.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/module/utils.py b/module/utils.py index 94bf78054..424aeaf37 100644 --- a/module/utils.py +++ b/module/utils.py @@ -117,12 +117,25 @@ def freeSpace(folder): ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes)) return free_bytes.value else: - from os import statvfs - - s = statvfs(folder) + s = os.statvfs(folder) return s.f_bsize * s.f_bavail +def fs_bsize(path): + """ get optimal file system buffer size (in bytes) for I/O calls """ + path = fs_encode(path) + + if os.name == "nt": + import ctypes + + drive = "%s\\" % os.path.splitdrive(path)[0] + cluster_sectors, sector_size = ctypes.c_longlong(0) + ctypes.windll.kernel32.GetDiskFreeSpaceW(ctypes.c_wchar_p(drive), ctypes.pointer(cluster_sectors), ctypes.pointer(sector_size), None, None) + return cluster_sectors * sector_size + else: + return os.statvfs(path).f_bsize + + def uniqify(seq, idfun=None): # order preserving if idfun is None: -- cgit v1.2.3