Skip to content

Commit

Permalink
fix: limit size of MBR partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Jun 10, 2024
1 parent 4357a77 commit 38428d4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/rugpi-common/src/disk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ impl PartitionTable {

/// The last usable block.
pub fn last_usable_block(&self) -> NumBlocks {
self.disk_size - GPT_TABLE_BLOCKS - NumBlocks::ONE
match self.disk_id {
DiskId::Mbr(_) => {
self.disk_size.min(NumBlocks::from_raw(u32::MAX.into()))
- GPT_TABLE_BLOCKS
- NumBlocks::ONE
}
DiskId::Gpt(_) => self.disk_size - GPT_TABLE_BLOCKS - NumBlocks::ONE,
}
}

/// Write the partition table to a device or image.
Expand Down

0 comments on commit 38428d4

Please sign in to comment.