Bruno Haible <br...@clisp.org> writes:

> The questions is: which ones are useful in this context?

I've attached a basic patch, but I have not pushed it since I am unsure
how useful it actually is or if I am missing important information.

>From a test run (on Wine, which isn't perfect):

    $ find ~/.wine/dosdevices/ -name '*:'
    /home/collin/.wine/dosdevices/c:
    /home/collin/.wine/dosdevices/z:
    $ ./gltests/test-mountlist.exe 
    C:\ NTFS
    Z:\ NTFS

I was under the impression that all mount points on windows had drive
letters. It appears that "Mounted Folders" exist, but it reads to me
like they are just aliases for mounts with drive prefixes [1].

Collin

[1] https://learn.microsoft.com/en-us/windows/win32/fileio/volume-mount-points

>From 95bc393f6dc6586906b094ecb267b75b106c2925 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Mon, 17 Mar 2025 19:32:59 -0700
Subject: [PATCH] mountlist: Add support for native Windows.

* lib/mountlist.c (read_file_system_list) [_WIN32 && !__CYGWIN__]:
Enumerate all drive prefixes.
* m4/mountlist.m4 (gl_MOUNTLIST): Don't abort on native Windows.
---
 ChangeLog       |  7 +++++++
 lib/mountlist.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 m4/mountlist.m4 |  6 ++++++
 3 files changed, 64 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index b653fc2914..e19d848dec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-03-17  Collin Funk  <collin.fu...@gmail.com>
+
+	mountlist: Add support for native Windows.
+	* lib/mountlist.c (read_file_system_list) [_WIN32 && !__CYGWIN__]:
+	Enumerate all drive prefixes.
+	* m4/mountlist.m4 (gl_MOUNTLIST): Don't abort on native Windows.
+
 2025-03-13  Collin Funk  <collin.fu...@gmail.com>
 
 	vma-iter: Detect executable memory segments on Haiku (regr. 2011-01-25).
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 3376b730fc..2170debb4b 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -132,6 +132,10 @@
 # endif
 #endif
 
+#if defined _WIN32 && !defined __CYGWIN__
+# include <windows.h>
+#endif
+
 #ifndef HAVE_HASMNTOPT
 # define hasmntopt(mnt, opt) ((char *) 0)
 #endif
@@ -1092,6 +1096,53 @@ read_file_system_list (bool need_fs_type)
   }
 #endif /* MOUNTED_INTERIX_STATVFS */
 
+#if defined _WIN32 && !defined __CYGWIN__
+/* Don't assume that UNICODE is not defined.  */
+# undef GetDriveType
+# define GetDriveType GetDriveTypeA
+# undef GetVolumeInformation
+# define GetVolumeInformation GetVolumeInformationA
+  {
+    DWORD value = GetLogicalDrives ();
+    int i;
+
+    for (i = 0; i < 26; ++i)
+      {
+        if (value & (1U << i))
+          {
+            char fs_name[MAX_PATH + 1];
+            me = xmalloc (sizeof *me);
+            me->me_mountdir = xmalloc (4);
+            me->me_mountdir[0] = 'A' + i;
+            me->me_mountdir[1] = ':';
+            me->me_mountdir[2] = '\\';
+            me->me_mountdir[3] = '\0';
+            me->me_remote = GetDriveType (me->me_mountdir) == DRIVE_REMOTE;
+            me->me_devname = NULL;
+            me->me_mntroot = NULL;
+            me->me_dev = (dev_t) -1;
+            me->me_dummy = 0;
+            if (GetVolumeInformation (me->me_mountdir, NULL, 0, NULL, NULL,
+                                      NULL, fs_name, sizeof fs_name))
+              {
+                me->me_type = xstrdup (fs_name);
+                me->me_type_malloced = 1;
+              }
+            else
+              {
+                me->me_type = NULL;
+                me->me_type_malloced = 0;
+              }
+
+            /* Add to the linked list. */
+            *mtail = me;
+            mtail = &me->me_next;
+          }
+      }
+  }
+
+#endif
+
   *mtail = NULL;
   return mount_list;
 
diff --git a/m4/mountlist.m4 b/m4/mountlist.m4
index f86da32b9b..0b8e3f1da2 100644
--- a/m4/mountlist.m4
+++ b/m4/mountlist.m4
@@ -318,6 +318,12 @@ AC_DEFUN([gl_MOUNTLIST]
     esac
   fi
 
+  if test -z "$ac_list_mounted_fs"; then
+    case "$host_os" in
+      mingw* | windows*) ac_list_mounted_fs=found ;;
+    esac
+  fi
+
   if test -z "$ac_list_mounted_fs"; then
     AC_MSG_ERROR([could not determine how to read list of mounted file systems])
     # FIXME -- no need to abort building the whole package
-- 
2.48.1

Reply via email to