standard_lib/fs/mod.rs
1//! File-system interface which acts as an abstraction over Linux's syscalls. As such, this crate is
2//! specific to Linux only.
3//!
4//! # Purpose
5//! Doing the research to write this module has taught me heaps about how Linux actually works and
6//! how programs interact with it. It has also helped to clarify what functions the Kernel actually
7//! encompasses.
8//!
9//! # Method
10//! All components of this module are written to target Linux specifically. Although most parts
11//! probably rely on the general POSIX standards, there may be some places where they make use of
12//! Linux-specific extensions or implementation details. As for architecture, I haven't yet decided
13//! whether I'm targeting 64-bit systems specifically or handling all pointer sizes, 64-bit is
14//! certainly the primary target. Beyond pointer width, this should work on architecture thanks to
15//! glibc's platform specific constants.
16//!
17//! Some types in the module very closely resemble [`std::fs`], but others differ significantly.
18//! Notable differences include:
19//! - A [`Directory`] type, which leverages the file descriptor and open syscall's
20//! ability to open and refer to a directory by a descriptor rather then just a path. This could
21//! help to prevent TOCTOU bugs / exploits.
22//! - Distinct absolute ([`Path<Abs>`](Path<Abs>)) and relative
23//! ([`Path<Rel>`](Path<Rel>)) path types with additional formatting invariants for both.
24//! Among other things, this prevents unexpected behavior such as absolute paths replacing each
25//! other when joined (as they do in [`std`]).
26//! - Statically dispatched error types for more explicit error handling.
27#![cfg(feature = "fs")]
28#![cfg(target_os = "linux")]
29#![doc(cfg(all(Linux, feature = "fs")))]
30
31pub mod dir;
32pub mod error;
33pub mod file;
34pub(crate) mod panic;
35pub mod path;
36
37mod fd;
38mod file_type;
39mod metadata;
40
41pub(crate) use fd::*;
42pub use file_type::*;
43pub use metadata::*;
44
45#[doc(inline)]
46pub use dir::Directory;
47#[doc(inline)]
48pub use file::File;
49#[doc(inline)]
50pub use path::{Abs, OwnedPath, Path, Rel};