Expand description
§File System Module
This crate provides a comprehensive file system abstraction layer for the Xila operating system. It includes support for various file system operations, device management, partition handling, and Master Boot Record (MBR) operations.
§Overview
The File System module is designed to provide a unified interface for:
- File and directory operations (create, read, write, delete, etc.)
- Device abstraction for block devices and memory devices
- Partition management and MBR (Master Boot Record) support
- File system metadata handling (permissions, timestamps, etc.)
- Cross-platform file system traits
§Key Components
§File System Traits
FileSystemOperations- Core trait for implementing file systems- Support for POSIX-like operations with task and user isolation
§Device Management
CharacterDevice- Character device abstractionBlockDevice- Block device abstractionDirectCharacterDevice- Context-free direct character device operationsDirectBlockDevice- Context-free direct block device operationsMemoryDevice- In-memory device implementation for testing
§Partition Support
PartitionDevice- Device representing a partition on a larger devicembr::PartitionEntry- MBR partition table entrymbr::PartitionKind- Enumeration of partition types
§MBR (Master Boot Record)
mbr::Mbr- Complete MBR structure with partition table- Utilities for creating, reading, and validating MBRs
- Support for creating partition devices from MBR entries
§Fundamental Types
Path- File system path representationIoErrorKind- Common I/O error kindSize- Size and position typesTime- Timestamp handlingFlags- File operation flags
§Features
std- Enables standard library support for environments that have it- Default is
no_stdfor embedded systems
§Examples
§Basic Device Operations
// Create an in-memory device for testing
let device = MemoryDevice::<512>::new(1024 * 1024);
// Write some data
let data = b"Hello, File System!";
let mut cx = core::task::Context::from_waker(core::task::Waker::noop());
assert_eq!(device.write(&mut cx, data, 0), core::task::Poll::Ready(Ok(data.len())));§MBR Operations
extern crate alloc;
use file_system::{mbr::{Mbr, PartitionKind, create_partition_device}, MemoryDevice};
// Create a device and format it with MBR
let device = MemoryDevice::<512>::new(4 * 1024 * 1024);
// Format disk with a partition
let partition = Mbr::format_disk_with_signature_and_partition(
&device,
0x12345678,
PartitionKind::Xila,
).unwrap();§Safety and Concurrency
This crate is designed to be thread-safe and supports concurrent access to file systems
and devices. All device implementations must be Send + Sync and should use appropriate
synchronization primitives to handle concurrent access.
§Error Handling
Device I/O returns Poll<Result<T>>; synchronous operations return Result<T>.
The IoErrorKind enum provides comprehensive error reporting for all file system operations.
Re-exports§
pub use io_error;
Modules§
- attribute
- base
- One object-safe polling contract for device I/O.
- block_
device - character_
device - Character device contracts, including the terminal line discipline controls.
- directory
- file
- file_
system - mbr
- Master Boot Record (MBR) module.
- mount
- tests
- Generic test suite for file system operations.
Macros§
- define_
command - Defines a control command: a unit struct implementing
ControlCommand. - implement_
block_ device_ tests - implement_
file_ system_ tests - Macro to implement all file system operation tests for a given file system instance.
- plain_
data - Declares a plain-data structure and implements
PlainDatafor it.
Structs§
- Access
Flags - File access permissions.
- Attribute
Flags - Attributes
- File attributes.
- Block
- Standard block size representation for file system operations.
- Components
- Context
- Control
Command Identifier - Control
Direction Flags - Direction of control commands.
- Create
Flags - File creation flags.
- Dummy
File System - Entry
- Represents a single entry within a directory.
- Entry
Identifier - Flags
- All the flags that can be set for a file.
- Memory
Device - In-memory device implementation with configurable block size.
- Partition
Device - A device implementation that represents a partition within a larger storage device.
- Path
- A borrowed path type.
The implementation is very similar to the standard library’s
std::path::Path. However, this implementation is more lightweight and allows for std-less usage. - Path
Owned - Permission
- Permissions
- Represents the permissions of a file or directory.
- Readiness
Waiter - A one-shot registration in the I/O readiness hub. Register before probing sources, re-register on each poll, and drop to cancel. Using the pinned address as the key keeps distinct waiters even when they share a task waker.
- Ready
Events - Special
- State
Flags - File status flags.
- Statistics
- Statistics of a file.
- Time
- Represents a point in time for file system operations.
- Wait
Queue - Bounded, allocation-free registrations. Notifications preserve reservations until cancellation, preventing a woken opening from clearing a reused slot. Callers must check readiness, register, then recheck before returning Pending.
- Waiter
- One opening’s reservation in a WaitQueue. Never share or clone reservations between openings; always cancel before discarding an opening.
Enums§
- Component
- IoError
Kind - A semantic I/O failure with a stable Xila ID.
- Kind
- Enumeration of file system object types.
- Operation
- Position
- Represents a position within a file for seek operations.
Constants§
- EXTENSION_
SEPARATOR - Extension separator character used in paths.
- SEPARATOR
- Separator character used in paths.
- XILA_
DISK_ SIGNATURE
Traits§
- Attribute
Operations - Base
Operations - Device operations return
Polldirectly, includingread.Pendingrequires race-free waker registration and must not hide consumed bytes. Never retain caller buffers or task-context pointers. Device-owned state belongs in the opening context (or the device for context-free implementations). - Block
Device - Character
Device - Control
Command - Direct
Base Operations - Device operations return
Polldirectly, includingread.Pendingrequires race-free waker registration and must not hide consumed bytes. Never retain caller buffers or task-context pointers. Device-owned state belongs in the opening context (or the device for context-free implementations). - Direct
Block Device - Direct
Character Device - Directory
Operations - File
Operations - File
System Operations - Into
IoError Kind - Explicit translation of a subsystem error into an I/O kind.
- Mount
Operations - Plain
Data - Marker trait for plain data: a type for which every bit pattern of
size_of::<Self>()bytes is a valid value. - Result
Ext - Convert a result whose error implements
IntoIoErrorKind.
Functions§
- is_
valid_ string - notify_
readiness - Notify after a source changes state. Drivers must release their state lock before calling this. Waiters always recheck their own sources after a wake. Returns the number of registrations woken.
- ready
- Complete an intrinsically synchronous backend operation with the polling contract. The closure runs exactly once; busy errors remain errors.
Type Aliases§
- Entry
Identifier Inner - Inode
- Result
- Result type of every file system, VFS and device operation.
- Size