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 representationError- File system error enumerationSize- 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 result = device.write(data, 0);
assert!(result.is_ok());§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);
// Create MBR and add a partition
let mut mbr = Mbr::new_with_signature(0x12345678);
mbr.add_partition(PartitionKind::Fat32Lba, 2048, 8192, true).unwrap();
// Write MBR to device
mbr.write_to_device(&device).unwrap();
// Create a partition device
let partition = create_partition_device(&device, &mbr.partitions[0]).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
All operations return Result<T> which is an alias for Result<T, Error>.
The Error enum provides comprehensive error reporting for all file system operations.
Modules§
- attribute
- base
- Device abstraction for storage and I/O operations.
- block_
device - character_
device - directory
- file
- file_
system - mbr
- Master Boot Record (MBR) module
- mount
Macros§
- define_
command - implement_
block_ device_ tests - implement_
file_ system_ tests - Macro to implement all file system operation tests for a given file system instance.
Structs§
- Access
Flags - The flags for opening a file.
- Attribute
Flags - Flags for file creation.
- Attributes
- File attributes.
- Block
- Standard block size representation for file system operations.
- Components
- Context
- Control
Command Identifier - Control
Direction Flags - The kinds of control commands.
- Create
Flags - The flags for opening a file.
- 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
- The permissions of a file or directory.
- Permissions
- Represents the permissions of a file or directory.
- Special
- The special permissions of a file or directory.
- State
Flags - The status flags of a file.
- Statistics
- Statistics of a file.
- Time
- Represents a point in time for file system operations.
Enums§
- Component
- Error
- Comprehensive enumeration of all possible file system errors.
- Kind
- Enumeration of file system object types.
- 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 - Core trait for all device implementations in the file system.
- Block
Device - Character
Device - Control
Command - Direct
Base Operations - Direct
Block Device - Direct
Character Device - Directory
Operations - File
Operations - File
System Operations - Mount
Operations
Functions§
Type Aliases§
- Entry
Identifier Inner - Inode
- Result
- Standard result type for file system operations.
- Size