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
FileSystemTraits
- Core trait for implementing file systems- Support for POSIX-like operations with task and user isolation
§Device Management
DeviceTrait
- Abstraction for storage devicesMemoryDevice
- In-memory device implementation for testingDevice
- Thread-safe device wrapper
§Partition Support
PartitionDevice
- Device representing a partition on a larger devicePartitionEntry
- MBR partition table entryPartitionKind
- Enumeration of partition types
§MBR (Master Boot Record)
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_std
for embedded systems
§Examples
§Basic Device Operations
// Create an in-memory device for testing
let device = create_device!(Memory_device_type::<512>::new(1024 * 1024));
// Write some data
let data = b"Hello, File System!";
let result = device.Write(data);
assert!(result.is_ok());
§MBR Operations
// Create a device and format it with MBR
let device = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));
// Create MBR and add a partition
let mut mbr = MBR_type::New_with_signature(0x12345678);
mbr.Add_partition(Partition_type_type::Fat32_lba, 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§
Macros§
- create_
device - Convenience macro for creating a new
Device
from any type implementingDeviceTrait
. - create_
file_ system - Convenience macro for creating file system instances.
Structs§
- Block
- Standard block size representation for file system operations.
- Components
- Device
- Thread-safe wrapper for device implementations.
- Entry
- Represents a single entry within a directory.
- Entry
Identifier - File
Identifier - Type-safe wrapper for file identifiers.
- File
System Identifier - File system identifier type
- Flags
- All the flags that can be set for a file.
- Inode
- Type-safe wrapper for inode numbers.
- Local
File Identifier - Local file type
- Local
File Identifier Iterator - Mbr
- Master Boot Record structure (512 bytes)
- Memory
Device - In-memory device implementation with configurable block size.
- Metadata
- File attributes.
- Mode
- The mode of a file.
- Open
- The type of opening a file.
- Partition
Device - A device implementation that represents a partition within a larger storage device.
- Partition
Entry - MBR partition table entry structure (16 bytes).
- Partition
Statistics - Comprehensive statistics about partitions in an MBR.
- 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
- Represents a permission.
- Permissions
- Represents the permissions of a file or directory.
- Size
- Type-safe wrapper for size values in file system operations.
- Special
- Statistics_
type - Statistics of a file.
- Status
- The status of a file.
- Time
- Represents a point in time for file system operations.
- Unique
File Identifier - Unique file identifier type
Enums§
- Component
- Error
- Comprehensive enumeration of all possible file system errors.
- Kind
- Enumeration of file system object types.
- Partition
Kind - MBR partition type enumeration with comprehensive type definitions.
- 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.
Traits§
- Device
Trait - Core trait for all device implementations in the file system.
- File
System Traits - Core trait for all file system implementations.
Functions§
- backup_
mbr - Create a backup of an MBR as a byte array.
- clone_
mbr - Clone an MBR from one device to another.
- create_
all_ partition_ devices - Create partition devices for all valid partitions in an MBR.
- create_
basic_ mbr - Create a basic MBR with a single partition covering most of the disk.
- create_
partition_ device - Create a partition device from an MBR partition entry.
- find_
partitions_ by_ type - Find partitions of a specific type within an MBR.
- format_
disk_ and_ get_ first_ partition - Format disk to MBR if it doesn’t contain valid MBR and return first partition device
- get_
new_ file_ identifier - get_
new_ inode - has_
valid_ mbr - Check if a device contains a valid MBR.
- is_
gpt_ disk - Check if a device uses GPT (GUID Partition Table) instead of MBR.
- is_
valid_ string - restore_
mbr - Restore an MBR from a backup byte array.
- scan_
mbr_ partitions - Scan a device for MBR and return partition information.
- validate_
mbr - Validate MBR structure and partitions for consistency and correctness.
Type Aliases§
- Entry
Identifier Inner - File
Identifier Inner - File
System Identifier Inner - Result
- Standard result type for file system operations.