From fd6256e68ff5db4628f3d169942a00ff2e9bd12a Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 9 May 2023 20:46:10 -0700 Subject: [PATCH] libsysprof-analyze: start on object to represent a mount --- src/libsysprof-analyze/meson.build | 1 + .../sysprof-mount-private.h | 41 ++++ src/libsysprof-analyze/sysprof-mount.c | 198 ++++++++++++++++++ 3 files changed, 240 insertions(+) create mode 100644 src/libsysprof-analyze/sysprof-mount-private.h create mode 100644 src/libsysprof-analyze/sysprof-mount.c diff --git a/src/libsysprof-analyze/meson.build b/src/libsysprof-analyze/meson.build index 0939bcf2..905fd5b6 100644 --- a/src/libsysprof-analyze/meson.build +++ b/src/libsysprof-analyze/meson.build @@ -25,6 +25,7 @@ libsysprof_analyze_private_sources = [ 'sysprof-document-bitset-index.c', 'sysprof-mapped-file.c', 'sysprof-memory-map.c', + 'sysprof-mount.c', 'sysprof-mount-device.c', 'sysprof-mount-namespace.c', ] diff --git a/src/libsysprof-analyze/sysprof-mount-private.h b/src/libsysprof-analyze/sysprof-mount-private.h new file mode 100644 index 00000000..081fef17 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-mount-private.h @@ -0,0 +1,41 @@ +/* sysprof-mount-private.h + * + * Copyright 2023 Christian Hergert + * + * 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 3 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_MOUNT (sysprof_mount_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofMount, sysprof_mount, SYSPROF, MOUNT, GObject) + +SysprofMount *sysprof_mount_new_for_mountinfo (const char *mountinfo); +int sysprof_mount_get_device_major (SysprofMount *self); +int sysprof_mount_get_device_minor (SysprofMount *self); +const char *sysprof_mount_get_root (SysprofMount *self); +const char *sysprof_mount_get_mount_path (SysprofMount *self); +const char *sysprof_mount_get_mount_source (SysprofMount *self); +const char *sysprof_mount_get_filesystem_type (SysprofMount *self); +const char *sysprof_mount_get_superblock_option (SysprofMount *self, + const char *option); + +G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-mount.c b/src/libsysprof-analyze/sysprof-mount.c new file mode 100644 index 00000000..786bf111 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-mount.c @@ -0,0 +1,198 @@ +/* sysprof-mount.c + * + * Copyright 2023 Christian Hergert + * + * 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 3 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "sysprof-mount-private.h" + +struct _SysprofMount +{ + GObject parent_instance; + int device_major; + int device_minor; + GRefString *root; + GRefString *mount_path; + GRefString *mount_source; + GRefString *filesystem_type; + GRefString *superblock_options; +}; + +enum { + PROP_0, + PROP_DEVICE_MAJOR, + PROP_DEVICE_MINOR, + PROP_ROOT, + PROP_MOUNT_PATH, + PROP_MOUNT_SOURCE, + PROP_FILESYSTEM_TYPE, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofMount, sysprof_mount, G_TYPE_OBJECT) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_mount_finalize (GObject *object) +{ + SysprofMount *self = (SysprofMount *)object; + + g_clear_pointer (&self->root, g_ref_string_release); + g_clear_pointer (&self->mount_path, g_ref_string_release); + g_clear_pointer (&self->mount_source, g_ref_string_release); + g_clear_pointer (&self->filesystem_type, g_ref_string_release); + g_clear_pointer (&self->superblock_options, g_ref_string_release); + + G_OBJECT_CLASS (sysprof_mount_parent_class)->finalize (object); +} + +static void +sysprof_mount_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofMount *self = SYSPROF_MOUNT (object); + + switch (prop_id) + { + case PROP_DEVICE_MAJOR: + g_value_set_int (value, sysprof_mount_get_device_major (self)); + break; + + case PROP_DEVICE_MINOR: + g_value_set_int (value, sysprof_mount_get_device_minor (self)); + break; + + case PROP_ROOT: + g_value_set_string (value, sysprof_mount_get_root (self)); + break; + + case PROP_MOUNT_PATH: + g_value_set_string (value, sysprof_mount_get_mount_path (self)); + break; + + case PROP_MOUNT_SOURCE: + g_value_set_string (value, sysprof_mount_get_mount_source (self)); + break; + + case PROP_FILESYSTEM_TYPE: + g_value_set_string (value, sysprof_mount_get_filesystem_type (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_mount_class_init (SysprofMountClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = sysprof_mount_finalize; + object_class->get_property = sysprof_mount_get_property; + + properties[PROP_DEVICE_MAJOR] = + g_param_spec_int ("device-major", NULL, NULL, + G_MININT, G_MAXINT, 0, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties[PROP_DEVICE_MINOR] = + g_param_spec_int ("device-minor", NULL, NULL, + G_MININT, G_MAXINT, 0, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties[PROP_ROOT] = + g_param_spec_string ("root", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties[PROP_MOUNT_PATH] = + g_param_spec_string ("mount-path", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties[PROP_MOUNT_SOURCE] = + g_param_spec_string ("mount-source", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + properties[PROP_FILESYSTEM_TYPE] = + g_param_spec_string ("filesystem-type", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); +} + +static void +sysprof_mount_init (SysprofMount *self) +{ +} + +SysprofMount * +sysprof_mount_new_for_mountinfo (const char *mountinfo) +{ + return NULL; +} + +int +sysprof_mount_get_device_major (SysprofMount *self) +{ + return self->device_major; +} + +int +sysprof_mount_get_device_minor (SysprofMount *self) +{ + return self->device_minor; +} + +const char * +sysprof_mount_get_root (SysprofMount *self) +{ + return self->root; +} + +const char * +sysprof_mount_get_mount_path (SysprofMount *self) +{ + return self->mount_path; +} + +const char * +sysprof_mount_get_mount_source (SysprofMount *self) +{ + return self->mount_source; +} + +const char * +sysprof_mount_get_filesystem_type (SysprofMount *self) +{ + return self->filesystem_type; +} + +const char * +sysprof_mount_get_superblock_option (SysprofMount *self, + const char *option) +{ + return NULL; +}