Crate file_system

Crate file_system 

Source
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

§Partition Support

§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 representation
  • Error - File system error enumeration
  • Size - Size and position types
  • Time - Timestamp handling
  • Flags - 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 = 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§

AccessFlags
The flags for opening a file.
AttributeFlags
Flags for file creation.
Attributes
File attributes.
Block
Standard block size representation for file system operations.
Components
Context
ControlCommandIdentifier
ControlDirectionFlags
The kinds of control commands.
CreateFlags
The flags for opening a file.
DummyFileSystem
Entry
Represents a single entry within a directory.
EntryIdentifier
Flags
All the flags that can be set for a file.
MemoryDevice
In-memory device implementation with configurable block size.
PartitionDevice
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.
PathOwned
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.
StateFlags
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§

AttributeOperations
BaseOperations
Core trait for all device implementations in the file system.
BlockDevice
CharacterDevice
ControlCommand
DirectBaseOperations
DirectBlockDevice
DirectCharacterDevice
DirectoryOperations
FileOperations
FileSystemOperations
MountOperations

Functions§

is_valid_string

Type Aliases§

EntryIdentifierInner
Inode
Result
Standard result type for file system operations.
Size