diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index 5092e5311..1f2e9abe7 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -339,33 +339,209 @@ public class Installer.PartitioningView : AbstractInstallerView { InstallerDaemon.Disk[] physical_disks = {}; InstallerDaemon.Disk[] logical_disks = {}; - InstallerDaemon.Partition[] partitions = {}; + var partitions_0 = InstallerDaemon.Partition () { + device_path = "/dev/sda1", + filesystem = InstallerDaemon.FileSystem.NONE, + start_sector = 34, + end_sector = 32767, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 0, + value = 0 + }, + current_lvm_volume_group = "" + }; - var usage_1 = InstallerDaemon.PartitionUsage () { - tag = 1, - value = 30312 + var partitions_1 = InstallerDaemon.Partition () { + device_path = "/dev/sda2", + filesystem = InstallerDaemon.FileSystem.NTFS, + start_sector = 32768, + end_sector = 3907026943, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 73486552 + }, + current_lvm_volume_group = "" }; - partitions += InstallerDaemon.Partition () { - device_path = "/dev/nvme0n1p1", + physical_disks += InstallerDaemon.Disk () { + name = "ATA ST2000DM008-2FR1", + device_path = "/dev/sda", + sectors = 3907029168, + sector_size = 512, + rotational = true, + removable = false, + partitions = {partitions_0, partitions_1} + }; + + var partitions_2 = InstallerDaemon.Partition () { + device_path = "/dev/sdb1", + filesystem = InstallerDaemon.FileSystem.NTFS, + start_sector = 8192, + end_sector = 1953524143, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 14657872 + }, + current_lvm_volume_group = "" + }; + + physical_disks += InstallerDaemon.Disk () { + name = "ATA SAMSUNG HD103SJ", + device_path = "/dev/sdb", + sectors = 1953525168, + sector_size = 512, + rotational = true, + removable = false, + partitions = {partitions_2} + }; + + var partitions_3 = InstallerDaemon.Partition () { + device_path = "/dev/sdc1", filesystem = InstallerDaemon.FileSystem.FAT32, start_sector = 4096, end_sector = 542966, - sectors_used = usage_1, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 30328 + }, + current_lvm_volume_group = "" + }; + + var partitions_4 = InstallerDaemon.Partition () { + device_path = "/dev/sdc2", + filesystem = InstallerDaemon.FileSystem.LVM, + start_sector = 542968, + end_sector = 1062820270, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 0, + value = 0 + }, + current_lvm_volume_group = "data" + }; + + physical_disks += InstallerDaemon.Disk () { + name = "ATA INTEL SSDSC2BX80", + device_path = "/dev/sdc", + sectors = 1562824368, + sector_size = 4096, + rotational = false, + removable = false, + partitions = {partitions_3, partitions_4} + }; + + var partitions_5 = InstallerDaemon.Partition () { + device_path = "/dev/nvme0n1p1", + filesystem = InstallerDaemon.FileSystem.FAT32, + start_sector = 2048, + end_sector = 1023999, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 58488 + }, + current_lvm_volume_group = "" + }; + + var partitions_6 = InstallerDaemon.Partition () { + device_path = "/dev/nvme0n1p2", + filesystem = InstallerDaemon.FileSystem.NONE, + start_sector = 1024000, + end_sector = 1286143, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 0, + value = 0 + }, + current_lvm_volume_group = "" + }; + + var partitions_7 = InstallerDaemon.Partition () { + device_path = "/dev/nvme0n1p3", + filesystem = InstallerDaemon.FileSystem.NTFS, + start_sector = 1286144, + end_sector = 1952003975, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 1624133504 + }, current_lvm_volume_group = "" }; - var usage_2 = InstallerDaemon.PartitionUsage () { - tag = 0, - value = 0 + var partitions_8 = InstallerDaemon.Partition () { + device_path = "/dev/nvme0n1p4", + filesystem = InstallerDaemon.FileSystem.NTFS, + start_sector = 1952004096, + end_sector = 1953519615, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 1305608 + }, + current_lvm_volume_group = "" + }; + + physical_disks += InstallerDaemon.Disk () { + name = "WDC WDS100T2B0C-00PXH0", + device_path = "/dev/nvme0n1", + sectors = 1953525168, + sector_size = 512, + rotational = false, + removable = false, + partitions = {partitions_5, partitions_6, partitions_7, partitions_8} + }; + + var partitions_9 = InstallerDaemon.Partition () { + device_path = "/dev/dm-0", + filesystem = InstallerDaemon.FileSystem.EXT4, + start_sector = 0, + end_sector = 1554268160, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 136999784 + }, + current_lvm_volume_group = "" + }; + + var partitions_10 = InstallerDaemon.Partition () { + device_path = "/dev/dm-1", + filesystem = InstallerDaemon.FileSystem.SWAP, + start_sector = 1554268161, + end_sector = 1562271745, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 0, + value = 0 + }, + current_lvm_volume_group = "" + }; + + logical_disks += InstallerDaemon.Disk () { + name = "LVM data", + device_path = "/dev/mapper/data", + sectors = 1562277302, + sector_size = 512, + rotational = false, + removable = false, + partitions = {partitions_9, partitions_10} + }; + + var partitions_11 = InstallerDaemon.Partition () { + device_path = "/dev/nvme0n1p1", + filesystem = InstallerDaemon.FileSystem.FAT32, + start_sector = 4096, + end_sector = 542966, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 30312 + }, + current_lvm_volume_group = "" }; - partitions += InstallerDaemon.Partition () { + var partitions_12 = InstallerDaemon.Partition () { device_path = "/dev/nvme0n1p2", filesystem = InstallerDaemon.FileSystem.LVM, start_sector = 542968, end_sector = 976769070, - sectors_used = usage_2, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 0, + value = 0 + }, current_lvm_volume_group = "data" }; @@ -376,7 +552,41 @@ public class Installer.PartitioningView : AbstractInstallerView { sector_size = 512, rotational = false, removable = false, - partitions = partitions + partitions = {partitions_11, partitions_12} + }; + + var partitions_13 = InstallerDaemon.Partition () { + device_path = "/dev/dm-0", + filesystem = InstallerDaemon.FileSystem.EXT4, + start_sector = 0, + end_sector = 968220672, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 534569520 + }, + current_lvm_volume_group = "" + }; + + var partitions_14 = InstallerDaemon.Partition () { + device_path = "/dev/dm-1", + filesystem = InstallerDaemon.FileSystem.SWAP, + start_sector = 968220673, + end_sector = 976216065, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 0, + value = 0 + }, + current_lvm_volume_group = "" + }; + + logical_disks += InstallerDaemon.Disk () { + name = "LVM data", + device_path = "/dev/mapper/data", + sectors = 976226102, + sector_size = 512, + rotational = false, + removable = false, + partitions = {partitions_13, partitions_14} }; return InstallerDaemon.DiskInfo () { diff --git a/src/Widgets/DiskBar.vala b/src/Widgets/DiskBar.vala index 5e4e790c8..cd29ca842 100644 --- a/src/Widgets/DiskBar.vala +++ b/src/Widgets/DiskBar.vala @@ -21,20 +21,19 @@ public class Installer.DiskBar: Gtk.Box { } construct { - var size = disk.sectors * disk.sector_size; - var name_label = new Granite.HeaderLabel (disk.name) { - secondary_text = "%s %s".printf (disk.device_path, GLib.format_size (size)) + // Calculate the actual size of the disk in bytes for the label + secondary_text = "%s %s".printf (disk.device_path, GLib.format_size (disk.sectors * disk.sector_size)) }; - var bar = new PartitionContainer (size, partitions); + var bar = new PartitionContainer (disk.sectors, partitions); var legend_box = new Gtk.Box (VERTICAL, 6) { halign = START }; foreach (PartitionBlock partition_block in partitions) { - var legend = new Legend (partition_block.partition); + var legend = new Legend (partition_block.partition, disk.sector_size); legend_box.append (legend); var click_gesture = new Gtk.GestureClick (); @@ -43,14 +42,14 @@ public class Installer.DiskBar: Gtk.Box { legend.add_controller (click_gesture); } - uint64 used = 0; + uint64 used_sectors = 0; foreach (PartitionBlock partition in partitions) { - used += partition.get_partition_size (); + used_sectors += partition.get_partition_size_in_sectors (); } - var unused = size - (used * 512); - if (size / 100 < unused) { - var legend = new Legend.unused (unused); + // If more than 1% of the disk is unused, show a legend for the unused space + if ((double)(disk.sectors - used_sectors) / disk.sectors > 0.01) { + var legend = new Legend.unused ((disk.sectors - used_sectors) * disk.sector_size); legend_box.append (legend); } @@ -67,14 +66,14 @@ public class Installer.DiskBar: Gtk.Box { private class PartitionContainer : Gtk.Widget { public Gee.ArrayList partitions { get; construct; } - public uint64 size { get; construct; } + public uint64 total_disk_sectors { get; construct; } private Gtk.ConstraintGuide guide; - public PartitionContainer (uint64 size, Gee.ArrayList partitions) { + public PartitionContainer (uint64 total_disk_sectors, Gee.ArrayList partitions) { Object ( - partitions: partitions, - size: size + total_disk_sectors: total_disk_sectors, + partitions: partitions ); } @@ -105,13 +104,11 @@ public class Installer.DiskBar: Gtk.Box { ) ); - uint64 used = 0; - var disk_sectors = size / 512; + uint64 used_sectors = 0; foreach (var partition in partitions) { - double percent_requested = (double) partition.get_partition_size () / disk_sectors; - percent_requested = percent_requested.clamp (0.01, 0.99); + double percent_requested = (double) partition.get_partition_size_in_sectors () / total_disk_sectors; - used += partition.get_partition_size (); + used_sectors += partition.get_partition_size_in_sectors (); append_partition ( partition, @@ -119,12 +116,13 @@ public class Installer.DiskBar: Gtk.Box { ); } - var unused = size - (used * 512); - if (size / 100 < unused) { + // If more than 1% of the disk is unused, show a block for the unused space + var unused_sectors = total_disk_sectors - used_sectors; + if ((double) unused_sectors / total_disk_sectors > 0.01) { var unused_bar = new Block (); unused_bar.add_css_class ("unused"); - append_partition (unused_bar, (double) unused / size); + append_partition (unused_bar, (double) unused_sectors / total_disk_sectors); } // Position last child at end @@ -149,6 +147,9 @@ public class Installer.DiskBar: Gtk.Box { } private void append_partition (Gtk.Widget widget, double percentage) { + // Truncate to 2 decimal places (round down), to ensure we don't go over 100% because of rounding errors + percentage = (int)(percentage * 100) / 100.0; + widget.set_parent (this); var layout_manager = ((Gtk.ConstraintLayout) get_layout_manager ()); @@ -220,19 +221,20 @@ public class Installer.DiskBar: Gtk.Box { public string fs { get; construct; } public string? vg { get; construct; default = null; } - public Legend (InstallerDaemon.Partition partition) { + public Legend (InstallerDaemon.Partition partition, uint64 sector_size) { Object ( ppath: partition.device_path, - size: (partition.end_sector - partition.start_sector) * 512, + // Calculate the actual size of the partition in bytes for the label + size: (partition.end_sector - partition.start_sector) * sector_size, fs: partition.filesystem.to_string (), vg: partition.filesystem == LVM ? partition.current_lvm_volume_group : null ); } - public Legend.unused (uint64 size) { + public Legend.unused (uint64 size_in_bytes) { Object ( ppath: "unused", - size: size, + size: size_in_bytes, fs: "unused" ); } diff --git a/src/Widgets/PartitionBlock.vala b/src/Widgets/PartitionBlock.vala index a3e977287..34599f86f 100644 --- a/src/Widgets/PartitionBlock.vala +++ b/src/Widgets/PartitionBlock.vala @@ -50,7 +50,7 @@ public class Installer.PartitionBlock : Adw.Bin { bind_property ("icon", image, "gicon", SYNC_CREATE); } - public uint64 get_partition_size () { + public uint64 get_partition_size_in_sectors () { return partition.end_sector - partition.start_sector; } } diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index ec38f8fc1..739865af7 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -270,7 +270,7 @@ public class Installer.PartitionMenu : Gtk.Popover { partition_path, parent_disk, mount, - partition_bar.get_partition_size (), + partition_bar.get_partition_size_in_sectors (), (format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0) + (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), filesystem,