1 use libc::{c_ulong, c_int};
2 use libc;
3 use {Result, NixPath};
4 use errno::Errno;
5 
6 libc_bitflags!(
7     pub struct MsFlags: c_ulong {
8         /// Mount read-only
9         MS_RDONLY;
10         /// Ignore suid and sgid bits
11         MS_NOSUID;
12         /// Disallow access to device special files
13         MS_NODEV;
14         /// Disallow program execution
15         MS_NOEXEC;
16         /// Writes are synced at once
17         MS_SYNCHRONOUS;
18         /// Alter flags of a mounted FS
19         MS_REMOUNT;
20         /// Allow mandatory locks on a FS
21         MS_MANDLOCK;
22         /// Directory modifications are synchronous
23         MS_DIRSYNC;
24         /// Do not update access times
25         MS_NOATIME;
26         /// Do not update directory access times
27         MS_NODIRATIME;
28         /// Linux 2.4.0 - Bind directory at different place
29         MS_BIND;
30         MS_MOVE;
31         MS_REC;
32         MS_SILENT;
33         MS_POSIXACL;
34         MS_UNBINDABLE;
35         MS_PRIVATE;
36         MS_SLAVE;
37         MS_SHARED;
38         MS_RELATIME;
39         MS_KERNMOUNT;
40         MS_I_VERSION;
41         MS_STRICTATIME;
42         MS_ACTIVE;
43         MS_NOUSER;
44         MS_RMT_MASK;
45         MS_MGC_VAL;
46         MS_MGC_MSK;
47     }
48 );
49 
50 libc_bitflags!(
51     pub struct MntFlags: c_int {
52         MNT_FORCE;
53         MNT_DETACH;
54         MNT_EXPIRE;
55     }
56 );
57 
mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P4: ?Sized + NixPath>( source: Option<&P1>, target: &P2, fstype: Option<&P3>, flags: MsFlags, data: Option<&P4>) -> Result<()>58 pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P4: ?Sized + NixPath>(
59         source: Option<&P1>,
60         target: &P2,
61         fstype: Option<&P3>,
62         flags: MsFlags,
63         data: Option<&P4>) -> Result<()> {
64 
65     let res =
66         source.with_nix_path(|source| {
67             target.with_nix_path(|target| {
68                 fstype.with_nix_path(|fstype| {
69                     data.with_nix_path(|data| {
70                         unsafe {
71                             libc::mount(source.as_ptr(),
72                                        target.as_ptr(),
73                                        fstype.as_ptr(),
74                                        flags.bits,
75                                        data.as_ptr() as *const libc::c_void)
76                         }
77                     })
78                 })
79             })
80         })????;
81 
82     Errno::result(res).map(drop)
83 }
84 
umount<P: ?Sized + NixPath>(target: &P) -> Result<()>85 pub fn umount<P: ?Sized + NixPath>(target: &P) -> Result<()> {
86     let res = target.with_nix_path(|cstr| {
87         unsafe { libc::umount(cstr.as_ptr()) }
88     })?;
89 
90     Errno::result(res).map(drop)
91 }
92 
umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()>93 pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()> {
94     let res = target.with_nix_path(|cstr| {
95         unsafe { libc::umount2(cstr.as_ptr(), flags.bits) }
96     })?;
97 
98     Errno::result(res).map(drop)
99 }
100