[PATCH 4 of 7 V2] win32: split a utility function to obtain the volume out of getfstype()

Matt Harbison mharbison72 at gmail.com
Sat Dec 30 23:11:11 EST 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1514603737 18000
#      Fri Dec 29 22:15:37 2017 -0500
# Node ID 48cb8407217a0dce068d8bc8b3b88a9233d36fd3
# Parent  57d4dbf825679ee66dd33f8cef723a5769992026
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 @@
         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 @@
     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 @@
     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
 


More information about the Mercurial-devel mailing list