1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! High level abstraction over the `mount` and `umount2` system calls.
//! 
//! Additionally creates loopback devices automatically when mounting an iso or
//! squashfs file.
//! 
//! # Example
//! 
//! ```rust,no_run
//! extern crate sys_mount;
//! 
//! use std::process::exit;
//! use sys_mount::{
//!     Mount,
//!     MountFlags,
//!     SupportedFilesystems,
//!     Unmount,
//!     UnmountFlags
//! };
//! 
//! fn main() {
//!     // Fetch a list of supported file systems.
//!     // When mounting, a file system will be selected from this.
//!     let supported = SupportedFilesystems::new().unwrap();
//! 
//!     // Attempt to mount the src device to the dest directory.
//!     let mount_result = Mount::new(
//!         "/imaginary/block/device".into(),
//!         "/tmp/location",
//!         &supported,
//!         MountFlags::empty(),
//!         None
//!     );
//! 
//!     match mount_result {
//!         Ok(mount) => {
//!             // Make the mount temporary, so that it will be unmounted on drop.
//!             let mount = mount.into_unmount_drop(UnmountFlags::DETACH);
//!             // Do thing with the mounted device.
//!         }
//!         Err(why) => {
//!             eprintln!("failed to mount device: {}", why);
//!             exit(1);
//!         }
//!     }
//! }

extern crate libc;
extern crate loopdev;
#[macro_use]
extern crate bitflags;

mod fstype;
mod mount;
mod supported;
mod umount;

pub use self::fstype::*;
pub use self::mount::*;
pub use self::supported::*;
pub use self::umount::*;

use std::io;
use std::ffi::CString;

fn to_cstring(data: &[u8]) -> io::Result<CString> {
    CString::new(data).map_err(|why| {
        io::Error::new(
            io::ErrorKind::InvalidData,
            format!("failed to create `CString`: {}", why)
        )
    })
}