# HG changeset patch # User Matt Harbison # Date 2017-12-30 03:15:37 # Node ID 5cc1becd04934b927c67ebac25098dace9badec1 # Parent d8f408d999f919ee10057aa8640a6a41d2097c2b win32: split a utility function to obtain the volume out of getfstype() This is only done on Windows because it's simple enough to call statfs() on Unix. The goal is to display this in `hg debugfs`. diff --git a/mercurial/win32.py b/mercurial/win32.py --- a/mercurial/win32.py +++ b/mercurial/win32.py @@ -428,8 +428,9 @@ def executablepath(): raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) return buf.value -def getfstype(path): - """Get the filesystem type name from a directory or file (best-effort) +def getvolumename(path): + """Get the mount point of the filesystem from a directory or file + (best-effort) Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. """ @@ -442,7 +443,16 @@ def getfstype(path): if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size): raise ctypes.WinError() # Note: WinError is a function - t = _kernel32.GetDriveTypeA(buf.value) + return buf.value + +def getfstype(path): + """Get the filesystem type name from a directory or file (best-effort) + + Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. + """ + volume = getvolumename(path) + + t = _kernel32.GetDriveTypeA(volume) if t == _DRIVE_REMOTE: return 'cifs' @@ -453,7 +463,7 @@ def getfstype(path): size = 256 name = ctypes.create_string_buffer(size) - if not _kernel32.GetVolumeInformationA(buf.value, None, 0, None, None, None, + if not _kernel32.GetVolumeInformationA(volume, None, 0, None, None, None, ctypes.byref(name), size): raise ctypes.WinError() # Note: WinError is a function