From b0e30ceba2288eab10c6ff7be0ac0cb05a9ed0b7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:51:51 +0200 Subject: Adding upstream version 43.0. Signed-off-by: Daniel Baumann --- plugins/housekeeping/gsd-disk-space-helper.c | 159 +++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 plugins/housekeeping/gsd-disk-space-helper.c (limited to 'plugins/housekeeping/gsd-disk-space-helper.c') diff --git a/plugins/housekeeping/gsd-disk-space-helper.c b/plugins/housekeeping/gsd-disk-space-helper.c new file mode 100644 index 0000000..56e054c --- /dev/null +++ b/plugins/housekeeping/gsd-disk-space-helper.c @@ -0,0 +1,159 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * vim: set et sw=8 ts=8: + * + * Copyright (c) 2008, Novell, Inc. + * Copyright (c) 2012, Red Hat, Inc. + * + * Authors: Vincent Untz + * Bastien Nocera + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + */ + +#include "config.h" + +#include +#include + +#include "gsd-disk-space-helper.h" + +gboolean +gsd_should_ignore_unix_mount (GUnixMountEntry *mount) +{ + const char *fs, *device; + g_autofree char *label = NULL; + guint i; + + /* This is borrowed from GLib and used as a way to determine + * which mounts we should ignore by default. GLib doesn't + * expose this in a way that allows it to be used for this + * purpose + */ + + /* We also ignore network filesystems */ +#if !GLIB_CHECK_VERSION(2, 56, 0) + const gchar *ignore_fs[] = { + "adfs", + "afs", + "auto", + "autofs", + "autofs4", + "cgroup", + "configfs", + "cxfs", + "debugfs", + "devfs", + "devpts", + "devtmpfs", + "ecryptfs", + "fdescfs", + "fusectl", + "gfs", + "gfs2", + "gpfs", + "hugetlbfs", + "kernfs", + "linprocfs", + "linsysfs", + "lustre", + "lustre_lite", + "mfs", + "mqueue", + "ncpfs", + "nfsd", + "nullfs", + "ocfs2", + "overlay", + "proc", + "procfs", + "pstore", + "ptyfs", + "rootfs", + "rpc_pipefs", + "securityfs", + "selinuxfs", + "sysfs", + "tmpfs", + "usbfs", + "zfs", + NULL + }; +#endif /* GLIB < 2.56.0 */ + const gchar *ignore_network_fs[] = { + "cifs", + "nfs", + "nfs4", + "smbfs", + NULL + }; + const gchar *ignore_devices[] = { + "none", + "sunrpc", + "devpts", + "nfsd", + "/dev/loop", + "/dev/vn", + NULL + }; + const gchar *ignore_labels[] = { + "RETRODE", + NULL + }; + + fs = g_unix_mount_get_fs_type (mount); +#if GLIB_CHECK_VERSION(2, 56, 0) + if (g_unix_is_system_fs_type (fs)) + return TRUE; +#else + for (i = 0; ignore_fs[i] != NULL; i++) + if (g_str_equal (ignore_fs[i], fs)) + return TRUE; +#endif + for (i = 0; ignore_network_fs[i] != NULL; i++) + if (g_str_equal (ignore_network_fs[i], fs)) + return TRUE; + + device = g_unix_mount_get_device_path (mount); + for (i = 0; ignore_devices[i] != NULL; i++) + if (g_str_equal (ignore_devices[i], device)) + return TRUE; + + label = g_unix_mount_guess_name (mount); + for (i = 0; ignore_labels[i] != NULL; i++) + if (g_str_equal (ignore_labels[i], label)) + return TRUE; + + return FALSE; +} + +/* Used in gnome-control-center's info panel */ +gboolean +gsd_is_removable_mount (GUnixMountEntry *mount) +{ + const char *mount_path; + char *path; + + mount_path = g_unix_mount_get_mount_path (mount); + if (mount_path == NULL) + return FALSE; + + path = g_strdup_printf ("/run/media/%s", g_get_user_name ()); + if (g_str_has_prefix (mount_path, path)) { + g_free (path); + return TRUE; + } + g_free (path); + return FALSE; +} -- cgit v1.2.3