Skip to main content

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
  • IoErrorKind - Common I/O error kind
  • 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 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 PlainData for it.

Structs§

AccessFlags
File access permissions.
AttributeFlags
Attributes
File attributes.
Block
Standard block size representation for file system operations.
Components
Context
ControlCommandIdentifier
ControlDirectionFlags
Direction of control commands.
CreateFlags
File creation flags.
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
Permissions
Represents the permissions of a file or directory.
ReadinessWaiter
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.
ReadyEvents
Special
StateFlags
File status flags.
Statistics
Statistics of a file.
Time
Represents a point in time for file system operations.
WaitQueue
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
IoErrorKind
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§

AttributeOperations
BaseOperations
Device operations return Poll directly, including read. Pending requires 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).
BlockDevice
CharacterDevice
ControlCommand
DirectBaseOperations
Device operations return Poll directly, including read. Pending requires 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).
DirectBlockDevice
DirectCharacterDevice
DirectoryOperations
FileOperations
FileSystemOperations
IntoIoErrorKind
Explicit translation of a subsystem error into an I/O kind.
MountOperations
PlainData
Marker trait for plain data: a type for which every bit pattern of size_of::<Self>() bytes is a valid value.
ResultExt
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§

EntryIdentifierInner
Inode
Result
Result type of every file system, VFS and device operation.
Size