]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - rust-src/bch_bindgen/src/fs.rs
rust: Fix ptr casting in Fs::open()
[bcachefs-tools-debian] / rust-src / bch_bindgen / src / fs.rs
index 1176846d90e4d0a0034567a3e8da87d43abcc6f4..b26c51b6c4102cd4bebabd4ff8dcf990d411e80c 100644 (file)
@@ -9,15 +9,12 @@ pub struct Fs {
 }
 
 impl Fs {
-    pub fn open(devices: &Vec<PathBuf>, opts: c::bch_opts) -> Result<Fs, bch_errcode> {
-        let devices: Vec<_> = devices.iter()
-            .map(|i| CString::new(i.as_os_str().as_bytes()).unwrap()).collect();
-        let dev_c_strs: Vec<_> = devices.iter()
-            .map(|i| { let p: *const i8 = i.as_ptr(); p })
+    pub fn open(devs: &Vec<PathBuf>, opts: c::bch_opts) -> Result<Fs, bch_errcode> {
+        let devs: Vec<_> = devs.iter()
+            .map(|i| CString::new(i.as_os_str().as_bytes()).unwrap().into_raw())
             .collect();
-        let dev_c_strarray: *const *mut i8 = dev_c_strs[..].as_ptr() as *const *mut i8;
 
-        let ret = unsafe { c::bch2_fs_open(dev_c_strarray, dev_c_strs.len() as u32, opts) };
+        let ret = unsafe { c::bch2_fs_open(devs[..].as_ptr(), devs.len() as u32, opts) };
 
         errptr_to_result(ret).map(|fs| Fs { raw: fs})
     }