diff --git a/src/bin/thin_shrink.rs b/src/bin/thin_shrink.rs index ffb29ad..26b70a4 100644 --- a/src/bin/thin_shrink.rs +++ b/src/bin/thin_shrink.rs @@ -25,7 +25,14 @@ fn main() { .value_name("OUTPUT") .takes_value(true), ) - // FIXME: support various disk units + .arg( + Arg::with_name("DATA") + .help("Specify pool data device where data will be moved") + .required(true) + .long("data") + .value_name("DATA") + .takes_value(true), + ) .arg( Arg::with_name("SIZE") .help("Specify new size for the pool (in data blocks)") @@ -41,13 +48,14 @@ fn main() { let input_file = matches.value_of("INPUT").unwrap(); let output_file = matches.value_of("OUTPUT").unwrap(); let size = matches.value_of("SIZE").unwrap().parse::().unwrap(); + let data_file = matches.value_of("DATA").unwrap(); if !file_utils::file_exists(input_file) { eprintln!("Couldn't find input file '{}'.", &input_file); exit(1); } - if let Err(reason) = thinp::shrink::toplevel::shrink(&input_file, &output_file, size) { + if let Err(reason) = thinp::shrink::toplevel::shrink(&input_file, &output_file, &data_file, size) { println!("Application error: {}\n", reason); exit(1); } diff --git a/src/shrink/copier.rs b/src/shrink/copier.rs new file mode 100644 index 0000000..3df0042 --- /dev/null +++ b/src/shrink/copier.rs @@ -0,0 +1,14 @@ +use anyhow::Result; + +pub type Sector = u64; + +pub struct Region { + src: Sector, + dest: Sector, + len: Sector, +} + +// FIXME: pass in +pub fn copy(path: &str, regions: &Vec) -> Result<()> { + Ok(()) +} diff --git a/src/shrink/mod.rs b/src/shrink/mod.rs index a2c8345..56f9dd5 100644 --- a/src/shrink/mod.rs +++ b/src/shrink/mod.rs @@ -1,3 +1,4 @@ pub mod toplevel; +mod copier; mod xml; diff --git a/src/shrink/toplevel.rs b/src/shrink/toplevel.rs index 394f9d3..a0f4007 100644 --- a/src/shrink/toplevel.rs +++ b/src/shrink/toplevel.rs @@ -5,6 +5,7 @@ use std::io::Write; use std::os::unix::fs::OpenOptionsExt; use crate::shrink::xml; +use crate::shrink::copier::{self, Region}; //--------------------------------------- @@ -268,7 +269,7 @@ fn overlaps(r1: &BlockRange, r2: &BlockRange, index: usize) -> Option { // Finds the index of the first entry that overlaps r. fn find_first(r: &BlockRange, remaps: &Vec<(BlockRange, BlockRange)>) -> Option { if remaps.len() == 0 { - return None + return None; } match remaps.binary_search_by_key(&r.start, |(from, _)| from.start) { @@ -319,9 +320,9 @@ fn remap(r: &BlockRange, remaps: &Vec<(BlockRange, BlockRange)>) -> Vec) -> Vec { + let rs = Vec::new(); + rs +} + fn process_xml(input_path: &str, pass: &mut MV) -> Result<()> { let input = OpenOptions::new() .read(true) @@ -428,7 +434,7 @@ fn process_xml(input_path: &str, pass: &mut MV) -> Res Ok(()) } -pub fn shrink(input_path: &str, output_path: &str, nr_blocks: u64) -> Result<()> { +pub fn shrink(input_path: &str, output_path: &str, data_path: &str, nr_blocks: u64) -> Result<()> { let mut pass1 = Pass1::new(nr_blocks); process_xml(input_path, &mut pass1); eprintln!("{} blocks need moving", pass1.nr_high_blocks); @@ -465,6 +471,11 @@ pub fn shrink(input_path: &str, output_path: &str, nr_blocks: u64) -> Result<()> let remaps = build_remaps(above, free); eprintln!("remappings {:?}.", remaps); + let regions = build_copy_regions(&remaps); + eprint!("Copying data..."); + copier::copy(data_path, ®ions); + eprintln!("done."); + let output = OpenOptions::new() .read(false) .write(true)