driver.storage.vol.mgr¶
Partition and volume management.
Overview¶
The volume manager owns the global volume list and all partition operations. It is the layer between raw device I/O (storage manager) and the filesystem drivers. When a device is registered, driver.storage.mgr calls discover_volumes to parse the partition table and create TStorage_Volume instances for each valid partition.
Volume discovery supports three paths:
1. ATAPI/optical: bypasses partition table parsing and calls each registered filesystem's detectCallback directly (handles ISO 9660 media with hybrid MBR).
2. GPT: if any MBR partition entry has system ID $EE, reads the GPT header at LBA 1, validates it, and creates volumes from the GPT partition array.
3. MBR (classic): reads the MBR and creates volumes for each non-empty partition entry.
After volumes are created, probe_volume assigns a filesystem driver to each one. If no filesystem is identified, the volume's filesystem field remains nil.
Dependencies¶
io.syslogdriver.storage.fs.mgrcore.ds.listsmemory.heapdriver.storage.vol.mbrdriver.storage.vol.gptdriver.storage.mgrdriver.storage.typescore.stringsio.stdiodebug.tracercore.util,arch.x86.util
Variables¶
| Name | Type | Description |
|---|---|---|
volumes |
PDList |
Global list of all registered PStorage_Volume pointers |
Functions and Procedures¶
init¶
Allocates the global volume list. Must be called before volume manager functions are used.
get_volume_list¶
Returns the global volume list.
get_volume_count¶
Returns the number of registered volumes.
get_volume¶
Returns the volume at index, or nil if out of range.
register_volume¶
Adds volume to both the global list and the device's per-device volume list.
create_volume_from_partition¶
procedure create_volume_from_partition(device : PStorage_Device; sectorStart : uint32; sectorCount : uint32);
Allocates a TStorage_Volume, populates it from the device and partition geometry, calls probe_volume to identify the filesystem, and registers it.
get_partition¶
Returns the MBR partition entry at index (0..3) from the device's cached MBR. Returns a zeroed record if the device is nil, the index is out of range, or no MBR is cached.
add_partition¶
Writes partition to MBR slot slot (0..3) and creates the corresponding volume in memory. Does nothing if the device is nil, the slot is out of range, or the device is read-only.
remove_partition¶
Zeros MBR slot slot and removes the corresponding volume from the global and device lists.
init_disk¶
Removes all volumes for the device, writes a clean MBR (only the $AA55 signature, all partition entries zeroed). Used as the first step of the destructive disk test.
discover_volumes¶
Detects and registers all partitions on device. Handles ATAPI, GPT, and MBR cases as described in the Overview. If no volume is identified by any filesystem after partition detection, calls each filesystem's detectCallback on the raw device as a fallback.
find_free_space¶
Scans the device's partition table to find a contiguous free region of at least needed sectors. Returns the starting LBA of the free region, or 0 if none found.
find_free_slot¶
Returns the index (0..3) of the first empty MBR partition slot, or -1 if all slots are occupied.
get_free_sector_count¶
Returns the number of sectors on the device not covered by any MBR partition entry.
add_partition_async¶
procedure add_partition_async(device : PStorage_Device; slot : uint32; partition : TPartition_table;
callback : TIOCallback; callbackData : pointer);
Non-blocking version of add_partition. Fires callback when the MBR write completes.
remove_partition_async¶
procedure remove_partition_async(device : PStorage_Device; slot : uint32;
callback : TIOCallback; callbackData : pointer);
Non-blocking version of remove_partition.
init_disk_async¶
procedure init_disk_async(device : PStorage_Device;
callback : TIOCallback; callbackData : pointer);
Non-blocking version of init_disk.
format_volume¶
function format_volume(device : PStorage_Device; volIndex : uint32; filesystemName : pchar; config : puint32) : boolean;
Finds the filesystem driver named filesystemName and calls its createCallback on the volume at volIndex. Returns true if the driver was found and the callback was invoked.
format_volume_async¶
function format_volume_async(device : PStorage_Device; volIndex : uint32; filesystemName : pchar; config : puint32; callback : TIOCallback; callbackData : pointer) : boolean;
Non-blocking version of format_volume. Uses createAsyncCallback if available, falls back to the synchronous callback.
delete_volume¶
Removes a volume from the global and device lists and frees its memory.
Notes¶
- The global volume list stores
PStorage_Volumepointers (not value copies); the device's per-device list stores the same pointers. discover_volumescallsprobe_volumeviacreate_volume_from_partitionfor each partition. If the fallbackdetectCallbackpath creates additional volumes, those are also probed.- GPT partition entries with
StartLBA_HiorEndLBA_Hinon-zero are skipped because the kernel runs in 32-bit protected mode and cannot address LBAs beyond 32 bits.