summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-11-21 11:52:04 +0100
committerraveit65 <[email protected]>2020-11-23 11:02:15 +0100
commit8f7c0deb42d1219d21d9c6324c730b2665a0cc3e (patch)
tree2a353779803f0a32d8085b079f7026efd479d8e7
parent144afb19d06320612768e506197cd8a22d17f563 (diff)
downloadmate-system-monitor-8f7c0deb42d1219d21d9c6324c730b2665a0cc3e.tar.bz2
mate-system-monitor-8f7c0deb42d1219d21d9c6324c730b2665a0cc3e.tar.xz
Show subvol mount option on GNU/Linux
-rw-r--r--src/disks.cpp65
-rw-r--r--src/org.mate.system-monitor.gschema.xml.in22
2 files changed, 78 insertions, 9 deletions
diff --git a/src/disks.cpp b/src/disks.cpp
index a44572c..7dd398a 100644
--- a/src/disks.cpp
+++ b/src/disks.cpp
@@ -1,5 +1,9 @@
#include <config.h>
+#ifdef __linux__
+#include <mntent.h>
+#endif // __linux__
+
#include <giomm.h>
#include <giomm/themedicon.h>
#include <gtk/gtk.h>
@@ -24,6 +28,7 @@ enum DiskColumns
DISK_DEVICE,
DISK_DIR,
DISK_TYPE,
+ DISK_SUBVOLUME,
DISK_TOTAL,
DISK_FREE,
DISK_AVAIL,
@@ -176,6 +181,46 @@ remove_old_disks(GtkTreeModel *model, const glibtop_mountentry *entries, guint n
}
}
+#ifdef __linux__
+static char *
+get_mount_opt(const glibtop_mountentry *entry, const char* opt)
+{
+ char *opt_value = NULL;
+ const struct mntent *mnt;
+ FILE *fp;
+
+ if (!(fp = setmntent(MOUNTED, "r"))) {
+ goto out;
+ }
+
+ while ((mnt = getmntent(fp))) {
+ if ((g_strcmp0(entry->mountdir, mnt->mnt_dir) == 0) &&
+ (g_strcmp0(entry->devname, mnt->mnt_fsname) == 0)) {
+ char *res;
+
+ res = hasmntopt(mnt, "subvol");
+ if ((res = hasmntopt(mnt, "subvol")) != NULL) {
+ char **strs = g_strsplit_set(res, "=", 2);
+
+ if (g_strv_length(strs) == 2) {
+ char *value = strs[1];
+ if (g_strcmp0 (value,"/root") == 0)
+ opt_value = g_strdup("/");
+ else
+ opt_value = g_strdup(strs[1]);
+ g_strfreev(strs);
+ }
+ }
+ break;
+ }
+ }
+
+ endmntent(fp);
+
+ out:
+ return opt_value;
+}
+#endif // __linux__
static void
@@ -187,6 +232,9 @@ add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs)
glibtop_fsusage usage;
guint64 bused, bfree, bavail, btotal;
gint percentage;
+#ifdef __linux__
+ char *subvol = NULL;
+#endif // __linux__
glibtop_get_fsusage(&usage, entry->mountdir);
@@ -197,6 +245,9 @@ add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs)
}
fsusage_stats(&usage, &bused, &bfree, &bavail, &btotal, &percentage);
+#ifdef __linux__
+ subvol = get_mount_opt(entry, "subvol");
+#endif // __linux__
pixbuf = get_icon_for_device(entry->mountdir);
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf->gobj(), 0, NULL);
@@ -212,12 +263,21 @@ add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs)
DISK_DEVICE, entry->devname,
DISK_DIR, entry->mountdir,
DISK_TYPE, entry->type,
+#ifdef __linux__
+
+ DISK_SUBVOLUME, subvol != NULL ? subvol : "",
+#else
+ DISK_SUBVOLUME, "",
+#endif // __linux__
DISK_USED_PERCENTAGE, percentage,
DISK_TOTAL, btotal,
DISK_FREE, bfree,
DISK_AVAIL, bavail,
DISK_USED, bused,
-1);
+#ifdef __linux__
+ g_free (subvol);
+#endif // __linux__
}
@@ -345,6 +405,7 @@ create_disk_view(ProcData *procdata)
N_("Device"),
N_("Directory"),
N_("Type"),
+ N_("SubVolume"),
N_("Total"),
N_("Free"),
N_("Available"),
@@ -368,13 +429,13 @@ create_disk_view(ProcData *procdata)
G_TYPE_STRING, /* DISK_DEVICE */
G_TYPE_STRING, /* DISK_DIR */
G_TYPE_STRING, /* DISK_TYPE */
+ G_TYPE_STRING, /* DISK_SUBVOLUME */
G_TYPE_UINT64, /* DISK_TOTAL */
G_TYPE_UINT64, /* DISK_FREE */
G_TYPE_UINT64, /* DISK_AVAIL */
G_TYPE_UINT64, /* DISK_USED */
CAIRO_GOBJECT_TYPE_SURFACE, /* DISK_ICON */
- G_TYPE_INT /* DISK_USED_PERCENTAGE */
- );
+ G_TYPE_INT); /* DISK_USED_PERCENTAGE */
disk_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
g_signal_connect(G_OBJECT(disk_tree), "row-activated", G_CALLBACK(open_dir), NULL);
diff --git a/src/org.mate.system-monitor.gschema.xml.in b/src/org.mate.system-monitor.gschema.xml.in
index 3e976f4..0bac3e8 100644
--- a/src/org.mate.system-monitor.gschema.xml.in
+++ b/src/org.mate.system-monitor.gschema.xml.in
@@ -477,33 +477,41 @@
</key>
<key name="col-3-width" type="i">
<default>80</default>
- <summary>Width of disk view 'Total' column</summary>
+ <summary>Width of disk view 'SubVol' column</summary>
</key>
<key name="col-3-visible" type="b">
<default>true</default>
- <summary>Show disk view 'Total' column on startup</summary>
+ <summary>Show disk view 'SubVol' column on startup</summary>
</key>
<key name="col-4-width" type="i">
<default>80</default>
- <summary>Width of disk view 'Free' column</summary>
+ <summary>Width of disk view 'Total' column</summary>
</key>
<key name="col-4-visible" type="b">
<default>true</default>
- <summary>Show disk view 'Free' column on startup</summary>
+ <summary>Show disk view 'Total' column on startup</summary>
</key>
<key name="col-5-width" type="i">
<default>80</default>
- <summary>Width of disk view 'Available' column</summary>
+ <summary>Width of disk view 'Free' column</summary>
</key>
<key name="col-5-visible" type="b">
<default>true</default>
- <summary>Show disk view 'Available' column on startup</summary>
+ <summary>Show disk view 'Free' column on startup</summary>
</key>
<key name="col-6-width" type="i">
+ <default>80</default>
+ <summary>Width of disk view 'Available' column</summary>
+ </key>
+ <key name="col-6-visible" type="b">
+ <default>true</default>
+ <summary>Show disk view 'Available' column on startup</summary>
+ </key>
+ <key name="col-7-width" type="i">
<default>300</default>
<summary>Width of disk view 'Used' column</summary>
</key>
- <key name="col-6-visible" type="b">
+ <key name="col-7-visible" type="b">
<default>true</default>
<summary>Show disk view 'Used' column on startup</summary>
</key>