Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sector sizes that are not 512 bytes #186

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Objects/Mount.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,15 +36,16 @@ 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;
this.flags = flags;
this.menu = menu;
this.parent_disk = parent_disk;
this.sectors = sectors;
this.sector_size = sector_size;
}

public bool is_valid_boot_mount () {
Expand Down
6 changes: 5 additions & 1 deletion src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
* Authored by: Corentin Noël <[email protected]>
*/

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);
Expand Down
8 changes: 6 additions & 2 deletions src/Views/DiskView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +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 () / SECTORS_AS_GIB
(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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Views/PartitioningView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 ()) {
Expand Down
11 changes: 7 additions & 4 deletions src/Widgets/DiskBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<PartitionBar> partitions { get; construct; }

public Gtk.Box label;
Expand All @@ -34,13 +35,15 @@ public class Installer.DiskBar: Gtk.Grid {
string model,
string path,
uint64 size,
uint64 sector_size,
Gee.ArrayList<PartitionBar> partitions
) {
Object (
disk_name: model,
disk_path: path,
partitions: partitions,
size: size
size: size,
sector_size: sector_size
);
}

Expand All @@ -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 () {
Expand All @@ -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) {
Expand Down Expand Up @@ -165,7 +168,7 @@ public class Installer.DiskBar: Gtk.Grid {

private void update_sector_lengths (Gee.ArrayList<PartitionBar> 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++) {
Expand Down
2 changes: 2 additions & 0 deletions src/Widgets/PartitionBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/Widgets/PartitionMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down