[glib] gio: Add API for identifying system FS types and device paths
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gio: Add API for identifying system FS types and device paths
- Date: Wed, 25 Oct 2017 23:19:43 +0000 (UTC)
commit 1e4221a3f7b0a7cde11bc824c1faff63499ff862
Author: Philip Withnall <withnall endlessm com>
Date: Wed Oct 25 15:03:17 2017 +0100
gio: Add API for identifying system FS types and device paths
This is needed by gnome-control-center and gnome-settings-daemon; it
makes existing checks from gunixmounts.c public.
Signed-off-by: Philip Withnall <withnall endlessm com>
https://bugzilla.gnome.org/show_bug.cgi?id=788927
docs/reference/gio/gio-sections.txt | 2 +
gio/gunixmounts.c | 71 ++++++++++++++++++++++++++++++----
gio/gunixmounts.h | 4 ++
gio/tests/Makefile.am | 1 +
gio/tests/meson.build | 1 +
gio/tests/unix-mounts.c | 57 ++++++++++++++++++++++++++++
6 files changed, 127 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 484ef62..87168fa 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -1571,6 +1571,8 @@ g_unix_mount_monitor_get
g_unix_mount_monitor_new
g_unix_mount_monitor_set_rate_limit
g_unix_is_mount_path_system_internal
+g_unix_is_system_fs_type
+g_unix_is_system_device_path
<SUBSECTION Standard>
GUnixMountMonitorClass
G_UNIX_MOUNT_MONITOR
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 2c589eb..ef7899d 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -281,10 +281,23 @@ g_unix_is_mount_path_system_internal (const char *mount_path)
return FALSE;
}
-static gboolean
-guess_system_internal (const char *mountpoint,
- const char *fs,
- const char *device)
+/**
+ * g_unix_is_system_fs_type:
+ * @fs_type: a file system type, e.g. `procfs` or `tmpfs`
+ *
+ * Determines if @fs_type is considered a type of file system which is only
+ * used in implementation of the OS. This is primarily used for hiding
+ * mounted volumes that are intended as APIs for programs to read, and system
+ * administrators at a shell; rather than something that should, for example,
+ * appear in a GUI. For example, the Linux `/proc` filesystem.
+ *
+ * The list of file system types considered ‘system’ ones may change over time.
+ *
+ * Returns: %TRUE if @fs_type is considered an implementation detail of the OS.
+ * Since: 2.56
+ */
+gboolean
+g_unix_is_system_fs_type (const char *fs_type)
{
const char *ignore_fs[] = {
"adfs",
@@ -336,6 +349,31 @@ guess_system_internal (const char *mountpoint,
"zfs",
NULL
};
+
+ g_return_val_if_fail (fs_type != NULL && *fs_type != '\0', FALSE);
+
+ return is_in (fs_type, ignore_fs);
+}
+
+/**
+ * g_unix_is_system_device_path:
+ * @fs_type: a device path, e.g. `/dev/loop0` or `nfsd`
+ *
+ * Determines if @device_path is considered a block device path which is only
+ * used in implementation of the OS. This is primarily used for hiding
+ * mounted volumes that are intended as APIs for programs to read, and system
+ * administrators at a shell; rather than something that should, for example,
+ * appear in a GUI. For example, the Linux `/proc` filesystem.
+ *
+ * The list of device paths considered ‘system’ ones may change over time.
+ *
+ * Returns: %TRUE if @device_path is considered an implementation detail of
+ * the OS.
+ * Since: 2.56
+ */
+gboolean
+g_unix_is_system_device_path (const char *device_path)
+{
const char *ignore_devices[] = {
"none",
"sunrpc",
@@ -345,11 +383,21 @@ guess_system_internal (const char *mountpoint,
"/dev/vn",
NULL
};
-
- if (is_in (fs, ignore_fs))
+
+ g_return_val_if_fail (device_path != NULL && *device_path != '\0', FALSE);
+
+ return is_in (device_path, ignore_devices);
+}
+
+static gboolean
+guess_system_internal (const char *mountpoint,
+ const char *fs,
+ const char *device)
+{
+ if (g_unix_is_system_fs_type (fs))
return TRUE;
- if (is_in (device, ignore_devices))
+ if (g_unix_is_system_device_path (device))
return TRUE;
if (g_unix_is_mount_path_system_internal (mountpoint))
@@ -2105,9 +2153,14 @@ g_unix_mount_is_readonly (GUnixMountEntry *mount_entry)
/**
* g_unix_mount_is_system_internal:
* @mount_entry: a #GUnixMount.
+ *
+ * Checks if a Unix mount is a system mount. This is the Boolean OR of
+ * g_unix_is_system_fs_type(), g_unix_is_system_device_path() and
+ * g_unix_is_mount_path_system_internal() on @mount_entry’s properties.
*
- * Checks if a unix mount is a system path.
- *
+ * The definition of what a ‘system’ mount entry is may change over time as new
+ * file system types and device paths are ignored.
+ *
* Returns: %TRUE if the unix mount is for a system path.
*/
gboolean
diff --git a/gio/gunixmounts.h b/gio/gunixmounts.h
index 853b161..b56b00c 100644
--- a/gio/gunixmounts.h
+++ b/gio/gunixmounts.h
@@ -151,6 +151,10 @@ void g_unix_mount_monitor_set_rate_limit (GUnixMountMonitor *mount
GLIB_AVAILABLE_IN_ALL
gboolean g_unix_is_mount_path_system_internal (const char *mount_path);
+GLIB_AVAILABLE_IN_2_56
+gboolean g_unix_is_system_fs_type (const char *fs_type);
+GLIB_AVAILABLE_IN_2_56
+gboolean g_unix_is_system_device_path (const char *device_path);
G_END_DECLS
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 4a04dd9..a553958 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -266,6 +266,7 @@ test_programs += \
socket-address \
stream-rw_all \
unix-fd \
+ unix-mounts \
unix-streams \
g-file-info-filesystem-readonly \
$(NULL)
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index dd522a6..fb17cc4 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -113,6 +113,7 @@ if host_machine.system() != 'windows'
'socket-address',
'stream-rw_all',
'unix-fd',
+ 'unix-mounts',
'unix-streams',
'g-file-info-filesystem-readonly',
'gschema-compile',
diff --git a/gio/tests/unix-mounts.c b/gio/tests/unix-mounts.c
new file mode 100644
index 0000000..3d54047
--- /dev/null
+++ b/gio/tests/unix-mounts.c
@@ -0,0 +1,57 @@
+/* GLib testing framework examples and tests
+ *
+ * Copyright © 2017 Endless Mobile, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+
+#ifndef G_OS_UNIX
+#error This is a Unix-specific test
+#endif
+
+#include <errno.h>
+#include <locale.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+#include <gio/gunixmounts.h>
+
+static void
+test_is_system_fs_type (void)
+{
+ g_assert_true (g_unix_is_system_fs_type ("tmpfs"));
+ g_assert_false (g_unix_is_system_fs_type ("ext4"));
+}
+
+static void
+test_is_system_device_path (void)
+{
+ g_assert_true (g_unix_is_system_device_path ("devpts"));
+ g_assert_false (g_unix_is_system_device_path ("/"));
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ setlocale (LC_ALL, "");
+
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/unix-mounts/is-system-fs-type", test_is_system_fs_type);
+ g_test_add_func ("/unix-mounts/is-system-device-path", test_is_system_device_path);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]