mod libmount;
use std::ffi::CStr;
+use std::ptr;
+use std::process;
+
+extern crate errno;
+
+fn check_call(error: i32, msg: &str) {
+ if error < 0 {
+ errno::set_errno(errno::Errno(-error));
+ eprintln!("ERROR: {}: {}", msg, errno::errno());
+ process::exit(1);
+ }
+}
fn main() {
let fstab_path_cstr: &CStr = unsafe { CStr::from_ptr (libmount::mnt_get_fstab_path()) };
println!("fstab path C-String: {:?}", fstab_path_cstr);
let fstab_path = fstab_path_cstr.to_str().unwrap(); // may cause UTF-8 decoding error
println!("fstab path str: {}", fstab_path);
+
+ let mut version = ptr::null();
+ check_call(unsafe { libmount::mnt_get_library_version(ptr::addr_of_mut!(version)) },
+ "Failed to get lib version");
+ println!("libmount version: {:?}", unsafe { CStr::from_ptr(version) });
+
+ let table = unsafe { libmount::mnt_new_table() };
+ check_call(unsafe {libmount::mnt_table_parse_mtab(table, ptr::null()) },
+ "Failed to parse mtab");
+ let mut fs = ptr::null_mut();
+ check_call(unsafe { libmount::mnt_table_first_fs(table, &mut fs) },
+ "Failed to find first fs");
+
+ println!("first fs type: {:?} source: {:?} target: {:?}",
+ unsafe { CStr::from_ptr (libmount::mnt_fs_get_fstype(fs)) },
+ unsafe { CStr::from_ptr (libmount::mnt_fs_get_source(fs)) },
+ unsafe { CStr::from_ptr (libmount::mnt_fs_get_target(fs)) });
}