]> Savannah Git Hosting - gnulib.git/commitdiff
mountlist: Improve implementation on native Windows.
authorBruno Haible <bruno@clisp.org>
Wed, 19 Mar 2025 08:10:35 +0000 (09:10 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 19 Mar 2025 08:12:02 +0000 (09:12 +0100)
* lib/mountlist.c (read_file_system_list) [_WIN32 && !__CYGWIN__]:
Filter out those volumes for which GetVolumeInformation fails.

ChangeLog
lib/mountlist.c

index eb51b0f33a48cb9e1a33b9b626129f618cbbf510..eb80449b85698645dd9525c30ca1dfdbb480f596 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-03-19  Bruno Haible  <bruno@clisp.org>
+
+       mountlist: Improve implementation on native Windows.
+       * lib/mountlist.c (read_file_system_list) [_WIN32 && !__CYGWIN__]:
+       Filter out those volumes for which GetVolumeInformation fails.
+
 2025-03-18  Collin Funk  <collin.funk1@gmail.com>
 
        futimens: Work around a GNU/Hurd bug.
index 7eacbf91b7bbbda4bf359bd35d4a04b53170ca1a..1385db43fddc0a4530c7e19e6f30baf859692ff3 100644 (file)
@@ -1114,37 +1114,34 @@ read_file_system_list (bool need_fs_type)
       {
         if (value & (1U << i))
           {
+            char mountdir[4];
             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:
+            mountdir[0] = 'A' + i;
+            mountdir[1] = ':';
+            mountdir[2] = '\\';
+            mountdir[3] = '\0';
+            /* Test whether the drive actually exists, and
+               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))
+            if (GetVolumeInformation (mountdir, NULL, 0, NULL, NULL, NULL,
+                                      fs_name, sizeof fs_name))
               {
+                me = xmalloc (sizeof *me);
+                me->me_mountdir = xstrdup (mountdir);
+                /* Check if drive is remote.  See:
+                   <https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdrivetypea>.  */
+                me->me_remote = GetDriveType (mountdir) == DRIVE_REMOTE;
+                me->me_devname = NULL;
+                me->me_mntroot = NULL;
+                me->me_dev = (dev_t) -1;
+                me->me_dummy = 0;
                 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;
+                /* Add to the linked list. */
+                *mtail = me;
+                mtail = &me->me_next;
+              }
           }
       }
   }