diff options
author | Andrea Azzarone <azzaronea@gmail.com> | 2018-03-26 14:11:12 +0200 |
---|---|---|
committer | Robert Roth <robert.roth.off@gmail.com> | 2023-01-10 05:44:39 +0000 |
commit | 9d385bdd1a1a5cef1a625316119880abad339d7f (patch) | |
tree | a52b5b94d1574fdb68ce5552fbfaa9d79b2360b3 | |
parent | 5e97014fea8153f42e21062f2f2f32bfcf6a29e9 (diff) | |
download | libgtop-9d385bdd1a1a5cef1a625316119880abad339d7f.tar.gz |
Ignore file systems if mounted with x-gdu.hide userspace mount option.
Scan /run/mount/utab file if present and hide all file systems mounted with x-gdu.hide
userspace mount options.
https://gitlab.gnome.org/GNOME/libgtop/issues/38
-rw-r--r-- | sysdeps/linux/mountlist.c | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/sysdeps/linux/mountlist.c b/sysdeps/linux/mountlist.c index 7c376fdc..c5a3c273 100644 --- a/sysdeps/linux/mountlist.c +++ b/sysdeps/linux/mountlist.c @@ -40,7 +40,8 @@ End: typedef struct { - GHashTable *table; + GHashTable *table_fstype; + GHashTable *table_mntdir; } IgnoreList; @@ -49,7 +50,8 @@ ignore_list_new(void) { IgnoreList* ig; ig = g_new(IgnoreList, 1); - ig->table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + ig->table_fstype = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + ig->table_mntdir = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); return ig; } @@ -58,24 +60,38 @@ static void ignore_list_delete(IgnoreList* ig) { if (ig) { - g_hash_table_destroy(ig->table); + g_hash_table_destroy(ig->table_fstype); + g_hash_table_destroy(ig->table_mntdir); g_free(ig); } } static void -ignore_list_add(IgnoreList* ig, const char* fs) +ignore_list_add_fstype(IgnoreList* ig, const char* fstype) { - g_hash_table_insert(ig->table, g_strdup(fs), GINT_TO_POINTER(1)); + g_hash_table_insert(ig->table_fstype, g_strdup(fstype), GINT_TO_POINTER(1)); } +static void +ignore_list_add_mntdir(IgnoreList* ig, const char* mntdir) +{ + g_hash_table_insert(ig->table_mntdir, g_strdup(mntdir), GINT_TO_POINTER(1)); +} + +static gboolean +ignore_list_has_fstype(IgnoreList* ig, const char* fstype) +{ + gpointer data; + data = g_hash_table_lookup(ig->table_fstype, fstype); + return data != NULL; +} static gboolean -ignore_list_has(IgnoreList* ig, const char* fs) +ignore_list_has_mntdir(IgnoreList* ig, const char* mntdir) { gpointer data; - data = g_hash_table_lookup(ig->table, fs); + data = g_hash_table_lookup(ig->table_mntdir, mntdir); return data != NULL; } @@ -84,7 +100,7 @@ ignore_list_has(IgnoreList* ig, const char* fs) static gboolean -ignore_fs(const char *fstype, IgnoreList** ig) +ignore_fs(const char *mntdir, const char *fstype, IgnoreList** ig) { if (!*ig) { FILE* fs; @@ -92,24 +108,43 @@ ignore_fs(const char *fstype, IgnoreList** ig) *ig = ignore_list_new(); - ignore_list_add(*ig, "none"); + ignore_list_add_fstype(*ig, "none"); if ((fs = fopen("/proc/filesystems", "r")) != NULL) { while (fgets(line, sizeof line, fs)) { if (!strncmp(line, "nodev", 5)) { char *type; type = g_strstrip(line + 5); - ignore_list_add(*ig, type); + ignore_list_add_fstype(*ig, type); } } fclose(fs); } + + if ((fs = fopen("/run/mount/utab", "r")) != NULL) { + size_t len = 0; + char *uline = NULL; + + while (getline(&uline, &len, fs) != -1) { + if (strstr(uline, "x-gdu.hide")) { + char * pch = strtok (uline, " "); + while (pch != NULL) { + if (!strncmp(pch, "TARGET=", 7)) { + ignore_list_add_mntdir(*ig, pch+7); + } + pch = strtok (NULL, " "); + } + } + } + + free(uline); + fclose(fs); + } } - return ignore_list_has(*ig, fstype); + return ignore_list_has_fstype(*ig, fstype) || ignore_list_has_mntdir(*ig, mntdir); } - glibtop_mountentry * glibtop_get_mountlist_s(glibtop *server, glibtop_mountlist *buf, int all_fs) { @@ -136,7 +171,7 @@ glibtop_get_mountlist_s(glibtop *server, glibtop_mountlist *buf, int all_fs) const char *devopt; gsize len; - if (!all_fs && ignore_fs(mnt->mnt_type, &ig)) + if (!all_fs && ignore_fs(mnt->mnt_dir, mnt->mnt_type, &ig)) continue; len = entries->len; |