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
impl LxFile
Sourcepub fn set_attr(&self, attr: SetAttributes) -> Result<()>
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.
Sourcepub fn truncate(&self, size: off_t, thread_uid: uid_t) -> Result<()>
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.
Sourcepub fn chmod(&self, mode: mode_t) -> Result<()>
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.
Sourcepub fn chown(&self, uid: Option<uid_t>, gid: Option<gid_t>) -> Result<()>
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.
Sourcepub fn set_times(&self, atime: SetTime, mtime: SetTime) -> Result<()>
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.
Sourcepub fn pread(&self, buffer: &mut [u8], offset: off_t) -> Result<usize>
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.
Sourcepub fn pwrite(
&self,
buffer: &[u8],
offset: off_t,
thread_uid: uid_t,
) -> Result<usize>
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.
Sourcepub fn read_dir<F>(&mut self, offset: off_t, callback: F) -> Result<()>
pub fn read_dir<F>(&mut self, offset: off_t, callback: F) -> Result<()>
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.