Skip to content

Commit 5f45112

Browse files
Add trim command
1 parent 9d6357d commit 5f45112

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,37 @@ fn main() {
373373
Ok(())
374374
}
375375

376+
fn trim(&mut self, offset: u64, len: u32) -> std::io::Result<()> {
377+
if self.arguments.print_operations {
378+
println!("trim(offset={offset} len={len})");
379+
}
380+
381+
let zeros = vec![0; len as usize];
382+
match self.overlay_file.write_at(&zeros, offset) {
383+
Ok(_) => (),
384+
Err(error) => {
385+
eprintln!(
386+
"failed to write {len} zeros to overlay file at offset {offset}: {error}"
387+
);
388+
if !self.arguments.ignore_errors {
389+
return Err(error);
390+
}
391+
}
392+
};
393+
match self.mask_file.write_at(&zeros, offset) {
394+
Ok(_) => (),
395+
Err(error) => {
396+
eprintln!(
397+
"failed to write {len} zeros to mask file at offset {offset}: {error}"
398+
);
399+
if !self.arguments.ignore_errors {
400+
return Err(error);
401+
}
402+
}
403+
};
404+
Ok(())
405+
}
406+
376407
fn unmount(&mut self) {
377408
if self.arguments.print_operations {
378409
println!("unmount()")

0 commit comments

Comments
 (0)