Skip to content

Commit 671e62f

Browse files
committed
🚑 Support sector sizes that are not 512 bytes
1 parent 30c228f commit 671e62f

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

src/Objects/Mount.vala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Installer.Mount {
2323
public string parent_disk;
2424
public string mount_point;
2525
public uint64 sectors;
26+
public uint64 sector_size;
2627
public Distinst.FileSystem filesystem;
2728
public Flags flags;
2829
public PartitionMenu menu;
@@ -35,15 +36,16 @@ public class Installer.Mount {
3536
}
3637

3738
public Mount (string partition, string parent_disk, string mount,
38-
uint64 sectors, Flags flags, Distinst.FileSystem fs,
39-
PartitionMenu menu) {
39+
uint64 sectors, uint64 sector_size, Flags flags,
40+
Distinst.FileSystem fs, PartitionMenu menu) {
4041
filesystem = fs;
4142
mount_point = mount;
4243
partition_path = partition;
4344
this.flags = flags;
4445
this.menu = menu;
4546
this.parent_disk = parent_disk;
4647
this.sectors = sectors;
48+
this.sector_size = sector_size;
4749
}
4850

4951
public bool is_valid_boot_mount () {

src/Utils.vala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
* Authored by: Corentin Noël <[email protected]>
1919
*/
2020

21-
const double SECTORS_AS_GIB = 2 * 1024 * 1024;
21+
const uint64 SECTORS_AS_GIB = 2 * 1024 * 1024;
2222

2323
namespace Utils {
24+
public uint64 normalize_sectors (uint64 base_count, uint64 sector_size) {
25+
return base_count / (sector_size / 512);
26+
}
27+
2428
public string string_from_utf8 (uint8[] input) {
2529
var builder = new GLib.StringBuilder.sized (input.length);
2630
builder.append_len ((string) input, input.length);

src/Views/DiskView.vala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ public class Installer.DiskView : OptionsView {
4646
unowned Distinst.InstallOptions options = install_options.get_updated_options ();
4747

4848
foreach (unowned Distinst.EraseOption disk in options.get_erase_options ()) {
49+
uint64 sector_size = disk.get_sector_size ();
4950
string logo = Utils.string_from_utf8 (disk.get_linux_icon ());
5051
string label = Utils.string_from_utf8 (disk.get_model ());
5152
string details = "%s %.1f GiB".printf (
5253
Utils.string_from_utf8 (disk.get_device_path ()),
53-
(double) disk.get_sectors () / SECTORS_AS_GIB
54+
(double) disk.get_sectors () / (double) Utils.normalize_sectors(SECTORS_AS_GIB, sector_size)
5455
);
5556

5657
// Ensure that the user cannot select a disk that is too large for BIOS installs.

src/Views/PartitioningView.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public class Installer.PartitioningView : AbstractInstallerView {
315315
throw new GLib.IOError.FAILED (_("EFI partition is not on a GPT disk"));
316316
} else if (!mount.is_valid_boot_mount ()) {
317317
throw new GLib.IOError.FAILED (_("EFI partition has the wrong file system"));
318-
} else if (mount.sectors < REQUIRED_EFI_SECTORS) {
318+
} else if (mount.sectors < Utils.normalize_sectors(REQUIRED_EFI_SECTORS, mount.sector_size)) {
319319
error = _("EFI partition is too small");
320320
}
321321
} else if (mount.mount_point == "/" && !mount.is_valid_root_mount ()) {

src/Widgets/PartitionBar.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Installer.PartitionBar : Gtk.EventBox {
2323

2424
public uint64 start;
2525
public uint64 end;
26+
public uint64 sector_size;
2627
public uint64 used;
2728
public new string path;
2829
public string? vg;
@@ -38,6 +39,7 @@ public class Installer.PartitionBar : Gtk.EventBox {
3839
DecryptFn decrypt) {
3940
start = part->get_start_sector ();
4041
end = part->get_end_sector ();
42+
this.sector_size = sector_size;
4143

4244
var usage = part->sectors_used (sector_size);
4345
if (usage.tag == 1) {

src/Widgets/PartitionMenu.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ public class Installer.PartitionMenu : Gtk.Popover {
280280
parent_disk,
281281
mount,
282282
partition_bar.end - partition_bar.start,
283+
partition_bar.sector_size,
283284
(format_partition.active ? Mount.Flags.FORMAT : 0)
284285
+ (is_lvm ? Mount.Flags.LVM : 0),
285286
filesystem,

0 commit comments

Comments
 (0)