diff --git a/src/uu/df/Cargo.toml b/src/uu/df/Cargo.toml index 601a5acec..5fc2e3502 100644 --- a/src/uu/df/Cargo.toml +++ b/src/uu/df/Cargo.toml @@ -5,7 +5,7 @@ authors = [] [lib] name = "uu_df" -path = "df.rs" +path = "src/df.rs" [dependencies] clap = "2.32.0" @@ -18,4 +18,4 @@ winapi = { version = "0.3", features = ["handleapi"] } [[bin]] name = "df" -path = "main.rs" +path = "../../common/uumain.rs" diff --git a/src/uu/df/main.rs b/src/uu/df/main.rs deleted file mode 100644 index 09d4f3790..000000000 --- a/src/uu/df/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -extern crate uu_df; - -fn main() { - std::process::exit(uu_df::uumain(std::env::args().collect())); -} diff --git a/src/uu/df/df.rs b/src/uu/df/src/df.rs similarity index 96% rename from src/uu/df/df.rs rename to src/uu/df/src/df.rs index 394a0ca46..764182e03 100644 --- a/src/uu/df/df.rs +++ b/src/uu/df/src/df.rs @@ -30,7 +30,6 @@ use kernel32::{ use std::cell::Cell; use std::collections::HashMap; use std::collections::HashSet; -use std::env; #[cfg(unix)] use std::ffi::CString; @@ -100,6 +99,7 @@ static OPT_KILO: &str = "kilo"; static OPT_LOCAL: &str = "local"; static OPT_NO_SYNC: &str = "no-sync"; static OPT_OUTPUT: &str = "output"; +static OPT_PATHS: &str = "paths"; static OPT_PORTABILITY: &str = "portability"; static OPT_SYNC: &str = "sync"; static OPT_TYPE: &str = "type"; @@ -355,11 +355,13 @@ impl MountInfo { #[cfg(target_os = "linux")] fn new(file_name: &str, raw: Vec<&str>) -> Option { match file_name { + // Format: 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue + // "man proc" for more details "/proc/self/mountinfo" => { let mut m = MountInfo { dev_id: "".to_string(), - dev_name: raw[8].to_string(), - fs_type: raw[7].to_string(), + dev_name: raw[9].to_string(), + fs_type: raw[8].to_string(), mount_root: raw[3].to_string(), mount_dir: raw[4].to_string(), mount_option: raw[5].to_string(), @@ -645,7 +647,7 @@ fn read_fs_list() -> Vec { } } -fn filter_mount_list(vmi: Vec, opt: &Options) -> Vec { +fn filter_mount_list(vmi: Vec, paths: &[String], opt: &Options) -> Vec { vmi.into_iter() .filter_map(|mi| { if (mi.remote && opt.show_local_fs) @@ -654,7 +656,17 @@ fn filter_mount_list(vmi: Vec, opt: &Options) -> Vec { { None } else { - Some((mi.dev_id.clone(), mi)) + if paths.is_empty() { + // No path specified + return Some((mi.dev_id.clone(), mi)); + } + if paths.contains(&mi.mount_dir) { + // One or more paths have been provided + Some((mi.dev_id.clone(), mi)) + } else { + // Not a path we want to see + None + } } }) .fold( @@ -849,6 +861,8 @@ pub fn uumain(args: Vec) -> i32 { .long("version") .help("output version information and exit"), ) + .arg(Arg::with_name(OPT_PATHS).multiple(true)) + .help("Filesystem(s) to list") .get_matches_from(&args); if matches.is_present(OPT_VERSION) { @@ -856,6 +870,11 @@ pub fn uumain(args: Vec) -> i32 { return EXIT_OK; } + let paths: Vec = matches + .values_of(OPT_PATHS) + .map(|v| v.map(ToString::to_string).collect()) + .unwrap_or_default(); + #[cfg(windows)] { if matches.is_present(OPT_INODES) { @@ -896,7 +915,7 @@ pub fn uumain(args: Vec) -> i32 { opt.fs_selector.exclude(fs_type.to_owned()); } - let fs_list = filter_mount_list(read_fs_list(), &opt) + let fs_list = filter_mount_list(read_fs_list(), &paths, &opt) .into_iter() .filter_map(Filesystem::new) .filter(|fs| fs.usage.blocks != 0 || opt.show_all_fs || opt.show_listed_fs) diff --git a/tests/test_df.rs b/tests/test_df.rs index e97a34b49..03903049a 100644 --- a/tests/test_df.rs +++ b/tests/test_df.rs @@ -6,4 +6,11 @@ fn test_df_compatible() { let result = ucmd.arg("-ah").run(); assert!(result.success); } + +#[test] +fn test_df_compatible_type() { + let (_, mut ucmd) = at_and_ucmd!(); + let result = ucmd.arg("-aT").run(); + assert!(result.success); +} // TODO