From 35f87b612183e1dc3b14387e9b48e3a6e6827f37 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 11 May 2023 15:13:23 -0700 Subject: [PATCH] libsysprof-analyze: add superblock-options property This lets you get the full string that was parsed from the mountinfo rather than having to go through our yet-to-be-implemented specific option API. --- src/libsysprof-analyze/sysprof-mount.c | 50 ++++++++++++++++++- src/libsysprof-analyze/sysprof-mount.h | 22 ++++---- .../tests/test-list-processes.c | 7 ++- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-mount.c b/src/libsysprof-analyze/sysprof-mount.c index ec42dab9..362c4344 100644 --- a/src/libsysprof-analyze/sysprof-mount.c +++ b/src/libsysprof-analyze/sysprof-mount.c @@ -42,12 +42,13 @@ enum { PROP_0, PROP_DEVICE_MAJOR, PROP_DEVICE_MINOR, - PROP_ROOT, + PROP_FILESYSTEM_TYPE, PROP_MOUNT_ID, PROP_MOUNT_POINT, PROP_MOUNT_SOURCE, PROP_PARENT_MOUNT_ID, - PROP_FILESYSTEM_TYPE, + PROP_ROOT, + PROP_SUPERBLOCK_OPTIONS, N_PROPS }; @@ -111,6 +112,10 @@ sysprof_mount_get_property (GObject *object, g_value_set_string (value, sysprof_mount_get_filesystem_type (self)); break; + case PROP_SUPERBLOCK_OPTIONS: + g_value_set_string (value, sysprof_mount_get_superblock_options (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -164,6 +169,11 @@ sysprof_mount_class_init (SysprofMountClass *klass) NULL, (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + properties[PROP_SUPERBLOCK_OPTIONS] = + g_param_spec_string ("superblock-options", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_properties (object_class, N_PROPS, properties); } @@ -179,6 +189,7 @@ sysprof_mount_new_for_mountinfo (SysprofStrings *strings, g_autoptr(SysprofMount) self = NULL; g_auto(GStrv) parts = NULL; gsize n_parts; + guint i; g_return_val_if_fail (strings != NULL, NULL); g_return_val_if_fail (mountinfo != NULL, NULL); @@ -196,6 +207,35 @@ sysprof_mount_new_for_mountinfo (SysprofStrings *strings, self->root = sysprof_strings_get (strings, parts[3]); self->mount_point = sysprof_strings_get (strings, parts[4]); + /* Skip forward to end of optional fields */ + for (i = 5; parts[i]; i++) + { + if (strcmp (parts[i], "-") == 0) + break; + } + + if (parts[i] == NULL) + goto finish; + + /* filesystem-type column */ + i++; + if (parts[i] == NULL) + goto finish; + self->filesystem_type = sysprof_strings_get (strings, parts[i]); + + /* mount-source column */ + i++; + if (parts[i] == NULL) + goto finish; + self->mount_source = sysprof_strings_get (strings, parts[i]); + + /* superblock options column */ + i++; + if (parts[i] == NULL) + goto finish; + self->superblock_options = sysprof_strings_get (strings, parts[i]); + +finish: return g_steal_pointer (&self); } @@ -235,6 +275,12 @@ sysprof_mount_get_filesystem_type (SysprofMount *self) return self->filesystem_type; } +const char * +sysprof_mount_get_superblock_options (SysprofMount *self) +{ + return self->superblock_options; +} + const char * sysprof_mount_get_superblock_option (SysprofMount *self, const char *option) diff --git a/src/libsysprof-analyze/sysprof-mount.h b/src/libsysprof-analyze/sysprof-mount.h index c7ee83ff..2cf5e9ef 100644 --- a/src/libsysprof-analyze/sysprof-mount.h +++ b/src/libsysprof-analyze/sysprof-mount.h @@ -32,23 +32,25 @@ SYSPROF_AVAILABLE_IN_ALL G_DECLARE_FINAL_TYPE (SysprofMount, sysprof_mount, SYSPROF, MOUNT, GObject) SYSPROF_AVAILABLE_IN_ALL -int sysprof_mount_get_device_major (SysprofMount *self); +int sysprof_mount_get_device_major (SysprofMount *self); SYSPROF_AVAILABLE_IN_ALL -int sysprof_mount_get_device_minor (SysprofMount *self); +int sysprof_mount_get_device_minor (SysprofMount *self); SYSPROF_AVAILABLE_IN_ALL -int sysprof_mount_get_mount_id (SysprofMount *self); +int sysprof_mount_get_mount_id (SysprofMount *self); SYSPROF_AVAILABLE_IN_ALL -int sysprof_mount_get_parent_mount_id (SysprofMount *self); +int sysprof_mount_get_parent_mount_id (SysprofMount *self); SYSPROF_AVAILABLE_IN_ALL -const char *sysprof_mount_get_root (SysprofMount *self); +const char *sysprof_mount_get_root (SysprofMount *self); SYSPROF_AVAILABLE_IN_ALL -const char *sysprof_mount_get_mount_point (SysprofMount *self); +const char *sysprof_mount_get_mount_point (SysprofMount *self); SYSPROF_AVAILABLE_IN_ALL -const char *sysprof_mount_get_mount_source (SysprofMount *self); +const char *sysprof_mount_get_mount_source (SysprofMount *self); SYSPROF_AVAILABLE_IN_ALL -const char *sysprof_mount_get_filesystem_type (SysprofMount *self); +const char *sysprof_mount_get_filesystem_type (SysprofMount *self); SYSPROF_AVAILABLE_IN_ALL -const char *sysprof_mount_get_superblock_option (SysprofMount *self, - const char *option); +const char *sysprof_mount_get_superblock_options (SysprofMount *self); +SYSPROF_AVAILABLE_IN_ALL +const char *sysprof_mount_get_superblock_option (SysprofMount *self, + const char *option); G_END_DECLS diff --git a/src/libsysprof-analyze/tests/test-list-processes.c b/src/libsysprof-analyze/tests/test-list-processes.c index 2006bf32..de9fd9f4 100644 --- a/src/libsysprof-analyze/tests/test-list-processes.c +++ b/src/libsysprof-analyze/tests/test-list-processes.c @@ -74,13 +74,16 @@ main (int argc, { g_autoptr(SysprofMount) mount = g_list_model_get_item (mounts, j); - g_print (" %d %d %d:%d %s %s\n", + g_print (" %d %d %d:%d %s %s %s %s %s\n", sysprof_mount_get_mount_id (mount), sysprof_mount_get_parent_mount_id (mount), sysprof_mount_get_device_major (mount), sysprof_mount_get_device_minor (mount), sysprof_mount_get_root (mount), - sysprof_mount_get_mount_point (mount)); + sysprof_mount_get_mount_point (mount), + sysprof_mount_get_mount_source (mount), + sysprof_mount_get_filesystem_type (mount), + sysprof_mount_get_superblock_options (mount)); } }