Module fs

Source
Available on Linux only.
Expand description

File-system interface which acts as an abstraction over Linux’s syscalls. As such, this crate is specific to Linux only.

§Purpose

Doing the research to write this module has taught me heaps about how Linux actually works and how programs interact with it. It has also helped to clarify what functions the Kernel actually encompasses.

§Method

All components of this module are written to target Linux specifically. Although most parts probably rely on the general POSIX standards, there may be some places where they make use of Linux-specific extensions or implementation details. As for architecture, I haven’t yet decided whether I’m targeting 64-bit systems specifically or handling all pointer sizes, 64-bit is certainly the primary target. Beyond pointer width, this should work on architecture thanks to glibc’s platform specific constants.

Some types in the module very closely resemble std::fs, but others differ significantly. Notable differences include:

  • A Directory type, which leverages the file descriptor and open syscall’s ability to open and refer to a directory by a descriptor rather then just a path. This could help to prevent TOCTOU bugs / exploits.
  • Distinct absolute (Path<Abs>) and relative (Path<Rel>) path types with additional formatting invariants for both. Among other things, this prevents unexpected behavior such as absolute paths replacing each other when joined (as they do in std).
  • Statically dispatched error types for more explicit error handling.

Modules§

dir
Types for interacting with the directories of a file system. Simpler than the file module, this one is primarily focussed on the Directory and DirEntry types.
error
file
Types for interacting with files (or file-like inodes) on a file system. Primarily revolves around the File type and accompanying access mode markers.
path
Types for representing valid file system paths. OwnedPath and Path are available as owned and slice representations, respectively.

Structs§

Directory
An open directory that is guaranteed to exist for the lifetime of the Directory. Can also be used to obtain an iterator over each contained DirEntry.
File
An open file, allowing for reading and writing according to the associated AccessMode. The underlying file is guaranteed to exist for the lifetime of the File.
Metadata
OwnedPath
Path

Enums§

Abs
FileType
Rel