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//! - [`Error`] - File system error enumeration
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 result = device.write(data, 0);
65//! assert!(result.is_ok());
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//! // Create MBR and add a partition
78//! let mut mbr = Mbr::new_with_signature(0x12345678);
79//! mbr.add_partition(PartitionKind::Fat32Lba, 2048, 8192, true).unwrap();
80//!
81//! // Write MBR to device
82//! mbr.write_to_device(&device).unwrap();
83//!
84//! // Create a partition device
85//! let partition = create_partition_device(&device, &mbr.partitions[0]).unwrap();
86//! ```
87//!
88//! ## Safety and Concurrency
89//!
90//! This crate is designed to be thread-safe and supports concurrent access to file systems
91//! and devices. All device implementations must be `Send + Sync` and should use appropriate
92//! synchronization primitives to handle concurrent access.
93//!
94//! ## Error Handling
95//!
96//! All operations return [`Result<T>`] which is an alias for `Result<T, Error>`.
97//! The [`Error`] enum provides comprehensive error reporting for all file system operations.
98
99#![no_std]
100
101extern crate alloc;
102
103#[cfg(feature = "std")]
104extern crate std;
105
106mod context;
107mod devices;
108mod error;
109mod fundamentals;
110pub mod mbr;
111mod operations;
112mod time;
113
114pub use error::*;
115
116pub use context::*;
117
118pub use devices::*;
119pub use fundamentals::*;
120pub use operations::*;
121pub use time::*;
122
123pub const XILA_DISK_SIGNATURE: u32 = u32::from_le_bytes(*b"Xila");