On 13/11/2025 12:55, Pádraig Brady wrote:
On 12/11/2025 13:30, Bruno Haible via Gnulib discussion list wrote:
This patch adds a module for determining whether a file (or directory)
is on a local or a remote file system.
2025-11-12 Bruno Haible <[email protected]>
file-remote: New module.
* lib/file-remote.h: New file.
* lib/file-remote.c: New file.
* modules/file-remote: New file.
The Fs_type name comparisons in ME_REMOTE in lib/mountlist.c
look to be a subset of those im file-remote.c
Might the ME_REMOTE name list be augmented with some of these new items?
Perhaps that list of remote file systems names could be maintained
centrally in file-remote.c and then ME_REMOTE could call something like
is_remote_fs_type_name()?
The above idea is implemented in the attached.
cheers,
Padraig
From 02fda4ed1bc047aa8d2c46e2089c4ab16b69d7e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Mon, 23 Feb 2026 14:22:51 +0000
Subject: [PATCH] mountlist: use file-remote module to determine remoteness
* lib/file-remote.c (is_remote_fs_type_name): A new function
that matches file system _names_ as being remote. The list is
an amalgamation of those names already referenced in file-remote,
names referenced in ME_REMOTE, and IDs referenced in file-remote.
* lib/file-remote.h: Declare new function.
* lib/mountlist.c (ME_REMOTE): Use is_remote_fs_type_name()
to determine if the name is remote.
* modules/mountlist: Depend on file-remote.
---
lib/file-remote.c | 37 +++++++++++++++++++++++++++++++++++++
lib/file-remote.h | 6 ++++++
lib/mountlist.c | 23 +++++------------------
modules/mountlist | 1 +
4 files changed, 49 insertions(+), 18 deletions(-)
diff --git a/lib/file-remote.c b/lib/file-remote.c
index 890d67b518..ed59fe2f68 100644
--- a/lib/file-remote.c
+++ b/lib/file-remote.c
@@ -56,6 +56,43 @@
# endif
#endif
+#include <stdbool.h>
+
+bool _GL_ATTRIBUTE_CONST
+is_remote_fs_type_name (const char *fs_type)
+{
+ return (strcmp (fs_type, "acfs") == 0
+ || strcmp (fs_type, "afs") == 0
+ || strcmp (fs_type, "autofs") == 0
+ || strcmp (fs_type, "auristorfs") == 0
+ || strcmp (fs_type, "cachefs") == 0
+ || strcmp (fs_type, "ceph") == 0
+ || strcmp (fs_type, "cifs") == 0
+ || strcmp (fs_type, "coda") == 0
+ || strcmp (fs_type, "fhgfs") == 0
+ || strcmp (fs_type, "gfs") == 0
+ || strcmp (fs_type, "gfs2") == 0
+ || strcmp (fs_type, "gpfs") == 0
+ || strcmp (fs_type, "ibrix") == 0
+ || strcmp (fs_type, "lustre") == 0
+ || strcmp (fs_type, "ncpfs") == 0
+ || strcmp (fs_type, "netfs") == 0
+ || strcmp (fs_type, "nfs") == 0
+ || strcmp (fs_type, "nfs3") == 0
+ || strcmp (fs_type, "nfs4") == 0
+ || strcmp (fs_type, "ocfs2") == 0
+ || strcmp (fs_type, "panfs") == 0
+ || strcmp (fs_type, "smb") == 0
+ || strcmp (fs_type, "smb2") == 0
+ || strcmp (fs_type, "smb3") == 0
+ || strcmp (fs_type, "smbfs") == 0
+ || strcmp (fs_type, "snfs") == 0
+ || strcmp (fs_type, "stnfs") == 0
+ || strcmp (fs_type, "userlandfs") == 0
+ || strcmp (fs_type, "vxfs") == 0
+ || strcmp (fs_type, "websearchfs") == 0);
+}
+
#if defined _WIN32 || defined __CYGWIN__ /* Windows */
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
# include <windows.h>
diff --git a/lib/file-remote.h b/lib/file-remote.h
index 05c0d930f2..cae3c81695 100644
--- a/lib/file-remote.h
+++ b/lib/file-remote.h
@@ -17,6 +17,8 @@
#ifndef _FILE_REMOTE_H
#define _FILE_REMOTE_H
+#include <stdbool.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -30,6 +32,10 @@ extern "C" {
- -1 with errno set, upon error (e.g. if the file is not accessible). */
extern int file_is_remote (const char *file);
+/* Returns true if the filesystem type name FS_TYPE is known to be a
+ remote filesystem type. */
+extern bool is_remote_fs_type_name (const char *fs_type);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/mountlist.c b/lib/mountlist.c
index c19ce3fa99..21f6c05613 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -29,6 +29,7 @@
#include <unistd.h>
#include "c-ctype.h"
+#include "file-remote.h"
#include "xalloc.h"
#if HAVE_SYS_PARAM_H
@@ -230,27 +231,13 @@ me_remote (char const *fs_name, _GL_UNUSED char const *fs_type)
#ifndef ME_REMOTE
/* A file system is "remote" if its Fs_name contains a ':'
- or if (it is of type (smbfs or cifs) and its Fs_name starts with '//')
- or if it is of any other of the listed types
- or Fs_name is equal to "-hosts" (used by autofs to mount remote fs).
+ or Fs_name is equal to "-hosts" (used by autofs to mount remote fs)
+ or if it is of any other of the listed types.
"VM" file systems like prl_fs or vboxsf are not considered remote here. */
# define ME_REMOTE(Fs_name, Fs_type) \
(strchr (Fs_name, ':') != NULL \
- || ((Fs_name)[0] == '/' \
- && (Fs_name)[1] == '/' \
- && (streq (Fs_type, "smbfs") \
- || streq (Fs_type, "smb3") \
- || streq (Fs_type, "cifs"))) \
- || streq (Fs_type, "acfs") \
- || streq (Fs_type, "afs") \
- || streq (Fs_type, "coda") \
- || streq (Fs_type, "auristorfs") \
- || streq (Fs_type, "fhgfs") \
- || streq (Fs_type, "gpfs") \
- || streq (Fs_type, "ibrix") \
- || streq (Fs_type, "ocfs2") \
- || streq (Fs_type, "vxfs") \
- || streq ("-hosts", Fs_name))
+ || streq ("-hosts", Fs_name)) \
+ || is_remote_fs_type_name (Fs_type)
#endif
#if MOUNTED_GETMNTINFO /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 4.4BSD */
diff --git a/modules/mountlist b/modules/mountlist
index 4cf5563608..e495c90baa 100644
--- a/modules/mountlist
+++ b/modules/mountlist
@@ -9,6 +9,7 @@ m4/mountlist.m4
Depends-on:
c-ctype
+file-remote
fopen-gnu
free-posix
getline
--
2.53.0