Skip to content

Commit 621f49b

Browse files
committed
part/partitions: add method to relocate
Signed-off-by: Daniel Maslowski <info@orangecms.org>
1 parent 1d00e4f commit 621f49b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/part/partitions.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,34 @@ impl Partitions {
125125
}
126126
}
127127

128+
pub fn relocate(&mut self, part_name: &str, offset: u32) -> Result<(), String> {
129+
*self = match self {
130+
Partitions::Gen2(parts) => {
131+
let p = parts.iter_mut().find(|p| p.entry().name() == part_name);
132+
if let Some(p) = p {
133+
if let Err(e) = p.relocate(offset) {
134+
return Err(format!("Cannot relocate partition: {e}"));
135+
}
136+
}
137+
Partitions::Gen2(parts.to_vec())
138+
}
139+
Partitions::Gen3(parts) => {
140+
let p = parts.iter_mut().find(|p| p.entry().name() == part_name);
141+
if let Some(p) = p {
142+
if let Err(e) = p.relocate(offset) {
143+
return Err(format!("Cannot relocate partition: {e}"));
144+
}
145+
}
146+
Partitions::Gen3(parts.to_vec())
147+
}
148+
Partitions::Unknown(parts) => {
149+
let parts = parts.to_vec();
150+
Partitions::Unknown(parts)
151+
}
152+
};
153+
Ok(())
154+
}
155+
128156
pub fn to_vec(&self) -> Vec<u8> {
129157
fn copy_parts(parts: &Vec<&dyn Partition>, data: &mut Vec<u8>) {
130158
for p in parts {

0 commit comments

Comments
 (0)