mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
Merge pull request #283 from tmuehlbacher/msrv-and-tweaks
Msrv and tweaks
This commit is contained in:
commit
96843fc95d
@ -345,15 +345,15 @@ fn cmd_mount_inner(opt: Cli) -> Result<()> {
|
|||||||
if unsafe { bcachefs::bch2_sb_is_encrypted(first_sb.sb) } {
|
if unsafe { bcachefs::bch2_sb_is_encrypted(first_sb.sb) } {
|
||||||
let _key_handle = KeyHandle::new_from_search(&uuid).or_else(|_| {
|
let _key_handle = KeyHandle::new_from_search(&uuid).or_else(|_| {
|
||||||
opt.passphrase_file
|
opt.passphrase_file
|
||||||
.map(|path| {
|
.and_then(|path| match Passphrase::new_from_file(&first_sb, path) {
|
||||||
Passphrase::new_from_file(&first_sb, path)
|
Ok(p) => Some(KeyHandle::new(&first_sb, &p)),
|
||||||
.inspect_err(|e| {
|
Err(e) => {
|
||||||
error!(
|
error!(
|
||||||
"Failed to read passphrase from file, falling back to prompt: {}",
|
"Failed to read passphrase from file, falling back to prompt: {}",
|
||||||
e
|
e
|
||||||
)
|
);
|
||||||
})
|
None
|
||||||
.and_then(|p| KeyHandle::new(&first_sb, &p))
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| opt.unlock_policy.apply(&first_sb))
|
.unwrap_or_else(|| opt.unlock_policy.apply(&first_sb))
|
||||||
});
|
});
|
||||||
|
13
src/key.rs
13
src/key.rs
@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
ffi::{CStr, CString},
|
ffi::{c_long, CStr, CString},
|
||||||
fs,
|
fs,
|
||||||
io::{stdin, IsTerminal},
|
io::{stdin, IsTerminal},
|
||||||
mem,
|
mem,
|
||||||
@ -34,10 +34,7 @@ impl UnlockPolicy {
|
|||||||
pub fn apply(&self, sb: &bch_sb_handle) -> Result<KeyHandle> {
|
pub fn apply(&self, sb: &bch_sb_handle) -> Result<KeyHandle> {
|
||||||
let uuid = sb.sb().uuid();
|
let uuid = sb.sb().uuid();
|
||||||
|
|
||||||
info!(
|
info!("Using filesystem unlock policy '{self}' on {uuid}");
|
||||||
"Attempting to unlock filesystem {} with unlock policy '{}'",
|
|
||||||
uuid, self
|
|
||||||
);
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Self::Fail => Err(anyhow!("no passphrase available")),
|
Self::Fail => Err(anyhow!("no passphrase available")),
|
||||||
@ -57,12 +54,12 @@ impl Default for UnlockPolicy {
|
|||||||
pub struct KeyHandle {
|
pub struct KeyHandle {
|
||||||
// FIXME: Either these come in useful for something or we remove them
|
// FIXME: Either these come in useful for something or we remove them
|
||||||
_uuid: Uuid,
|
_uuid: Uuid,
|
||||||
_id: i64,
|
_id: c_long,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyHandle {
|
impl KeyHandle {
|
||||||
pub fn format_key_name(uuid: &Uuid) -> CString {
|
pub fn format_key_name(uuid: &Uuid) -> CString {
|
||||||
CString::new(format!("bcachefs:{}", uuid)).unwrap()
|
CString::new(format!("bcachefs:{uuid}")).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(sb: &bch_sb_handle, passphrase: &Passphrase) -> Result<Self> {
|
pub fn new(sb: &bch_sb_handle, passphrase: &Passphrase) -> Result<Self> {
|
||||||
@ -106,7 +103,7 @@ impl KeyHandle {
|
|||||||
info!("Found key in keyring");
|
info!("Found key in keyring");
|
||||||
Ok(KeyHandle {
|
Ok(KeyHandle {
|
||||||
_uuid: sb.sb().uuid(),
|
_uuid: sb.sb().uuid(),
|
||||||
_id: key_id as i64,
|
_id: key_id as c_long,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("failed to add key to keyring: {}", errno::errno()))
|
Err(anyhow!("failed to add key to keyring: {}", errno::errno()))
|
||||||
|
Loading…
Reference in New Issue
Block a user