>From 4de125a449fd90b865bdf69a0632939531a71fd6 Mon Sep 17 00:00:00 2001
From: Assaf Gordon
Date: Wed, 10 Oct 2018 14:13:10 -0600
Subject: [PATCH 2/2] mountlist: add support for windows DOS-style drives
Support basic DOS-style drives on Windows (e.g. C:\, D:\, Q:\).
Using Win32 API that should be backwards compatible back to Windows XP.
Example of 'struct mount_entry' (as printed by 'test-mountlist'):
devname: \Device\HarddiskVolume2
mountdir: C:\
mntdoor: C:\
type: NTFS
dev: -1
dummy: 0
remote: 0
type_alc: 1
devname: \Device\HarddiskVolume4
mountdir: D:\
mntdoor: D:\
type: NTFS
dev: -1
dummy: 0
remote: 0
type_alc: 1
* m4/ls-mntd-fs.m4: Check for and GetLogicalDrives()
function. If found, assume Win32 mount list method.
Adds MOUNTED_GETLOGICALDRIVES to config.h,
and fu_cv_getlogicaldrives={yes,no} to the ./configure script.
* lib/mountlist.c (re_remote): Include this function for both CYGWIN and
Win32.
(read_file_system_list): If using Win32, call GetLogicalDrives(),
GetVolumeInformation() and QueryDosDevice() to populate the mount
entries list.
---
ChangeLog | 33 ++++++++++++++++++++++++
lib/mountlist.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
m4/ls-mntd-fs.m4 | 20 +++++++++++++++
3 files changed, 129 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index aa490686f..3f6e7f207 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,38 @@
2018-10-10 Assaf Gordon
+ mountlist: add support for windows DOS-style drives
+ Support basic DOS-style drives on Windows (e.g. C:\, D:\, Q:\).
+ Using Win32 API that should be backwards compatible back to Windows XP.
+ Example of 'struct mount_entry' (as printed by 'test-mountlist'):
+ devname: \Device\HarddiskVolume2
+ mountdir: C:\
+ mntdoor: C:\
+ type: NTFS
+ dev: -1
+ dummy: 0
+ remote: 0
+ type_alc: 1
+ devname: \Device\HarddiskVolume4
+ mountdir: D:\
+ mntdoor: D:\
+ type: NTFS
+ dev: -1
+ dummy: 0
+ remote: 0
+ type_alc: 1
+ * m4/ls-mntd-fs.m4: Check for and GetLogicalDrives()
+ function. If found, assume Win32 mount list method.
+ Adds MOUNTED_GETLOGICALDRIVES to config.h,
+ and fu_cv_getlogicaldrives={yes,no} to the ./configure script.
+ * lib/mountlist.c (re_remote): Include this function for both CYGWIN and
+ Win32.
+ (read_file_system_list): If using Win32, call GetLogicalDrives(),
+ GetVolumeInformation() and QueryDosDevice() to populate the mount
+ entries list.
+
+
+2018-10-10 Assaf Gordon
+
mountlist tests: add mountlist-tests module
Call read_file_system_list, print the list, and free the entries.
Typical output example:
diff --git a/lib/mountlist.c b/lib/mountlist.c
index b691f3808..12964d1ef 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -135,6 +135,10 @@
# include
#endif
+#ifdef MOUNTED_GETLOGICALDRIVES /* Win32 API */
+# include
+#endif
+
#ifndef HAVE_HASMNTOPT
# define hasmntopt(mnt, opt) ((char *) 0)
#endif
@@ -196,7 +200,7 @@
(ME_DUMMY_0 (Fs_name, Fs_type) || strcmp (Fs_type, "none") == 0)
#endif
-#ifdef __CYGWIN__
+#if defined __CYGWIN__ || defined MOUNTED_GETLOGICALDRIVES
# include
# define ME_REMOTE me_remote
/* All cygwin mount points include ':' or start with '//'; so it
@@ -1105,6 +1109,77 @@ read_file_system_list (bool need_fs_type)
}
#endif /* MOUNTED_INTERIX_STATVFS */
+#ifdef MOUNTED_GETLOGICALDRIVES
+ {
+ int i;
+ char RootPathName[4];
+ char VolumeName[MAX_PATH+1];
+ DWORD VolumeSerialNum;
+ DWORD MaxComponentLen;
+ DWORD FileSystemFlags;
+ char FileSystemName[MAX_PATH+1];
+ char DosDevicePath[MAX_PATH+1];
+ DWORD dw;
+ DWORD ld = GetLogicalDrives();
+
+ if (ld == 0)
+ return NULL;
+
+ for (i=0 ; i<32; ++i)
+ {
+
+ if (!(ld & (1<me_devname = xstrdup (DosDevicePath);
+ me->me_mountdir = xstrdup (RootPathName);
+ me->me_mntroot = xstrdup (RootPathName);
+ me->me_type = xstrdup (FileSystemName);
+ me->me_type_malloced = 1;
+ me->me_dummy = 0;
+ me->me_remote = me_remote (RootPathName, NULL);
+ me->me_dev = -1;
+
+ /* Add to the linked list. */
+ *mtail = me;
+ mtail = &me->me_next;
+ }
+ }
+#endif /* MOUNTED_GETLOGICALDRIVES */
+
*mtail = NULL;
return mount_list;
diff --git a/m4/ls-mntd-fs.m4 b/m4/ls-mntd-fs.m4
index 4a84f0aca..e3a4ae5ce 100644
--- a/m4/ls-mntd-fs.m4
+++ b/m4/ls-mntd-fs.m4
@@ -349,6 +349,26 @@ if test -z "$ac_list_mounted_fs"; then
fi
if test -z "$ac_list_mounted_fs"; then
+ # Win32 API (based on GetLogicalDrives() function)
+ AC_MSG_CHECKING([for Win32API Volume Information])
+ AC_CACHE_VAL([fu_cv_getlogicaldrives],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include
+]],
+ [[ DWORD dw = GetLogicalDrives(); return 0; ]])],
+ [fu_cv_getlogicaldrives=yes],
+ [fu_cv_getlogicaldrives=no])])
+ AC_MSG_RESULT([$fu_cv_getlogicaldrives])
+ if test $fu_cv_getlogicaldrives = yes; then
+ ac_list_mounted_fs=found
+ AC_DEFINE([MOUNTED_GETLOGICALDRIVES], [1],
+ [Define if there is a function named GetLogicalDrives for reading the
+ list of logical drives.
+ (Win32 API)])
+ fi
+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
# Can't build mountlist.c or anything that needs its functions
--
2.11.0