]> Savannah Git Hosting - gnulib.git/commitdiff
mountlist: Add support for native Windows.
authorCollin Funk <collin.funk1@gmail.com>
Wed, 19 Mar 2025 02:23:00 +0000 (19:23 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Wed, 19 Mar 2025 02:23:00 +0000 (19:23 -0700)
* 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
lib/mountlist.c
m4/mountlist.m4

index 93ea8a097fdfad88ab89336e084676a2e56b2a10..29400e42b6c560ad652eda01374afabb634443cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2025-03-18  Collin Funk  <collin.funk1@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.
+
        Prefer the __gnu_hurd__ macro over __GNU__.
        * lib/get_ppid_of.c: Replace use of __GNU__ with __gnu_hurd__.
        * lib/get_progname_of.c: Likewise.
index 3376b730fc258f6a4c14afc62a07c8127d0ce044..7eacbf91b7bbbda4bf359bd35d4a04b53170ca1a 100644 (file)
 # endif
 #endif
 
+#if defined _WIN32 && !defined __CYGWIN__
+# include <windows.h>
+#endif
+
 #ifndef HAVE_HASMNTOPT
 # define hasmntopt(mnt, opt) ((char *) 0)
 #endif
@@ -1092,6 +1096,61 @@ 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
+  {
+    /* Windows has drive prefixes which are similar to mount points.
+       GetLogicalDrives returns a bitmask where the i-th bit is set
+       if ASCII 'A' + i is an available drive.  See:
+       <https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getlogicaldrives>.  */
+    DWORD value = GetLogicalDrives ();
+    unsigned 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';
+            /* Check if drive is remote.  See:
+               <https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdrivetypea>.  */
+            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;
+            /* Get the name of the file system.  See:
+               <https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa>.  */
+            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;
 
index f86da32b9be24c8a7062847c99d1fc7d515ad5fe..0b8e3f1da2bfd4f1eb044bc65708d3ab7b1fa01f 100644 (file)
@@ -318,6 +318,12 @@ int getmntinfo (struct statfs **, int);
     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