Struct glommio::io::BufferedFile[][src]

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

An asynchronously accessed file backed by the OS page cache.

All access uses buffered I/O, and all operations including open and close are asynchronous (with some exceptions noted).

See the module-level documentation for more details and examples.

Implementations

Returns true if the BufferedFile represent the same file on the underlying device.

Files are considered to be the same if they live in the same file system and have the same Linux inode. Note that based on this rule a symlink is not considered to be the same file.

Files will be considered to be the same if:

  • A file is opened multiple times (different file descriptors, but same file!)
  • they are hard links.

Examples

use glommio::{io::BufferedFile, LocalExecutor};
use std::os::unix::io::AsRawFd;

let ex = LocalExecutor::default();
ex.run(async {
    let mut wfile = BufferedFile::create("myfile.txt").await.unwrap();
    let mut rfile = BufferedFile::open("myfile.txt").await.unwrap();
    // Different objects (OS file descriptors), so they will be different...
    assert_ne!(wfile.as_raw_fd(), rfile.as_raw_fd());
    // However they represent the same object.
    assert!(wfile.is_same(&rfile));
    wfile.close().await;
    rfile.close().await;
});

Similar to create in the standard library, but returns a BufferedFile

Similar to open in the standard library, but returns a BufferedFile

Write the data in the buffer buf to this BufferedFile at the specified position

This method acquires ownership of the buffer so the buffer can be kept alive while the kernel has it.

Note that it is legal to return fewer bytes than the buffer size. That is the situation, for example, when the device runs out of space (See the man page for write(2) for details)

Examples

use glommio::{io::BufferedFile, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async {
    let file = BufferedFile::create("test.txt").await.unwrap();

    let mut buf = vec![0, 1, 2, 3];
    file.write_at(buf, 0).await.unwrap();
    file.close().await.unwrap();
});

Reads data at the specified position into a buffer allocated by this library.

Note that this differs from DmaFile’s read APIs: that reflects the fact that buffered reads need no specific alignment and io_uring will not be able to use its own pre-allocated buffers for it anyway.

Reads from a specific position in the file and returns the buffer.

Issues fdatasync for the underlying file, instructing the OS to flush all writes to the device, providing durability even if the system crashes or is rebooted.

pre-allocates space in the filesystem to hold a file at least as big as the size argument.

Truncates a file to the specified size.

Warning: synchronous operation, will block the reactor

rename this file.

Warning: synchronous operation, will block the reactor

remove this file.

The file does not have to be closed to be removed. Removing removes the name from the filesystem but the file will still be accessible for as long as it is open.

Warning: synchronous operation, will block the reactor

Returns the size of a file, in bytes.

Closes this file.

Returns an Option containing the path associated with this open directory, or None if there isn’t one.

Trait Implementations

Extracts the raw file descriptor. Read more

Formats the value using the given formatter. Read more

Constructs a new instance of Self from the given raw file descriptor. 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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more