file_system/lib.rs
1//! # File System Module
2//!
3//! This crate provides a comprehensive file system abstraction layer for the Xila operating system.
4//! It includes support for various file system operations, device management, partition handling,
5//! and Master Boot Record (MBR) operations.
6//!
7//! ## Overview
8//!
9//! The File System module is designed to provide a unified interface for:
10//! - File and directory operations (create, read, write, delete, etc.)
11//! - Device abstraction for block devices and memory devices
12//! - Partition management and MBR (Master Boot Record) support
13//! - File system metadata handling (permissions, timestamps, etc.)
14//! - Cross-platform file system traits
15//!
16//! ## Key Components
17//!
18//! ### File System Traits
19//! - [`FileSystemOperations`] - Core trait for implementing file systems
20//! - Support for POSIX-like operations with task and user isolation
21//!
22//! ### Device Management
23//! - [`CharacterDevice`] - Character device abstraction
24//! - [`BlockDevice`] - Block device abstraction
25//! - [`DirectCharacterDevice`] - Context-free direct character device operations
26//! - [`DirectBlockDevice`] - Context-free direct block device operations
27//! - [`MemoryDevice`] - In-memory device implementation for testing
28//!
29//! ### Partition Support
30//! - [`PartitionDevice`] - Device representing a partition on a larger device
31//! - [`mbr::PartitionEntry`] - MBR partition table entry
32//! - [`mbr::PartitionKind`] - Enumeration of partition types
33//!
34//! ### MBR (Master Boot Record)
35//! - [`mbr::Mbr`] - Complete MBR structure with partition table
36//! - Utilities for creating, reading, and validating MBRs
37//! - Support for creating partition devices from MBR entries
38//!
39//! ### Fundamental Types
40//! - [`Path`] - File system path representation
41//! - [`IoErrorKind`] - Common I/O error kind
42//! - [`Size`] - Size and position types
43//! - [`Time`] - Timestamp handling
44//! - [`Flags`] - File operation flags
45//!
46//! ## Features
47//!
48//! - `std` - Enables standard library support for environments that have it
49//! - Default is `no_std` for embedded systems
50//!
51//! ## Examples
52//!
53//! ### Basic Device Operations
54//!
55//! ```rust
56//! # extern crate alloc;
57//! # use file_system::{MemoryDevice, DirectBaseOperations};
58//!
59//! // Create an in-memory device for testing
60//! let device = MemoryDevice::<512>::new(1024 * 1024);
61//!
62//! // Write some data
63//! let data = b"Hello, File System!";
64//! let mut cx = core::task::Context::from_waker(core::task::Waker::noop());
65//! assert_eq!(device.write(&mut cx, data, 0), core::task::Poll::Ready(Ok(data.len())));
66//! ```
67//!
68//! ### MBR Operations
69//!
70//! ```rust
71//! extern crate alloc;
72//! use file_system::{mbr::{Mbr, PartitionKind, create_partition_device}, MemoryDevice};
73//!
74//! // Create a device and format it with MBR
75//! let device = MemoryDevice::<512>::new(4 * 1024 * 1024);
76//!
77//! // Format disk with a partition
78//! let partition = Mbr::format_disk_with_signature_and_partition(
79//! &device,
80//! 0x12345678,
81//! PartitionKind::Xila,
82//! ).unwrap();
83//! ```
84//!
85//! ## Safety and Concurrency
86//!
87//! This crate is designed to be thread-safe and supports concurrent access to file systems
88//! and devices. All device implementations must be `Send + Sync` and should use appropriate
89//! synchronization primitives to handle concurrent access.
90//!
91//! ## Error Handling
92//!
93//! Device I/O returns `Poll<Result<T>>`; synchronous operations return [`Result<T>`].
94//! The [`IoErrorKind`] enum provides comprehensive error reporting for all file system operations.
95
96#![no_std]
97
98extern crate alloc;
99
100#[cfg(feature = "std")]
101extern crate std;
102
103mod context;
104mod devices;
105mod error;
106mod fundamentals;
107pub mod mbr;
108mod operations;
109mod time;
110
111pub use error::*;
112
113pub use shared::{PlainData, plain_data};
114
115pub use context::*;
116
117pub use devices::*;
118pub use fundamentals::*;
119pub use operations::file_system::tests;
120pub use operations::*;
121pub use time::*;
122
123pub const XILA_DISK_SIGNATURE: u32 = u32::from_le_bytes(*b"Xila");