From 21a905065bf3c4ba02676c6cb5e26510fe551b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 11 Sep 2024 15:31:13 -0700 Subject: [PATCH] DBusStructures: add filesystem enum --- common/DBusStructures.vala | 62 ++++++++++++++++++++++--- daemon/Daemon.vala | 82 +++++++++++++++++++++++++++++---- src/Objects/Mount.vala | 14 +++--- src/Views/PartitioningView.vala | 2 +- src/Widgets/DiskBar.vala | 2 +- src/Widgets/PartitionBar.vala | 2 +- src/Widgets/PartitionMenu.vala | 26 +++++------ 7 files changed, 152 insertions(+), 38 deletions(-) diff --git a/common/DBusStructures.vala b/common/DBusStructures.vala index 388e2b9ed..1ca14fb0f 100644 --- a/common/DBusStructures.vala +++ b/common/DBusStructures.vala @@ -31,10 +31,58 @@ public struct InstallerDaemon.Disk { Partition[] partitions; } +public enum InstallerDaemon.FileSystem { + NONE, + BTRFS, + EXT2, + EXT3, + EXT4, + F2FS, + FAT16, + FAT32, + NTFS, + SWAP, + XFS, + LVM, + LUKS; + + public unowned string to_string () { + switch (this) { + case BTRFS: + return "btrfs"; + case EXT2: + return "ext2"; + case EXT3: + return "ext3"; + case EXT4: + return "ext4"; + case F2FS: + return "f2fs"; + case FAT16: + return "fat16"; + case FAT32: + return "fat32"; + case NTFS: + return "ntfs"; + case SWAP: + return "swap"; + case XFS: + return "xfs"; + case LVM: + return "lvm"; + case LUKS: + return "luks"; + case NONE: + default: + return "none"; + } + } +} + public struct InstallerDaemon.Partition { string device_path; - Distinst.FileSystem filesystem; + FileSystem filesystem; uint64 start_sector; uint64 end_sector; @@ -62,18 +110,18 @@ public struct InstallerDaemon.Mount { string parent_disk; string mount_point; uint64 sectors; - Distinst.FileSystem filesystem; + FileSystem filesystem; MountFlags flags; public bool is_valid_boot_mount () { - return filesystem == Distinst.FileSystem.FAT16 - || filesystem == Distinst.FileSystem.FAT32; + return filesystem == FileSystem.FAT16 + || filesystem == FileSystem.FAT32; } public bool is_valid_root_mount () { - return filesystem != Distinst.FileSystem.FAT16 - && filesystem != Distinst.FileSystem.FAT32 - && filesystem != Distinst.FileSystem.NTFS; + return filesystem != FileSystem.FAT16 + && filesystem != FileSystem.FAT32 + && filesystem != FileSystem.NTFS; } public bool is_lvm () { diff --git a/daemon/Daemon.vala b/daemon/Daemon.vala index 2a93ea6c0..04a53fe55 100644 --- a/daemon/Daemon.vala +++ b/daemon/Daemon.vala @@ -69,7 +69,7 @@ public class InstallerDaemon.Daemon : GLib.Object { partitions += Partition () { device_path = string_from_utf8 (part.get_device_path ()), - filesystem = part.get_file_system (), + filesystem = to_common_fs (part.get_file_system ()), start_sector = part.get_start_sector (), end_sector = part.get_end_sector (), sectors_used = part.sectors_used (disk.get_sector_size ()), @@ -103,7 +103,7 @@ public class InstallerDaemon.Daemon : GLib.Object { partitions += Partition () { device_path = string_from_utf8 (part.get_device_path ()), - filesystem = part.get_file_system (), + filesystem = to_common_fs (part.get_file_system ()), start_sector = part.get_start_sector (), end_sector = part.get_end_sector (), sectors_used = part.sectors_used (disk.get_sector_size ()), @@ -149,7 +149,7 @@ public class InstallerDaemon.Daemon : GLib.Object { partitions += Partition () { device_path = string_from_utf8 (part.get_device_path ()), - filesystem = part.get_file_system (), + filesystem = to_common_fs (part.get_file_system ()), start_sector = part.get_start_sector (), end_sector = part.get_end_sector (), sectors_used = part.sectors_used (disk.get_sector_size ()), @@ -451,7 +451,7 @@ public class InstallerDaemon.Daemon : GLib.Object { if (m.mount_point == "/boot/efi") { if (m.is_valid_boot_mount ()) { if (m.should_format ()) { - partition.format_with (m.filesystem); + partition.format_with (to_distinst_fs (m.filesystem)); } partition.set_mount (m.mount_point); @@ -460,7 +460,7 @@ public class InstallerDaemon.Daemon : GLib.Object { throw new GLib.IOError.FAILED ("Unreachable code path -- EFI partition is invalid"); } } else { - if (m.filesystem != Distinst.FileSystem.SWAP) { + if (m.filesystem != SWAP) { partition.set_mount (m.mount_point); } @@ -469,7 +469,7 @@ public class InstallerDaemon.Daemon : GLib.Object { } if (m.should_format ()) { - partition.format_with (m.filesystem); + partition.format_with (to_distinst_fs (m.filesystem)); } } } @@ -498,12 +498,12 @@ public class InstallerDaemon.Daemon : GLib.Object { throw new GLib.IOError.FAILED ("could not find %s", m.partition_path); } - if (m.filesystem != Distinst.FileSystem.SWAP) { + if (m.filesystem != SWAP) { partition.set_mount (m.mount_point); } if (m.should_format ()) { - partition.format_and_keep_name (m.filesystem); + partition.format_and_keep_name (to_distinst_fs (m.filesystem)); } } } @@ -513,6 +513,72 @@ public class InstallerDaemon.Daemon : GLib.Object { builder.append_len ((string) input, input.length); return (owned) builder.str; } + + private InstallerDaemon.FileSystem to_common_fs (Distinst.FileSystem fs) { + switch (fs) { + case BTRFS: + return InstallerDaemon.FileSystem.BTRFS; + case EXT2: + return InstallerDaemon.FileSystem.EXT2; + case EXT3: + return InstallerDaemon.FileSystem.EXT3; + case EXT4: + return InstallerDaemon.FileSystem.EXT4; + case F2FS: + return InstallerDaemon.FileSystem.F2FS; + case FAT16: + return InstallerDaemon.FileSystem.FAT16; + case FAT32: + return InstallerDaemon.FileSystem.FAT32; + case NONE: + return InstallerDaemon.FileSystem.NONE; + case NTFS: + return InstallerDaemon.FileSystem.NTFS; + case SWAP: + return InstallerDaemon.FileSystem.SWAP; + case XFS: + return InstallerDaemon.FileSystem.XFS; + case LVM: + return InstallerDaemon.FileSystem.LVM; + case LUKS: + return InstallerDaemon.FileSystem.LUKS; + default: + return InstallerDaemon.FileSystem.NONE; + } + } + + private Distinst.FileSystem to_distinst_fs (InstallerDaemon.FileSystem fs) { + switch (fs) { + case BTRFS: + return Distinst.FileSystem.BTRFS; + case EXT2: + return Distinst.FileSystem.EXT2; + case EXT3: + return Distinst.FileSystem.EXT3; + case EXT4: + return Distinst.FileSystem.EXT4; + case F2FS: + return Distinst.FileSystem.F2FS; + case FAT16: + return Distinst.FileSystem.FAT16; + case FAT32: + return Distinst.FileSystem.FAT32; + case NONE: + return Distinst.FileSystem.NONE; + case NTFS: + return Distinst.FileSystem.NTFS; + case SWAP: + return Distinst.FileSystem.SWAP; + case XFS: + return Distinst.FileSystem.XFS; + case LVM: + return Distinst.FileSystem.LVM; + case LUKS: + return Distinst.FileSystem.LUKS; + default: + return Distinst.FileSystem.NONE; + } + } } private void on_bus_acquired (GLib.DBusConnection connection, string name) { diff --git a/src/Objects/Mount.vala b/src/Objects/Mount.vala index 6896f0ac6..b20ac7a21 100644 --- a/src/Objects/Mount.vala +++ b/src/Objects/Mount.vala @@ -23,12 +23,12 @@ public class Installer.Mount { public string parent_disk; public string mount_point; public uint64 sectors; - public Distinst.FileSystem filesystem; + public InstallerDaemon.FileSystem filesystem; public InstallerDaemon.MountFlags flags; public PartitionMenu menu; public Mount (string partition, string parent_disk, string mount, - uint64 sectors, InstallerDaemon.MountFlags flags, Distinst.FileSystem fs, + uint64 sectors, InstallerDaemon.MountFlags flags, InstallerDaemon.FileSystem fs, PartitionMenu menu) { filesystem = fs; mount_point = mount; @@ -40,14 +40,14 @@ public class Installer.Mount { } public bool is_valid_boot_mount () { - return filesystem == Distinst.FileSystem.FAT16 - || filesystem == Distinst.FileSystem.FAT32; + return filesystem == FAT16 + || filesystem == FAT32; } public bool is_valid_root_mount () { - return filesystem != Distinst.FileSystem.FAT16 - && filesystem != Distinst.FileSystem.FAT32 - && filesystem != Distinst.FileSystem.NTFS; + return filesystem != FAT16 + && filesystem != FAT32 + && filesystem != NTFS; } public bool is_lvm () { diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index 1400e4eab..3b6b8d0d8 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -255,7 +255,7 @@ public class Installer.PartitioningView : AbstractInstallerView { m.parent_disk, m.partition_path, m.mount_point, - Distinst.strfilesys (m.filesystem), + m.filesystem.to_string (), m.should_format () ? "true" : "false" ); diff --git a/src/Widgets/DiskBar.vala b/src/Widgets/DiskBar.vala index 3641d11e5..a0c3a26ec 100644 --- a/src/Widgets/DiskBar.vala +++ b/src/Widgets/DiskBar.vala @@ -41,7 +41,7 @@ public class Installer.DiskBar: Gtk.Box { add_legend ( p.partition.device_path, p.get_partition_size () * 512, - Distinst.strfilesys (p.partition.filesystem), + p.partition.filesystem.to_string (), p.volume_group, p.menu ); diff --git a/src/Widgets/PartitionBar.vala b/src/Widgets/PartitionBar.vala index 219ec8518..0ae7c8743 100644 --- a/src/Widgets/PartitionBar.vala +++ b/src/Widgets/PartitionBar.vala @@ -65,7 +65,7 @@ public class Installer.PartitionBar : Gtk.Box { hexpand = true; tooltip_text = partition.device_path; - add_css_class (Distinst.strfilesys (partition.filesystem)); + add_css_class (partition.filesystem.to_string ()); bind_property ("icon", image, "gicon", SYNC_CREATE); } diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index 659ada23d..4fa4b446d 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -28,7 +28,7 @@ public class Installer.PartitionMenu : Gtk.Popover { private bool is_lvm; private string parent_disk; private string partition_path; - private Distinst.FileSystem original_filesystem; + private InstallerDaemon.FileSystem original_filesystem; private Granite.SwitchModelButton format_partition; private Granite.SwitchModelButton use_partition; @@ -40,7 +40,7 @@ public class Installer.PartitionMenu : Gtk.Popover { // A reference to the parent which owns this menu. private PartitionBar partition_bar; - public PartitionMenu (string path, string parent, Distinst.FileSystem fs, + public PartitionMenu (string path, string parent, InstallerDaemon.FileSystem fs, bool lvm, SetMount set_mount, UnsetMount unset_mount, MountSetFn mount_set, PartitionBar partition_bar) { this.partition_bar = partition_bar; @@ -205,13 +205,13 @@ public class Installer.PartitionMenu : Gtk.Popover { disable_signals = false; int select = 0; - if (fs == Distinst.FileSystem.FAT16 || fs == Distinst.FileSystem.FAT32) { + if (fs == InstallerDaemon.FileSystem.FAT16 || fs == InstallerDaemon.FileSystem.FAT32) { if (mount_set (boot_partition)) { select = 4; } else { select = 2; } - } else if (fs == Distinst.FileSystem.SWAP) { + } else if (fs == InstallerDaemon.FileSystem.SWAP) { select = 3; } else if (mount_set ("/")) { if (mount_set ("/home" )) { @@ -258,7 +258,7 @@ public class Installer.PartitionMenu : Gtk.Popover { private void update_values (SetMount set_mount) { var mount = get_mount (); var filesystem = mount == "swap" - ? Distinst.FileSystem.SWAP + ? InstallerDaemon.FileSystem.SWAP : get_file_system (); string? error = null; @@ -290,22 +290,22 @@ public class Installer.PartitionMenu : Gtk.Popover { return original_filesystem == get_file_system (); } - private Distinst.FileSystem get_file_system () { + private InstallerDaemon.FileSystem get_file_system () { switch (type.active) { case 0: - return Distinst.FileSystem.EXT4; + return InstallerDaemon.FileSystem.EXT4; case 1: - return Distinst.FileSystem.FAT16; + return InstallerDaemon.FileSystem.FAT16; case 2: - return Distinst.FileSystem.FAT32; + return InstallerDaemon.FileSystem.FAT32; case 3: - return Distinst.FileSystem.BTRFS; + return InstallerDaemon.FileSystem.BTRFS; case 4: - return Distinst.FileSystem.XFS; + return InstallerDaemon.FileSystem.XFS; case 5: - return Distinst.FileSystem.NTFS; + return InstallerDaemon.FileSystem.NTFS; default: - return Distinst.FileSystem.NONE; + return InstallerDaemon.FileSystem.NONE; } }