Function vmm_sys_util::fallocate::fallocate[][src]

pub fn fallocate(
    file: &dyn AsRawFd,
    mode: FallocateMode,
    keep_size: bool,
    offset: u64,
    len: u64
) -> Result<()>

A safe wrapper for fallocate.

Manipulate the file space with specified operation parameters.

Arguments

  • file: the file to be manipulate.
  • mode: specify the operation to be performed on the given range.
  • keep_size: file size won’t be changed even if offset + len is greater than the file size.
  • offset: the position that manipulates the file from.
  • size: the bytes of the operation range.

Examples

extern crate vmm_sys_util;
use vmm_sys_util::fallocate::{fallocate, FallocateMode};
use vmm_sys_util::tempdir::TempDir;

let tempdir = TempDir::new_with_prefix("/tmp/fallocate_test").unwrap();
let mut path = PathBuf::from(tempdir.as_path());
path.push("file");
let mut f = OpenOptions::new()
    .read(true)
    .write(true)
    .create(true)
    .open(&path)
    .unwrap();
fallocate(&f, FallocateMode::PunchHole, true, 0, 1).unwrap();