Expand description
The file system: files as File (std’s file in a
Handle), OpenOptions, the calls by path
(read, write, metadata, rename, copy, …),
directories (create_dir_all, DirBuilder, read_dir streamed a
page at a time) and links. Calls by path, and a regular file’s calls
beside its reads, writes, syncs and Handle::allocate, run on the
blocking pool; Handle::try_lock_file, which never waits, runs on the
calling thread, and so does File::open on Linux for a regular file on a
local file system whose path the kernel’s caches resolve at once.
A regular file’s reads and writes, at the handle’s own cursor or at an
offset of the caller’s (Handle::read_at, Handle::write_at and
their forms, which many tasks may make at once on one handle, and
Handle::read_many_at, many reads in one call), its syncs
(Handle::sync_all, Handle::sync_data, Handle::sync_range) and
Handle::allocate are operations of the shard’s ring on io_uring and
jobs of the blocking pool on the other backends (see file). A file
opened for direct IO (O_DIRECT, FILE_FLAG_NO_BUFFERING) is read and
written with exactly the caller’s lengths and offsets, never through the
handle’s read-ahead or write-behind. A File that is not a regular file
(a FIFO, a terminal, a pipe) is a byte stream the shard’s driver serves
like a socket (on Windows, through the completion port, or through jobs
of the blocking pool for a handle opened for synchronous IO). Reads and
writes at the cursor are AsyncRead and AsyncWrite on the handle and
on a shared reference to it (both share the cursor, as &File shares its
offset); AsyncBufRead and AsyncSeek are on the handle. read_owned,
write_owned, read_at_owned, write_at_owned and the vectored
read_vectored_owned and write_vectored_owned take the caller’s
buffers (any IoBuf or IoBufMut, an
AlignedBuf for direct IO) and give them back,
so the bytes are read into them and written from them with no copy.
Beside those, a regular file can be asked to change the space a range
uses (Handle::allocate: reserve, keep the length, punch a hole, zero),
to write a range back (Handle::sync_range), to copy a range into
another file in the kernel where the system can (Handle::copy_range_to),
and to take an advisory lock without blocking the worker
(Handle::lock_file, Handle::try_lock_file, Handle::unlock_file).
A file’s name in its directory needs sync_dir to survive a crash. To
replace a file atomically: write a temporary file in the same directory,
sync_all it, rename it over the target, then sync_dir the
directory.
Structs§
- DirBuilder
- How to create a directory: recursively or not, and with which mode.
- DirEntry
- An entry of a directory.
- File
Times - Representation of the various timestamps on a file.
- File
Type - A structure representing a type of file with accessors for each file type.
It is returned by
Metadata::file_typemethod. - Metadata
- Metadata information about a file.
- Open
Options - How to open a file: the options of std’s
OpenOptions, opened on the blocking pool into aHandle. - Permissions
- Representation of the various permissions on a file.
- ReadDir
- A directory’s entries, read a page at a time.
Enums§
- Allocate
- How a call to
File::allocatechanges the space a range of a file uses. - TryLock
Error - An enumeration of possible errors which can occur while trying to acquire a lock
from the
try_lockmethod andtry_lock_sharedmethod on aFile.
Functions§
- canonicalize
- The absolute path of
path, every link and..resolved. - copy
- Copies the file
fromtoto, with its permissions; answers the bytes copied. - create_
dir - Creates the directory
path; its parent must exist. - create_
dir_ all - Creates the directory
pathand every missing parent. - hard_
link - Makes
linka new name of the fileoriginal(a hard link). - metadata
- The metadata of what
pathnames, through links. - read
- The whole file at
path. - read_
dir - The entries of the directory at
path, throughReadDir::next_entryor as a [Stream]. - read_
link - Where the symbolic link
pathpoints. - read_
to_ string - The whole file at
path, which must be UTF-8. - remove_
dir - Removes the empty directory at
path. - remove_
dir_ all - Removes the directory at
pathand everything in it. - remove_
file - Removes the file at
path. - rename
- Renames
fromtoto, replacingtoif it is a file. - set_
permissions - Sets the permissions of what
pathnames. - symlink
- Makes
linka symbolic link tooriginal. - symlink_
metadata - The metadata of what
pathnames, a link itself rather than its target. - sync_
dir - Writes the entries of the directory at
paththrough to the device: the names created, removed or renamed in it before the call survive a crash. A file’s ownsync_alldoes not cover its name in the directory, so the name needs this call. It runs on the blocking pool. - try_
exists - Whether
pathnames something:Ok(false)when it does not, an error when that cannot be told (no permission, for one). - write
- Writes
contentsas the whole file atpath, creating it or cutting it down first.