Skip to content

Commit 6397127

Browse files
committed
partitions: fix obtaining last partition by offset
We need to ignore NVRAM partitions here, since they have an offset of 0xffff_ffff. Add a debug print. Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 4b8f0cb commit 6397127

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/part/partitions.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use zerocopy::IntoBytes;
55

66
use crate::EMPTY;
77
use crate::dir::gen3::CPD_MAGIC_BYTES;
8+
use crate::part::fpt::PartitionKind;
89
use crate::part::part::ClearOptions;
910
use crate::part::{
1011
fpt::{FPT, FPTEntry},
@@ -184,6 +185,7 @@ impl Partitions {
184185
}
185186

186187
pub fn to_vec(&self) -> Vec<u8> {
188+
use log::debug;
187189
fn copy_parts(parts: &Vec<&dyn Partition>, data: &mut Vec<u8>) {
188190
for p in parts {
189191
let offset = p.entry().offset();
@@ -202,8 +204,20 @@ impl Partitions {
202204
let sorted_parts = &self.get_sorted();
203205

204206
// This gets us the smallest possible slice to copy into.
205-
let last = &sorted_parts.into_iter().last().unwrap().entry();
206-
let size = last.offset() + last.size();
207+
// NOTE: We need to filter out NVRAM partitions, which have an offset of
208+
// 0xffff_ffff.
209+
let last = &sorted_parts
210+
.into_iter()
211+
.filter(|p| {
212+
let f = p.entry().flags;
213+
f.kind() != PartitionKind::NVRAM
214+
})
215+
.last()
216+
.unwrap()
217+
.entry();
218+
let o = last.offset();
219+
let size = o + last.size();
220+
debug!("Last partition @ {o:08x}; final size: {size:08x}");
207221
let mut data = vec![EMPTY; size];
208222

209223
match sorted_parts {

0 commit comments

Comments
 (0)