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.
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.
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
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
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
read_initializer
)Determines if this Read
er 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
Creates an adapter which will chain this stream with another. 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
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
Attempts to write an entire buffer into this writer. Read more
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