From 671e62fe436b822b5c6fe88450b15e4a1238d5c3 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 23 Apr 2019 12:19:28 -0600 Subject: [PATCH 1/2] :ambulance: Support sector sizes that are not 512 bytes --- src/Objects/Mount.vala | 6 ++++-- src/Utils.vala | 6 +++++- src/Views/DiskView.vala | 3 ++- src/Views/PartitioningView.vala | 2 +- src/Widgets/PartitionBar.vala | 2 ++ src/Widgets/PartitionMenu.vala | 1 + 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Objects/Mount.vala b/src/Objects/Mount.vala index 8e58374be..d5a069bd7 100644 --- a/src/Objects/Mount.vala +++ b/src/Objects/Mount.vala @@ -23,6 +23,7 @@ public class Installer.Mount { public string parent_disk; public string mount_point; public uint64 sectors; + public uint64 sector_size; public Distinst.FileSystem filesystem; public Flags flags; public PartitionMenu menu; @@ -35,8 +36,8 @@ public class Installer.Mount { } public Mount (string partition, string parent_disk, string mount, - uint64 sectors, Flags flags, Distinst.FileSystem fs, - PartitionMenu menu) { + uint64 sectors, uint64 sector_size, Flags flags, + Distinst.FileSystem fs, PartitionMenu menu) { filesystem = fs; mount_point = mount; partition_path = partition; @@ -44,6 +45,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/Utils.vala b/src/Utils.vala index b2932c686..a474ff103 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -18,9 +18,13 @@ * Authored by: Corentin Noël */ -const double SECTORS_AS_GIB = 2 * 1024 * 1024; +const uint64 SECTORS_AS_GIB = 2 * 1024 * 1024; namespace Utils { + public uint64 normalize_sectors (uint64 base_count, uint64 sector_size) { + return base_count / (sector_size / 512); + } + public string string_from_utf8 (uint8[] input) { var builder = new GLib.StringBuilder.sized (input.length); builder.append_len ((string) input, input.length); diff --git a/src/Views/DiskView.vala b/src/Views/DiskView.vala index d33e744de..5cf3e2457 100644 --- a/src/Views/DiskView.vala +++ b/src/Views/DiskView.vala @@ -46,11 +46,12 @@ public class Installer.DiskView : OptionsView { unowned Distinst.InstallOptions options = install_options.get_updated_options (); foreach (unowned Distinst.EraseOption disk in options.get_erase_options ()) { + uint64 sector_size = disk.get_sector_size (); string logo = Utils.string_from_utf8 (disk.get_linux_icon ()); string label = Utils.string_from_utf8 (disk.get_model ()); string details = "%s %.1f GiB".printf ( Utils.string_from_utf8 (disk.get_device_path ()), - (double) disk.get_sectors () / SECTORS_AS_GIB + (double) disk.get_sectors () / (double) Utils.normalize_sectors(SECTORS_AS_GIB, sector_size) ); // Ensure that the user cannot select a disk that is too large for BIOS installs. diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index 4a51f78f5..45443fee4 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -315,7 +315,7 @@ public class Installer.PartitioningView : AbstractInstallerView { throw new GLib.IOError.FAILED (_("EFI partition is not on a GPT disk")); } else 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 < Utils.normalize_sectors(REQUIRED_EFI_SECTORS, mount.sector_size)) { error = _("EFI partition is too small"); } } else if (mount.mount_point == "/" && !mount.is_valid_root_mount ()) { diff --git a/src/Widgets/PartitionBar.vala b/src/Widgets/PartitionBar.vala index c27f28c16..7f71449b0 100644 --- a/src/Widgets/PartitionBar.vala +++ b/src/Widgets/PartitionBar.vala @@ -23,6 +23,7 @@ public class Installer.PartitionBar : Gtk.EventBox { public uint64 start; public uint64 end; + public uint64 sector_size; public uint64 used; public new string path; public string? vg; @@ -38,6 +39,7 @@ public class Installer.PartitionBar : Gtk.EventBox { DecryptFn decrypt) { start = part->get_start_sector (); end = part->get_end_sector (); + this.sector_size = sector_size; var usage = part->sectors_used (sector_size); if (usage.tag == 1) { diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index 974947183..e2abb6a26 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -280,6 +280,7 @@ public class Installer.PartitionMenu : Gtk.Popover { parent_disk, mount, partition_bar.end - partition_bar.start, + partition_bar.sector_size, (format_partition.active ? Mount.Flags.FORMAT : 0) + (is_lvm ? Mount.Flags.LVM : 0), filesystem, From 1988db3f34a602f95f1e3517bade4b47d0ab0d36 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 24 Apr 2019 10:57:54 -0600 Subject: [PATCH 2/2] :ambulance: Fix partition sizes in the custom partitioning view --- src/Views/DiskView.vala | 7 +++++-- src/Views/PartitioningView.vala | 4 ++-- src/Widgets/DiskBar.vala | 11 +++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Views/DiskView.vala b/src/Views/DiskView.vala index 5cf3e2457..b9886dd4e 100644 --- a/src/Views/DiskView.vala +++ b/src/Views/DiskView.vala @@ -46,18 +46,21 @@ public class Installer.DiskView : OptionsView { unowned Distinst.InstallOptions options = install_options.get_updated_options (); foreach (unowned Distinst.EraseOption disk in options.get_erase_options ()) { + uint64 sectors = disk.get_sectors (); uint64 sector_size = disk.get_sector_size (); + string logo = Utils.string_from_utf8 (disk.get_linux_icon ()); string label = Utils.string_from_utf8 (disk.get_model ()); + string details = "%s %.1f GiB".printf ( Utils.string_from_utf8 (disk.get_device_path ()), - (double) disk.get_sectors () / (double) Utils.normalize_sectors(SECTORS_AS_GIB, sector_size) + (double) sectors / (double) Utils.normalize_sectors (SECTORS_AS_GIB, sector_size) ); // Ensure that the user cannot select a disk that is too large for BIOS installs. bool msdos_too_large = Distinst.bootloader_detect () == Distinst.PartitionTable.MSDOS - && disk.get_sectors () > MSDOS_MAX_SECTORS; + && sectors > MSDOS_MAX_SECTORS; base.add_option(logo, label, details, (button) => { if (disk.meets_requirements () && !msdos_too_large) { diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index 45443fee4..4300206af 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -192,7 +192,7 @@ public class Installer.PartitioningView : AbstractInstallerView { partitions.add (partition); } - var disk_bar = new DiskBar (model, path, size, (owned) partitions); + var disk_bar = new DiskBar (model, path, size, sector_size, (owned) partitions); label_sizer.add_widget (disk_bar.label); disk_list.pack_start (disk_bar); } @@ -248,7 +248,7 @@ public class Installer.PartitioningView : AbstractInstallerView { } } - var disk_bar = new DiskBar (model, path, size, (owned) partitions); + var disk_bar = new DiskBar (model, path, size, sector_size, (owned) partitions); label_sizer.add_widget (disk_bar.label); disk_list.pack_start (disk_bar); } diff --git a/src/Widgets/DiskBar.vala b/src/Widgets/DiskBar.vala index a4591778a..b6852f9fc 100644 --- a/src/Widgets/DiskBar.vala +++ b/src/Widgets/DiskBar.vala @@ -22,6 +22,7 @@ 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; } public Gtk.Box label; @@ -34,13 +35,15 @@ public class Installer.DiskBar: Gtk.Grid { string model, string path, uint64 size, + uint64 sector_size, Gee.ArrayList partitions ) { Object ( disk_name: model, disk_path: path, partitions: partitions, - size: size + size: size, + sector_size: sector_size ); } @@ -66,7 +69,7 @@ public class Installer.DiskBar: Gtk.Grid { used += partition.get_size (); } - return size - (used * 512); + return size - (used * sector_size); } private void generate_legend () { @@ -79,7 +82,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); } if (size / 100 < unused) { @@ -165,7 +168,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++) {