mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
cmd_debug: Use iter().find()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
99406d7d42
commit
72ff5146ec
@ -18,13 +18,7 @@ impl BkeyTypes {
|
|||||||
/// Given a struct name and a member name, return the size and offset of
|
/// Given a struct name and a member name, return the size and offset of
|
||||||
/// the member within the struct, or None if it does not exist.
|
/// the member within the struct, or None if it does not exist.
|
||||||
pub fn get_member_layout(&self, outer: &str, member: &str) -> Option<(u64, u64)> {
|
pub fn get_member_layout(&self, outer: &str, member: &str) -> Option<(u64, u64)> {
|
||||||
for bkey_type in self.0.iter() {
|
self.0.iter().find(|i| i.name == *outer).map(|i| i.member_layout(member)).flatten()
|
||||||
if bkey_type.name == *outer {
|
|
||||||
return bkey_type.member_layout(member);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,12 +46,7 @@ pub struct BchStruct {
|
|||||||
|
|
||||||
impl BchStruct {
|
impl BchStruct {
|
||||||
pub fn member_layout(&self, name: &str) -> Option<(u64, u64)> {
|
pub fn member_layout(&self, name: &str) -> Option<(u64, u64)> {
|
||||||
for memb in self.members.iter() {
|
self.members.iter().find(|i| i.name == *name).map(|i| (i.size, i.offset))
|
||||||
if memb.name == *name {
|
|
||||||
return Some((memb.size, memb.offset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use crate::key;
|
|||||||
use crate::key::UnlockPolicy;
|
use crate::key::UnlockPolicy;
|
||||||
use std::ffi::{CString, c_char, c_void};
|
use std::ffi::{CString, c_char, c_void};
|
||||||
|
|
||||||
fn mount_inner(
|
fn ffi_mount(
|
||||||
src: String,
|
src: String,
|
||||||
target: impl AsRef<std::path::Path>,
|
target: impl AsRef<std::path::Path>,
|
||||||
fstype: &str,
|
fstype: &str,
|
||||||
@ -86,20 +86,6 @@ fn parse_mount_options(options: impl AsRef<str>) -> (Option<String>, libc::c_ulo
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_mount(
|
|
||||||
device: String,
|
|
||||||
target: impl AsRef<std::path::Path>,
|
|
||||||
options: impl AsRef<str>,
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
let (data, mountflags) = parse_mount_options(options);
|
|
||||||
|
|
||||||
info!(
|
|
||||||
"mounting bcachefs filesystem, {}",
|
|
||||||
target.as_ref().display()
|
|
||||||
);
|
|
||||||
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: &std::path::PathBuf) -> 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);
|
||||||
@ -221,12 +207,11 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
|
|||||||
} else if opt.dev.starts_with("OLD_BLKID_UUID=") {
|
} else if opt.dev.starts_with("OLD_BLKID_UUID=") {
|
||||||
let uuid = opt.dev.replacen("OLD_BLKID_UUID=", "", 1);
|
let uuid = opt.dev.replacen("OLD_BLKID_UUID=", "", 1);
|
||||||
devs_str_sbs_from_uuid(uuid)?
|
devs_str_sbs_from_uuid(uuid)?
|
||||||
} else {
|
} else if opt.dev.contains(":") {
|
||||||
// If the device string contains ":" we will assume the user knows the entire list.
|
// If the device string contains ":" we will assume the user knows the entire list.
|
||||||
// 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(":") {
|
|
||||||
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(':') {
|
||||||
@ -237,12 +222,12 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
|
|||||||
(opt.dev, block_devices_to_mount)
|
(opt.dev, block_devices_to_mount)
|
||||||
} else {
|
} else {
|
||||||
devs_str_sbs_from_device(&PathBuf::from(opt.dev))?
|
devs_str_sbs_from_device(&PathBuf::from(opt.dev))?
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if block_devices_to_mount.len() == 0 {
|
if block_devices_to_mount.len() == 0 {
|
||||||
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
|
||||||
if unsafe { bcachefs::bch2_sb_is_encrypted_and_locked(block_devices_to_mount[0].sb) } {
|
if unsafe { bcachefs::bch2_sb_is_encrypted_and_locked(block_devices_to_mount[0].sb) } {
|
||||||
// First by password_file, if available
|
// First by password_file, if available
|
||||||
@ -276,17 +261,19 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
|
|||||||
&opt.options
|
&opt.options
|
||||||
);
|
);
|
||||||
|
|
||||||
do_mount(devices, mountpoint, &opt.options)?;
|
let (data, mountflags) = parse_mount_options(&opt.options);
|
||||||
|
|
||||||
|
ffi_mount(devices, mountpoint, "bcachefs", mountflags, data)
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
"would mount with params: device: {}, options: {}",
|
"would mount with params: device: {}, options: {}",
|
||||||
devices,
|
devices,
|
||||||
&opt.options
|
&opt.options
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mount(mut argv: Vec<String>, symlink_cmd: Option<&str>) -> i32 {
|
pub fn mount(mut argv: Vec<String>, symlink_cmd: Option<&str>) -> i32 {
|
||||||
// If the bcachefs tool is being called as "bcachefs mount dev ..." (as opposed to via a
|
// If the bcachefs tool is being called as "bcachefs mount dev ..." (as opposed to via a
|
||||||
|
Loading…
Reference in New Issue
Block a user