13 unstable releases

0.6.4 Sep 18, 2023
0.6.3 Mar 29, 2023
0.6.2 Nov 10, 2022
0.6.1 Jun 29, 2022
0.2.0 Sep 5, 2018

#20 in Unix APIs

Download history 92545/week @ 2024-01-03 133034/week @ 2024-01-10 130498/week @ 2024-01-17 130683/week @ 2024-01-24 110936/week @ 2024-01-31 130818/week @ 2024-02-07 140447/week @ 2024-02-14 139447/week @ 2024-02-21 146832/week @ 2024-02-28 137673/week @ 2024-03-06 124095/week @ 2024-03-13 133884/week @ 2024-03-20 116542/week @ 2024-03-27 133973/week @ 2024-04-03 128559/week @ 2024-04-10 97159/week @ 2024-04-17

499,560 downloads per month
Used in 455 crates (9 directly)

MIT/Apache

17KB
257 lines

memfd

Build Status crates.io Documentation

A pure-Rust library to work with Linux memfd and seals.

It provides support for creating memfd objects on Linux and handling seals on them. This was first introduced in Linux kernel 3.17. For further details, see memfd_create(2) manpage.

Example

extern crate memfd;
use memfd::errors::Result;

fn new_sized_memfd() -> Result<memfd::Memfd> {
    // Create a sealable memfd.
    let opts = memfd::MemfdOptions::default().allow_sealing(true);
    let mfd = opts.create("sized-1K")?;

    // Resize to 1024B.
    mfd.as_file().set_len(1024)?;

    // Add seals to prevent further resizing.
    let mut seals = memfd::SealsHashSet::new();
    seals.insert(memfd::FileSeal::SealShrink);
    seals.insert(memfd::FileSeal::SealGrow);
    mfd.add_seals(&seals)?;

    // Prevent further sealing changes.
    mfd.add_seal(memfd::FileSeal::SealSeal);

    Ok(mfd)
}

Some more examples are available under examples.

License

Licensed under either of

at your option.

Dependencies

~2–11MB
~107K SLoC