diff --git a/src/commands/mount.rs b/src/commands/mount.rs index 71bc2bd4..0959bdcf 100644 --- a/src/commands/mount.rs +++ b/src/commands/mount.rs @@ -1,6 +1,7 @@ use std::{ - ffi::CString, + ffi::{CString, OsString}, io::{stdout, IsTerminal}, + os::unix::ffi::OsStringExt, path::{Path, PathBuf}, ptr, str, }; @@ -17,14 +18,14 @@ use crate::{ }; fn mount_inner( - src: String, + src: OsString, target: &std::path::Path, fstype: &str, mut mountflags: libc::c_ulong, data: Option, ) -> anyhow::Result<()> { // bind the CStrings to keep them alive - let c_src = CString::new(src.clone())?; + let c_src = CString::new(src.clone().into_vec())?; let c_target = path_to_cstr(target); let data = data.map(CString::new).transpose()?; let fstype = CString::new(fstype)?; @@ -63,9 +64,9 @@ fn mount_inner( let e = crate::ErrnoError(err); if err.0 == libc::EBUSY { - eprintln!("mount: {}: {} already mounted or mount point busy", target.to_string_lossy(), src); + eprintln!("mount: {}: {:?} already mounted or mount point busy", target.to_string_lossy(), src); } else { - eprintln!("mount: {}: {}", src, e); + eprintln!("mount: {:?}: {}", src, e); } Err(e.into()) @@ -160,7 +161,7 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> { if let Some(mountpoint) = cli.mountpoint.as_deref() { info!( - "mounting with params: device: {}, target: {}, options: {}", + "mounting with params: device: {:?}, target: {}, options: {}", devices, mountpoint.to_string_lossy(), &cli.options @@ -169,7 +170,7 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> { mount_inner(devices, mountpoint, "bcachefs", mountflags, optstr) } else { info!( - "would mount with params: device: {}, options: {}", + "would mount with params: device: {:?}, options: {}", devices, &cli.options ); diff --git a/src/device_scan.rs b/src/device_scan.rs index cb153198..479ebd20 100644 --- a/src/device_scan.rs +++ b/src/device_scan.rs @@ -1,8 +1,9 @@ use std::{ - ffi::{CStr, CString, c_char, c_int}, + ffi::{CStr, CString, c_char, c_int, OsString, OsStr}, collections::HashMap, env, fs, + os::unix::ffi::OsStringExt, path::{Path, PathBuf}, str, }; @@ -179,14 +180,14 @@ pub fn scan_sbs(device: &String, opts: &bch_opts) -> Result) -> String { +pub fn joined_device_str(sbs: &Vec<(PathBuf, bch_sb_handle)>) -> OsString { sbs.iter() - .map(|sb| sb.0.clone().into_os_string().into_string().unwrap()) + .map(|sb| sb.0.clone().into_os_string()) .collect::>() - .join(":") + .join(OsStr::new(":")) } -pub fn scan_devices(device: &String, opts: &bch_opts) -> Result { +pub fn scan_devices(device: &String, opts: &bch_opts) -> Result { let mut sbs = scan_sbs(device, opts)?; for sb in &mut sbs { @@ -236,8 +237,10 @@ pub extern "C" fn bch2_scan_devices(device: *const c_char) -> *mut c_char { // how to initialize to default/empty? let opts = bch_bindgen::opts::parse_mount_opts(None, None, true).unwrap_or_default(); - CString::new(scan_devices(&device, &opts).unwrap_or_else(|e| { + let devs = scan_devices(&device, &opts).unwrap_or_else(|e| { eprintln!("bcachefs ({}): error reading superblock: {}", device, e); std::process::exit(-1); - })).unwrap().into_raw() + }); + + CString::new(devs.into_vec()).unwrap().into_raw() }