mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
Merge pull request #271 from tmuehlbacher/cargo-clippy
Fix clippy lints
This commit is contained in:
commit
7d795ddb25
@ -4,7 +4,7 @@ use std::collections::HashMap;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use std::io::{stdout, IsTerminal};
|
use std::io::{stdout, IsTerminal};
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::{fs, str, env};
|
use std::{fs, str, env};
|
||||||
use crate::key;
|
use crate::key;
|
||||||
use crate::key::UnlockPolicy;
|
use crate::key::UnlockPolicy;
|
||||||
@ -50,7 +50,7 @@ fn parse_mount_options(options: impl AsRef<str>) -> (Option<String>, libc::c_ulo
|
|||||||
debug!("parsing mount options: {}", options.as_ref());
|
debug!("parsing mount options: {}", options.as_ref());
|
||||||
let (opts, flags) = options
|
let (opts, flags) = options
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.split(",")
|
.split(',')
|
||||||
.map(|o| match o {
|
.map(|o| match o {
|
||||||
"dirsync" => Left(libc::MS_DIRSYNC),
|
"dirsync" => Left(libc::MS_DIRSYNC),
|
||||||
"lazytime" => Left(1 << 25), // MS_LAZYTIME
|
"lazytime" => Left(1 << 25), // MS_LAZYTIME
|
||||||
@ -67,7 +67,7 @@ fn parse_mount_options(options: impl AsRef<str>) -> (Option<String>, libc::c_ulo
|
|||||||
"strictatime" => Left(libc::MS_STRICTATIME),
|
"strictatime" => Left(libc::MS_STRICTATIME),
|
||||||
"sync" => Left(libc::MS_SYNCHRONOUS),
|
"sync" => Left(libc::MS_SYNCHRONOUS),
|
||||||
"" => Left(0),
|
"" => Left(0),
|
||||||
o @ _ => Right(o),
|
o => Right(o),
|
||||||
})
|
})
|
||||||
.fold((Vec::new(), 0), |(mut opts, flags), next| match next {
|
.fold((Vec::new(), 0), |(mut opts, flags), next| match next {
|
||||||
Left(f) => (opts, flags | f),
|
Left(f) => (opts, flags | f),
|
||||||
@ -78,7 +78,7 @@ fn parse_mount_options(options: impl AsRef<str>) -> (Option<String>, libc::c_ulo
|
|||||||
});
|
});
|
||||||
|
|
||||||
(
|
(
|
||||||
if opts.len() == 0 {
|
if opts.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(opts.join(","))
|
Some(opts.join(","))
|
||||||
@ -101,11 +101,11 @@ fn do_mount(
|
|||||||
mount_inner(device, target, "bcachefs", mountflags, data)
|
mount_inner(device, target, "bcachefs", mountflags, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_super_silent(path: &std::path::PathBuf) -> anyhow::Result<bch_sb_handle> {
|
fn read_super_silent(path: impl AsRef<Path>) -> anyhow::Result<bch_sb_handle> {
|
||||||
let mut opts = bcachefs::bch_opts::default();
|
let mut opts = bcachefs::bch_opts::default();
|
||||||
opt_set!(opts, noexcl, 1);
|
opt_set!(opts, noexcl, 1);
|
||||||
|
|
||||||
bch_bindgen::sb_io::read_super_silent(&path, opts)
|
bch_bindgen::sb_io::read_super_silent(path.as_ref(), opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn device_property_map(dev: &udev::Device) -> HashMap<String, String> {
|
fn device_property_map(dev: &udev::Device) -> HashMap<String, String> {
|
||||||
@ -158,7 +158,7 @@ fn get_super_blocks(
|
|||||||
Ok(devices
|
Ok(devices
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|dev| {
|
.filter_map(|dev| {
|
||||||
read_super_silent(&PathBuf::from(dev))
|
read_super_silent(PathBuf::from(dev))
|
||||||
.ok()
|
.ok()
|
||||||
.map(|sb| (PathBuf::from(dev), sb))
|
.map(|sb| (PathBuf::from(dev), sb))
|
||||||
})
|
})
|
||||||
@ -203,6 +203,7 @@ fn get_devices_by_uuid(
|
|||||||
get_super_blocks(uuid, &devices)
|
get_super_blocks(uuid, &devices)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
fn get_uuid_for_dev_node(
|
fn get_uuid_for_dev_node(
|
||||||
udev_bcachefs: &HashMap<String, Vec<String>>,
|
udev_bcachefs: &HashMap<String, Vec<String>>,
|
||||||
device: &std::path::PathBuf,
|
device: &std::path::PathBuf,
|
||||||
@ -327,7 +328,7 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
|
|||||||
// If they supply a single device it could be either the FS only has 1 device or it's
|
// If they supply a single device it could be either the FS only has 1 device or it's
|
||||||
// only 1 of a number of devices which are part of the FS. This appears to be the case
|
// only 1 of a number of devices which are part of the FS. This appears to be the case
|
||||||
// when we get called during fstab mount processing and the fstab specifies a UUID.
|
// when we get called during fstab mount processing and the fstab specifies a UUID.
|
||||||
if opt.dev.contains(":") {
|
if opt.dev.contains(':') {
|
||||||
let mut block_devices_to_mount = Vec::new();
|
let mut block_devices_to_mount = Vec::new();
|
||||||
|
|
||||||
for dev in opt.dev.split(':') {
|
for dev in opt.dev.split(':') {
|
||||||
@ -341,7 +342,7 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if block_devices_to_mount.len() == 0 {
|
if block_devices_to_mount.is_empty() {
|
||||||
Err(anyhow::anyhow!("No device found from specified parameters"))?;
|
Err(anyhow::anyhow!("No device found from specified parameters"))?;
|
||||||
}
|
}
|
||||||
// Check if the filesystem's master key is encrypted
|
// Check if the filesystem's master key is encrypted
|
||||||
|
@ -98,7 +98,7 @@ fn ask_for_passphrase(sb: &bch_sb_handle) -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const BCH_KEY_MAGIC: &str = "bch**key";
|
const BCH_KEY_MAGIC: &str = "bch**key";
|
||||||
fn unlock_master_key(sb: &bch_sb_handle, passphrase: &String) -> anyhow::Result<()> {
|
fn unlock_master_key(sb: &bch_sb_handle, passphrase: &str) -> anyhow::Result<()> {
|
||||||
use bch_bindgen::bcachefs::{self, bch2_chacha_encrypt_key, bch_encrypted_key, bch_key};
|
use bch_bindgen::bcachefs::{self, bch2_chacha_encrypt_key, bch_encrypted_key, bch_key};
|
||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt};
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
@ -118,13 +118,13 @@ fn unlock_master_key(sb: &bch_sb_handle, passphrase: &String) -> anyhow::Result<
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut key = crypt.key().clone();
|
let mut key = *crypt.key();
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
bch2_chacha_encrypt_key(
|
bch2_chacha_encrypt_key(
|
||||||
&mut output as *mut _,
|
&mut output as *mut _,
|
||||||
sb.sb().nonce(),
|
sb.sb().nonce(),
|
||||||
&mut key as *mut _ as *mut _,
|
&mut key as *mut _ as *mut _,
|
||||||
std::mem::size_of::<bch_encrypted_key>() as usize,
|
std::mem::size_of::<bch_encrypted_key>(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
@ -138,7 +138,7 @@ fn unlock_master_key(sb: &bch_sb_handle, passphrase: &String) -> anyhow::Result<
|
|||||||
key_type,
|
key_type,
|
||||||
key_name.as_c_str().to_bytes_with_nul() as *const _ as *const c_char,
|
key_name.as_c_str().to_bytes_with_nul() as *const _ as *const c_char,
|
||||||
&output as *const _ as *const _,
|
&output as *const _ as *const _,
|
||||||
std::mem::size_of::<bch_key>() as usize,
|
std::mem::size_of::<bch_key>(),
|
||||||
bch_bindgen::keyutils::KEY_SPEC_USER_KEYRING,
|
bch_bindgen::keyutils::KEY_SPEC_USER_KEYRING,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user