Struct nix::mount::Nmount[][src]

pub struct Nmount<'a> { /* fields omitted */ }
Expand description

Mount a FreeBSD file system.

The nmount(2) system call works similarly to the mount(8) program; it takes its options as a series of name-value pairs. Most of the values are strings, as are all of the names. The Nmount structure builds up an argument list and then executes the syscall.

Examples

To mount target onto mountpoint with nullfs:

use nix::mount::{MntFlags, Nmount, unmount};
use std::ffi::CString;
use tempfile::tempdir;

let mountpoint = tempdir().unwrap();
let target = tempdir().unwrap();

let fstype = CString::new("fstype").unwrap();
let nullfs = CString::new("nullfs").unwrap();
Nmount::new()
    .str_opt(&fstype, &nullfs)
    .str_opt_owned("fspath", mountpoint.path().to_str().unwrap())
    .str_opt_owned("target", target.path().to_str().unwrap())
    .nmount(MntFlags::empty()).unwrap();
 
unmount(mountpoint.path(), MntFlags::empty()).unwrap();

See Also

Implementations

Add an opaque mount option.

Some file systems take binary-valued mount options. They can be set with this method.

Safety

Unsafe because it will cause Nmount::nmount to dereference a raw pointer. The user is responsible for ensuring that val is valid and its lifetime outlives self! An easy way to do that is to give the value a larger scope than name

Examples

use libc::c_void;
use nix::mount::Nmount;
use std::ffi::CString;
use std::mem;

// Note that flags outlives name
let mut flags: u32 = 0xdeadbeef;
let name = CString::new("flags").unwrap();
let p = &mut flags as *mut u32 as *mut c_void;
let len = mem::size_of_val(&flags);
let mut nmount = Nmount::new();
unsafe { nmount.mut_ptr_opt(&name, p, len) };

Add a mount option that does not take a value.

Examples

use nix::mount::Nmount;
use std::ffi::CString;

let read_only = CString::new("ro").unwrap();
Nmount::new()
    .null_opt(&read_only);

Add a mount option that does not take a value, but whose name must be owned.

This has higher runtime cost than Nmount::null_opt, but is useful when the name’s lifetime doesn’t outlive the Nmount, or it’s a different string type than CStr.

Examples

use nix::mount::Nmount;

let read_only = "ro";
let mut nmount: Nmount<'static> = Nmount::new();
nmount.null_opt_owned(read_only);

Add a mount option as a CStr.

Examples

use nix::mount::Nmount;
use std::ffi::CString;

let fstype = CString::new("fstype").unwrap();
let nullfs = CString::new("nullfs").unwrap();
Nmount::new()
    .str_opt(&fstype, &nullfs);

Add a mount option as an owned string.

This has higher runtime cost than Nmount::str_opt, but is useful when the value’s lifetime doesn’t outlive the Nmount, or it’s a different string type than CStr.

Examples

use nix::mount::Nmount;
use std::path::Path;

let mountpoint = Path::new("/mnt");
Nmount::new()
    .str_opt_owned("fspath", mountpoint.to_str().unwrap());

Create a new Nmount struct with no options

Actually mount the file system.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.