Collin Funk wrote: > I pushed both attached patches. Thanks! The unit test is perfect.
On my Windows VM with just 1 drive, the test produces this output: ??? C:\ ??? NTFS local ??? D:\ ??? ??? local The D:\ line needs to be filtered out. Done through the patch below. 2025-03-19 Bruno Haible <br...@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. diff --git a/lib/mountlist.c b/lib/mountlist.c index 7eacbf91b7..1385db43fd 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -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; + } } } }