lxutil

Struct LxFile

Source
pub struct LxFile { /* private fields */ }
Expand description

A platform-independent abstraction that allows you to treat a file as if it has Unix semantics.

LxFile instances are created by using LxVolume::open.

Implementations§

Source§

impl LxFile

Source

pub fn fstat(&self) -> Result<Stat>

Retrieves the attributes of the file.

Source

pub fn set_attr(&self, attr: SetAttributes) -> Result<()>

Sets the attributes of the file.

This function combines the functionality of truncate, chmod, chown and utimensat.

If this function fails, some of the operations may still have succeeded.

§Windows

Chmod and chown are only fully supported if metadata is enabled and the file system supports it. Without metadata, chmod only changes the read-only attribute if all write bits are removed from the mode, and chown silently succeeds without taking any action.

This function disables the set-user-ID and set-group-ID as required if a request is made to change the size, owner or group of a file. This is done based on whether the SetAttributes::thread_uid field indicates the user is root.

§Unix

The SetAttributes::thread_uid field is ignored, and the thread’s actual capabilities are are used.

If SetAttributes::ctime is set, the ctime is set to the current time rather than the specified value.

Source

pub fn truncate(&self, size: off_t, thread_uid: uid_t) -> Result<()>

Truncates a file.

§Windows

The thread_uid argument is used to determine whether or not the set-user-ID and set-group-ID bits should be cleared. This is ignored if metadata is disabled.

§Unix

Unlike the normal truncate syscall on Linux, this function does not follow symlinks. The thread_uid argument is ignored, and the thread’s actual capabilities are used.

Source

pub fn chmod(&self, mode: mode_t) -> Result<()>

Changes the permissions of a file.

§Windows

Chmod is only fully supported if metadata is enabled and the file system supports it. Without metadata, chmod only changes the read-only attribute if all write bites are removed from the mode.

Source

pub fn chown(&self, uid: Option<uid_t>, gid: Option<gid_t>) -> Result<()>

Changes the owner and/or group of a file.

§Windows

Chown is only fully supported if metadata is enabled and the file system supports it. Without metadata, chown silently succeeds without taking any action.

Source

pub fn set_times(&self, atime: SetTime, mtime: SetTime) -> Result<()>

Changes a file’s time stamps.

The change time of the file is always set to the current time if this function is called.

Source

pub fn pread(&self, buffer: &mut [u8], offset: off_t) -> Result<usize>

Reads a number of bytes starting from a given offset.

Returns the number of bytes read.

On Windows, the file pointer is changed after this operation, while on Unix, it is not.

Source

pub fn pwrite( &self, buffer: &[u8], offset: off_t, thread_uid: uid_t, ) -> Result<usize>

Writes a number of bytes starting from a given offset.

Returns the number of bytes written.

§Windows

The file pointer is changed after this operation, while on Unix, it is not.

The thread_uid argument is used to determine whether or not the set-user-ID and set-group-ID bits should be cleared. This is ignored if metadata is disabled.

§Unix

The thread_uid argument is ignored, and the thread’s actual capabilities are used.

Source

pub fn read_dir<F>(&mut self, offset: off_t, callback: F) -> Result<()>
where F: FnMut(DirEntry) -> Result<bool>,

Reads the contents of the directory, invoking the callback for each item.

If the callback returns an error, it is propagated to the caller. If the callback returns false, enumeration is stopped but no error is returned. Enumeration can be continued from the same position by calling this function again with the offset of the entry before the one that cancelled the enumeration.

§Windows

The . and .. entries are always returned, but their inode number is not set.

§Unix

The . and .. entries are returned only if the underlying file system returns them.

Source

pub fn fsync(&self, data_only: bool) -> Result<()>

Synchronizes the file’s buffer.

This function can optionally synchronize only data, not metadata.

Auto Trait Implementations§

§

impl Freeze for LxFile

§

impl RefUnwindSafe for LxFile

§

impl Send for LxFile

§

impl Sync for LxFile

§

impl Unpin for LxFile

§

impl UnwindSafe for LxFile

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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