From 3292f95707bae14f0d51f4db558c08d920f2bfa6 Mon Sep 17 00:00:00 2001 From: Vishal Rao Date: Fri, 8 Oct 2021 22:47:15 +0530 Subject: [PATCH 1/2] Handle disk sector size --- src/Objects/Mount.vala | 4 +++- src/Views/PartitioningView.vala | 8 ++++---- src/Widgets/DiskBar.vala | 10 ++++++---- src/Widgets/PartitionBar.vala | 6 ++++++ src/Widgets/PartitionMenu.vala | 1 + 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Objects/Mount.vala b/src/Objects/Mount.vala index 6896f0ac6..5da75293d 100644 --- a/src/Objects/Mount.vala +++ b/src/Objects/Mount.vala @@ -23,12 +23,13 @@ public class Installer.Mount { public string parent_disk; public string mount_point; public uint64 sectors; + public uint64 sector_size; public Distinst.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, uint64 sector_size, InstallerDaemon.MountFlags flags, Distinst.FileSystem fs, PartitionMenu menu) { filesystem = fs; mount_point = mount; @@ -37,6 +38,7 @@ public class Installer.Mount { this.menu = menu; this.parent_disk = parent_disk; this.sectors = sectors; + this.sector_size = sector_size; } public bool is_valid_boot_mount () { diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index 44ec75850..64ca0a2c0 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -43,7 +43,7 @@ public class Installer.PartitioningView : AbstractInstallerView { EFI } - const uint64 REQUIRED_EFI_SECTORS = 524288; + const uint64 REQUIRED_ESP_SIZE = 256 * 1024 * 1024; construct { mounts = new Gee.ArrayList (); @@ -161,7 +161,7 @@ public class Installer.PartitioningView : AbstractInstallerView { partitions.add (partition); } - var disk_bar = new DiskBar (disk.name, path, size, (owned) partitions); + var disk_bar = new DiskBar (disk.name, path, size, sector_size, (owned) partitions); disk_list.add (disk_bar); } @@ -212,7 +212,7 @@ public class Installer.PartitioningView : AbstractInstallerView { partitions.add (partition); } - var disk_bar = new DiskBar (disk.name, path, size, (owned) partitions); + var disk_bar = new DiskBar (disk.name, path, size, sector_size, (owned) partitions); disk_list.add (disk_bar); } @@ -269,7 +269,7 @@ public class Installer.PartitioningView : AbstractInstallerView { if (mount.mount_point == "/boot/efi") { if (!mount.is_valid_boot_mount ()) { throw new GLib.IOError.FAILED (_("EFI partition has the wrong file system")); - } else if (mount.sectors < REQUIRED_EFI_SECTORS) { + } else if ((mount.sectors * mount.sector_size) < REQUIRED_ESP_SIZE) { throw new GLib.IOError.FAILED (_("EFI partition is too small")); } } else if (mount.mount_point == "/" && !mount.is_valid_root_mount ()) { diff --git a/src/Widgets/DiskBar.vala b/src/Widgets/DiskBar.vala index aa606d506..c1b5c8aec 100644 --- a/src/Widgets/DiskBar.vala +++ b/src/Widgets/DiskBar.vala @@ -22,17 +22,19 @@ public class Installer.DiskBar: Gtk.Grid { public string disk_name { get; construct; } public string disk_path { get; construct; } public uint64 size { get; construct; } + public uint64 sector_size { get; construct; } public Gee.ArrayList partitions { get; construct; } private static Gtk.SizeGroup label_sizegroup; private Gtk.Grid legend_container; - public DiskBar (string disk_name, string disk_path, uint64 size, Gee.ArrayList partitions) { + public DiskBar (string disk_name, string disk_path, uint64 size, uint64 sector_size, Gee.ArrayList partitions) { Object ( disk_name: disk_name, disk_path: disk_path, partitions: partitions, + sector_size: sector_size, size: size ); } @@ -89,7 +91,7 @@ public class Installer.DiskBar: Gtk.Grid { legend.add (legend_container); foreach (PartitionBar p in partitions) { - add_legend (p.path, p.get_size () * 512, Distinst.strfilesys (p.filesystem), p.vg, p.menu); + add_legend (p.path, p.get_size () * sector_size, Distinst.strfilesys (p.filesystem), p.vg, p.menu); } uint64 used = 0; @@ -97,7 +99,7 @@ public class Installer.DiskBar: Gtk.Grid { used += partition.get_size (); } - var unused = size - (used * 512); + var unused = size - (used * sector_size); if (size / 100 < unused) { add_legend ("unused", unused, "unused", null, null); @@ -167,7 +169,7 @@ public class Installer.DiskBar: Gtk.Grid { private void update_sector_lengths (Gee.ArrayList partitions, Gtk.Allocation alloc) { var alloc_width = alloc.width; - var disk_sectors = this.size / 512; + var disk_sectors = this.size / sector_size; int[] lengths = {}; for (int x = 0; x < partitions.size; x++) { diff --git a/src/Widgets/PartitionBar.vala b/src/Widgets/PartitionBar.vala index df44cc955..afb5da9d3 100644 --- a/src/Widgets/PartitionBar.vala +++ b/src/Widgets/PartitionBar.vala @@ -24,6 +24,7 @@ public class Installer.PartitionBar : Gtk.EventBox { public uint64 start; public uint64 end; public uint64 used; + public uint64 sector_size; public new string path; public string? vg; @@ -38,6 +39,7 @@ public class Installer.PartitionBar : Gtk.EventBox { UnsetMount unset_mount, MountSetFn mount_set) { start = part.start_sector; end = part.end_sector; + this.sector_size = sector_size; var usage = part.sectors_used; if (usage.tag == 1) { @@ -89,6 +91,10 @@ public class Installer.PartitionBar : Gtk.EventBox { return end - start; } + public uint64 get_sector_size () { + return sector_size; + } + public double get_percent (uint64 disk_sectors) { return (((double) this.get_size () / (double) disk_sectors)); } diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index 51007cf49..86bf18943 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -266,6 +266,7 @@ public class Installer.PartitionMenu : Gtk.Popover { parent_disk, mount, partition_bar.end - partition_bar.start, + partition_bar.sector_size, (format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0) + (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), filesystem, From 4da7330dee9aad784108a6c68bad5385526987d4 Mon Sep 17 00:00:00 2001 From: Vishal Rao Date: Sun, 28 Nov 2021 17:01:09 +0530 Subject: [PATCH 2/2] Remove unused method. --- src/Widgets/PartitionBar.vala | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Widgets/PartitionBar.vala b/src/Widgets/PartitionBar.vala index afb5da9d3..83d04f9b3 100644 --- a/src/Widgets/PartitionBar.vala +++ b/src/Widgets/PartitionBar.vala @@ -91,10 +91,6 @@ public class Installer.PartitionBar : Gtk.EventBox { return end - start; } - public uint64 get_sector_size () { - return sector_size; - } - public double get_percent (uint64 disk_sectors) { return (((double) this.get_size () / (double) disk_sectors)); }