Struct memfile::MemFile[][src]

pub struct MemFile { /* fields omitted */ }
Expand description

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

Create a new MemFile 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.

Create a new MemFile with the given options.

This is identical to Self::create, except that it takes the name as CStr to avoid allocations. See that function for more information.

Create a new MemFile with default options.

Sealing is not enabled for the created file.

See Self::create for more information.

Create a new MemFile with file sealing enabled.

Sealing is enabled for the created file. All other options are the same as the defaults.

See Self::create for more information.

Create a new MemFile that shares the same underlying file handle.

The clones MemFile has a new file descriptor, but reads, writes, and seeks will affect both MemFile instances simultaneously.

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.

Convert this MemFile into an std::fs::File.

This may be useful for interoperability with other crates.

Query metadata about the underlying file.

Note that not all information in the metadata is not very meaningfull for a memfd. The file type is particularly useless since it is always the same. Some information, like the file size, may be useful.

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.

Get the active seals of the file.

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.

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

Extracts the raw file descriptor. Read more

Formats the value using the given formatter. Read more

Reads a number of bytes starting from a given offset. Read more

Writes a number of bytes starting from a given offset. Read more

Reads the exact number of byte required to fill buf from the given offset. Read more

Attempts to write an entire buffer starting from a given offset. Read more

Performs the conversion.

Constructs a new instance of Self from the given raw file descriptor. Read more

Consumes this object, returning the raw underlying file descriptor. Read more

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Like read, except that it reads into a slice of buffers. Read more

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Read the exact number of bytes required to fill buf. Read more

Creates a “by reference” adapter for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Seek to an offset, in bytes, in a stream. Read more

Rewind to the beginning of a stream. Read more

🔬 This is a nightly-only experimental API. (seek_stream_len)

Returns the length of this stream (in bytes). Read more

Returns the current seek position from the start of the stream. Read more

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

Write a buffer into this writer, returning how many bytes were written. Read more

Like write, except that it writes from a slice of buffers. Read more

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Writer has an efficient write_vectored implementation. Read more

Attempts to write an entire buffer into this writer. Read more

🔬 This is a nightly-only experimental API. (write_all_vectored)

Attempts to write multiple buffers into this writer. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

Creates a “by reference” adapter for this instance of Write. 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.