Struct memfile::MemFile[][src]

pub struct MemFile { /* fields omitted */ }

A memory backed file that can have seals applied to it.

The struct implements AsRawFd, IntoRawFd and FromRawFd. When using FromRawFd::from_raw_fd, you must ensure that the file descriptor is a valid memfd.

Implementations

impl MemFile[src]

pub fn create(name: &str, options: &CreateOptions) -> Result<Self>[src]

Create a new memfd with the given options.

The name argument is purely for debugging purposes. On Linux it shows up in /proc, but it serves no other purpose. In particular, multiple files can be created with the same name.

The close-on-exec flag is set on the created file descriptor. If you want to pass it to a child process, you should use libc::dup2 or something similar after forking. Disabling the close-on-exec flag before forking causes a race condition with other threads.

pub fn try_clone(&self) -> Result<Self>[src]

Try to create a new MemFile Createinstance that shares the same underlying file handle as the existing MemFile instance.

Reads, writes, and seeks will affect both MemFile instances simultaneously.

pub fn from_file<T: AsRawFd + IntoRawFd>(
    file: T
) -> Result<Self, FromFdError<T>>
[src]

Wrap an already-open file as MemFile.

This function returns an error if the file was not created by memfd_create.

If the function succeeds, the passed in file object is consumed and the returned MemFile takes ownership of the file descriptor. If the function fails, the original file object is included in the returned error.

pub fn set_len(&self, size: u64) -> Result<()>[src]

Truncate or extend the underlying file, updating the size of this file to become size.

If the size is less than the current file's size, then the file will be shrunk. If it is greater than the current file's size, then the file will be extended to size and have all of the intermediate data filled in with 0s. The file's cursor isn't changed. In particular, if the cursor was at the end and the file is shrunk using this operation, the cursor will now be past the end.

pub fn get_seals(&self) -> Result<Seals>[src]

Get the active seals of the file.

pub fn add_seal(&self, seal: Seal) -> Result<()>[src]

Add a single seal to the file.

If you want to add multiple seals, you should prefer Self::add_seals to reduce the number of syscalls.

This function will fail if the file was not created with sealing support, if the file has already been sealed with Seal::Seal, or if you try to add Seal::Write while a shared, writable memory mapping exists for the file.

Adding a seal that is already active is a no-op.

pub fn add_seals(&self, seals: Seals) -> Result<()>[src]

Add multiple seals to the file.

This function will fail if the file was not created with sealing support, if the file has already been sealed with Seal::Seal, or if you try to add Seal::Write while a shared, writable memory mapping exists for the file.

Adding seals that are already active is a no-op.

Trait Implementations

impl AsRawFd for MemFile[src]

impl Debug for MemFile[src]

impl FileExt for MemFile[src]

impl FromRawFd for MemFile[src]

impl IntoRawFd for MemFile[src]

impl Read for MemFile[src]

impl Seek for MemFile[src]

impl Write for MemFile[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.