diff --git a/src/bcachefs.rs b/src/bcachefs.rs index d201acfd..c188aae6 100644 --- a/src/bcachefs.rs +++ b/src/bcachefs.rs @@ -63,7 +63,7 @@ fn handle_c_command(mut argv: Vec, symlink_cmd: Option<&str>) -> i32 { "fusemount" => c::cmd_fusemount(argc, argv), _ => { - println!("Unknown command {}", cmd); + println!("Unknown command {cmd}"); c::bcachefs_usage(); 1 } diff --git a/src/commands/list.rs b/src/commands/list.rs index 082c9dc4..77f53b4f 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -10,7 +10,7 @@ use clap::Parser; use log::error; use std::io::{stdout, IsTerminal}; -fn list_keys(fs: &Fs, opt: Cli) -> anyhow::Result<()> { +fn list_keys(fs: &Fs, opt: &Cli) -> anyhow::Result<()> { let trans = BtreeTrans::new(fs); let mut iter = BtreeIter::new( &trans, @@ -38,7 +38,7 @@ fn list_keys(fs: &Fs, opt: Cli) -> anyhow::Result<()> { Ok(()) } -fn list_btree_formats(fs: &Fs, opt: Cli) -> anyhow::Result<()> { +fn list_btree_formats(fs: &Fs, opt: &Cli) -> anyhow::Result<()> { let trans = BtreeTrans::new(fs); let mut iter = BtreeNodeIter::new( &trans, @@ -61,7 +61,7 @@ fn list_btree_formats(fs: &Fs, opt: Cli) -> anyhow::Result<()> { Ok(()) } -fn list_btree_nodes(fs: &Fs, opt: Cli) -> anyhow::Result<()> { +fn list_btree_nodes(fs: &Fs, opt: &Cli) -> anyhow::Result<()> { let trans = BtreeTrans::new(fs); let mut iter = BtreeNodeIter::new( &trans, @@ -84,7 +84,7 @@ fn list_btree_nodes(fs: &Fs, opt: Cli) -> anyhow::Result<()> { Ok(()) } -fn list_nodes_ondisk(fs: &Fs, opt: Cli) -> anyhow::Result<()> { +fn list_nodes_ondisk(fs: &Fs, opt: &Cli) -> anyhow::Result<()> { let trans = BtreeTrans::new(fs); let mut iter = BtreeNodeIter::new( &trans, @@ -157,8 +157,8 @@ pub struct Cli { devices: Vec, } -fn cmd_list_inner(opt: Cli) -> anyhow::Result<()> { - let mut fs_opts: bcachefs::bch_opts = Default::default(); +fn cmd_list_inner(opt: &Cli) -> anyhow::Result<()> { + let mut fs_opts = bcachefs::bch_opts::default(); opt_set!(fs_opts, nochanges, 1); opt_set!(fs_opts, read_only, 1); @@ -197,7 +197,7 @@ fn cmd_list_inner(opt: Cli) -> anyhow::Result<()> { pub fn list(argv: Vec) -> i32 { let opt = Cli::parse_from(argv); colored::control::set_override(opt.colorize); - if let Err(e) = cmd_list_inner(opt) { + if let Err(e) = cmd_list_inner(&opt) { error!("Fatal error: {}", e); 1 } else { diff --git a/src/commands/mount.rs b/src/commands/mount.rs index 622f6cb9..4757bbff 100644 --- a/src/commands/mount.rs +++ b/src/commands/mount.rs @@ -49,7 +49,8 @@ fn mount_inner( /// Parse a comma-separated mount options and split out mountflags and filesystem /// specific options. fn parse_mount_options(options: impl AsRef) -> (Option, libc::c_ulong) { - use either::Either::*; + use either::Either::{Left, Right}; + debug!("parsing mount options: {}", options.as_ref()); let (opts, flags) = options .as_ref() @@ -66,10 +67,9 @@ fn parse_mount_options(options: impl AsRef) -> (Option, libc::c_ulo "relatime" => Left(libc::MS_RELATIME), "remount" => Left(libc::MS_REMOUNT), "ro" => Left(libc::MS_RDONLY), - "rw" => Left(0), + "rw" | "" => Left(0), "strictatime" => Left(libc::MS_STRICTATIME), "sync" => Left(libc::MS_SYNCHRONOUS), - "" => Left(0), o => Right(o), }) .fold((Vec::new(), 0), |(mut opts, flags), next| match next { @@ -127,7 +127,7 @@ fn udev_bcachefs_info() -> anyhow::Result>> { for m in udev .scan_devices()? - .filter(|dev| dev.is_initialized()) + .filter(udev::Device::is_initialized) .map(|dev| device_property_map(&dev)) .filter(|m| m.contains_key("ID_FS_UUID") && m.contains_key("DEVNAME")) { @@ -140,11 +140,8 @@ fn udev_bcachefs_info() -> anyhow::Result>> { Ok(info) } -fn get_super_blocks( - uuid: Uuid, - devices: &[String], -) -> anyhow::Result> { - Ok(devices +fn get_super_blocks(uuid: Uuid, devices: &[String]) -> Vec<(PathBuf, bch_sb_handle)> { + devices .iter() .filter_map(|dev| { read_super_silent(PathBuf::from(dev)) @@ -152,7 +149,7 @@ fn get_super_blocks( .map(|sb| (PathBuf::from(dev), sb)) }) .filter(|(_, sb)| sb.sb().uuid() == uuid) - .collect::>()) + .collect::>() } fn get_all_block_devnodes() -> anyhow::Result> { @@ -189,7 +186,7 @@ fn get_devices_by_uuid( } }; - get_super_blocks(uuid, &devices) + Ok(get_super_blocks(uuid, &devices)) } #[allow(clippy::type_complexity)] diff --git a/src/commands/subvolume.rs b/src/commands/subvolume.rs index 0691e34d..a5ebcf53 100644 --- a/src/commands/subvolume.rs +++ b/src/commands/subvolume.rs @@ -37,9 +37,9 @@ enum Subcommands { } pub fn subvolume(argv: Vec) -> i32 { - let args = Cli::parse_from(argv); + let cli = Cli::parse_from(argv); - match args.subcommands { + match cli.subcommands { Subcommands::Create { targets } => { for target in targets { if let Some(dirname) = target.parent() {