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

fix(DiskBar): simplify and prevent invalid constraints #862

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
180 changes: 161 additions & 19 deletions src/Views/PartitioningView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -339,44 +339,186 @@ 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 usage_2 = InstallerDaemon.PartitionUsage () {
tag = 0,
value = 0
};

partitions += InstallerDaemon.Partition () {
device_path = "/dev/nvme0n1p2",
var partitions_4 = InstallerDaemon.Partition () {
device_path = "/dev/sdc2",
filesystem = InstallerDaemon.FileSystem.LVM,
start_sector = 542968,
end_sector = 976769070,
sectors_used = usage_2,
end_sector = 1562820270,
sectors_used = InstallerDaemon.PartitionUsage () {
tag = 0,
value = 0
},
current_lvm_volume_group = "data"
};

physical_disks += InstallerDaemon.Disk () {
name = "Samsung SSD 970 EVO 500GB",
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 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 = 976773168,
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
partitions = {partitions_9, partitions_10}
};

return InstallerDaemon.DiskInfo () {
Expand Down
49 changes: 24 additions & 25 deletions src/Widgets/DiskBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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);
}

Expand All @@ -67,14 +66,14 @@ public class Installer.DiskBar: Gtk.Box {

private class PartitionContainer : Gtk.Widget {
public Gee.ArrayList<PartitionBlock> 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<PartitionBlock> partitions) {
public PartitionContainer (uint64 total_disk_sectors, Gee.ArrayList<PartitionBlock> partitions) {
Object (
partitions: partitions,
size: size
total_disk_sectors: total_disk_sectors,
partitions: partitions
);
}

Expand Down Expand Up @@ -105,26 +104,25 @@ 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,
percent_requested
);
}

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
Expand Down Expand Up @@ -220,16 +218,17 @@ 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,
davidmhewitt marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/PartitionBlock.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Widgets/PartitionMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading