Storage Drivers
Portix OS provides bare-metal storage access through an ATA PIO driver, FAT32 filesystem implementation, and virtual filesystem abstraction.ATA Bus
AtaBus::scan()
Scans all ATA channels (primary/secondary) and detects connected drives.AtaBus instance containing all detected drives.
Example:
AtaBus::count()
Returns the number of detected drives.AtaBus::info()
Retrieves drive information for a specific drive ID.Drive identifier:
Primary0, Primary1, Secondary0, or Secondary1Some(DriveInfo) if drive exists, None otherwise.
AtaBus::drive()
Creates an I/O handle for a detected drive.Drive identifier
Some(AtaDrive) handle for I/O operations, None if drive not found.
ATA Drive
AtaDrive::from_info()
Creates a drive handle from cachedDriveInfo without re-scanning the bus.
Previously obtained drive information
Safe to call anytime. Does not trigger hardware reset.
AtaDrive::read_sectors()
Reads consecutive sectors from the drive.Logical Block Address (sector number) to start reading from
Number of 512-byte sectors to read
Buffer to receive data. Must be exactly
count * 512 bytes.AtaError::BadBuffer- Buffer size is not a multiple of 512AtaError::OutOfRange- LBA exceeds drive capacityAtaError::Timeout- Drive did not respondAtaError::DeviceError(u8)- Drive reported an error
AtaDrive::write_sectors()
Writes consecutive sectors to the drive.Logical Block Address to start writing to
Number of 512-byte sectors to write
Data to write. Must be exactly
count * 512 bytes.flush() after each sector in LBA28/LBA48 modes.
AtaDrive::flush()
Flushes the drive’s write cache to physical media.Drive Information
DriveInfo
Contains metadata about a detected ATA drive.Drive position:
Primary0, Primary1, Secondary0, Secondary1Drive type:
Ata or AtapiTotal addressable 512-byte sectors
Drive capacity in MiB (total_sectors / 2048)
True if drive supports LBA48 (>128 GiB)
DriveInfo::model_str()
Returns the drive model as a UTF-8 string.DriveInfo::serial_str()
Returns the drive serial number.DriveInfo::firmware_str()
Returns the firmware revision.Cached Drive Access
Portix v0.8.0 introduces a global drive cache to avoid repeated hardware resets.store_primary_drive_info()
Stores the Primary0 drive info in the global cache.get_cached_drive_info()
Retrieves the cached Primary0 drive info without touching hardware.Some(DriveInfo) if cached, None if not yet stored.
Example (in disk commands):
FAT32 Volume
Fat32Volume::mount()
Mounts a FAT32 volume from an ATA drive.Drive handle to mount from
FatError::NotFat32- Volume is not FAT32 or MBR is invalidFatError::Ata(AtaError)- Underlying drive error
Fat32Volume::list_dir()
Iterates over directory entries.Cluster number of the directory (use
root_cluster() for root)Callback invoked for each entry
Fat32Volume::find_entry()
Searches for a file or directory by name.Directory to search in
Filename to find (case-insensitive)
DirEntryInfo if found.
Errors:
FatError::NotFound- Entry does not exist
Fat32Volume::read_file()
Reads file contents into a buffer.File entry to read
Buffer to receive file data
FatError::IsDir- Entry is a directory, not a file
Fat32Volume::write_file()
Writes data to a file, replacing its contents.File entry to write to (will be updated)
Data to write
Fat32Volume::create_file()
Creates a new empty file.Parent directory cluster
Filename (max 255 chars)
DirEntryInfo for the new file.
Errors:
FatError::NameTooLong- Name exceeds 255 charactersFatError::NoSpace- No free directory slots
Fat32Volume::create_dir()
Creates a new directory.Fat32Volume::delete_entry()
Deletes a file or directory.Entry to delete
Directory Entry
DirEntryInfo
Represents a file or directory in the FAT32 filesystem.Filename buffer (may contain LFN or 8.3 name)
Actual length of the filename in bytes
True if this is a directory
File size in bytes (0 for directories)
First cluster number
LBA of the sector containing this entry’s metadata
Byte offset within the sector
DirEntryInfo::name_str()
Returns the filename as a UTF-8 string.Virtual Filesystem (VFS)
VfsMount
Maps Unix-style paths to FAT32 clusters.VfsMount::new()
Creates an empty mount table.VfsMount::register()
Registers a path → cluster mapping.Unix path (e.g., “/home”, “/bin”)
FAT32 cluster number
VfsMount::resolve()
Resolves a path to its cluster number.Path to resolve
Some(cluster) if path is registered, None otherwise.
VfsMount::root_cluster()
Returns the root directory cluster (defaults to 2 if not registered).Path Utilities
path_split()
Splits a path into components.component_str()
Extracts a component as a string slice.path_join()
Joins a directory and filename.out.