From: Collin Funk Date: Wed, 19 Mar 2025 02:23:00 +0000 (-0700) Subject: mountlist: Add support for native Windows. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=5f693944c4a5d9ad8334c27752a0a286d3fcb273;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 93ea8a097f..29400e42b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2025-03-18 Collin Funk + 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. diff --git a/lib/mountlist.c b/lib/mountlist.c index 3376b730fc..7eacbf91b7 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -132,6 +132,10 @@ # endif #endif +#if defined _WIN32 && !defined __CYGWIN__ +# include +#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: + . */ + 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: + . */ + 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: + . */ + 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 @@ 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