Skip to main content

SectionedStorage

Struct SectionedStorage 

Source
pub struct SectionedStorage { /* private fields */ }

Implementations§

Source§

impl SectionedStorage

Source

pub fn create(path: &Path) -> Result<Self>

Create a new sectioned file

Source

pub fn is_sectioned_file(path: &Path) -> bool

Check if a file is a sectioned file without opening it

This is a lightweight check that only reads the file header to verify the magic number. It doesn’t validate the entire file structure.

Source

pub fn open(path: &Path) -> Result<Self>

Open an existing sectioned file

Reads header and section table, validates structure integrity. Returns error if validation fails.

Source

pub fn create_section( &mut self, name: &str, capacity: u64, flags: u32, ) -> Result<()>

Create a new section with IMMEDIATE physical reservation

This method:

  1. Validates the name
  2. Gets current file length
  3. Computes allocation_base = max(next_data_offset, file_len)
  4. Allocates from allocation_base
  5. Physically extends file to reserve capacity
  6. Updates header.next_data_offset

Fails if:

  • Name is empty
  • Name exceeds 32 UTF-8 bytes
  • Section with same name exists
  • Addition would overflow
  • File extension fails
Source

pub fn write_section(&mut self, name: &str, data: &[u8]) -> Result<()>

Write data to an existing section

TASK 4 CAPACITY BEHAVIOR: Fails loudly with explicit error on overflow. Never silently loses data.

Fails if:

  • Section doesn’t exist
  • data.len() > section.capacity (explicit capacity error)
Source

pub fn read_section(&mut self, name: &str) -> Result<Vec<u8>>

Read data from a section

Fails if:

  • Section doesn’t exist
  • Checksum mismatch
Source

pub fn get_section(&self, name: &str) -> Option<&Section>

Get section metadata without reading data

Source

pub fn list_sections(&self) -> Vec<Section>

List all sections

Source

pub fn section_count(&self) -> usize

Get the number of sections

Source

pub fn path(&self) -> &Path

Get the file path

Source

pub fn header(&self) -> &GeoFileHeader

Get a reference to the header

Source

pub fn flush(&mut self) -> Result<()>

Flush section table to EOF

Phase A behavior:

  • Appends a FRESH section table at current EOF
  • Updates header.section_table_offset to point to new table
  • Old section tables become dead bytes in file
  • File size grows with each flush

File layout after flush():

[0..128)                    - header
[128..next_data_offset)      - section payload area
[section_table_offset..EOF)  - current section table

Because create_section() guarantees EOF >= next_data_offset, the section table is always placed after all section payloads.

Compaction (reclaiming dead tables) is deferred to a later phase.

Source

pub fn validate(&mut self) -> Result<()>

Validate file structure integrity

IMPORTANT: If self.dirty == true, returns an error. Unflushed state cannot be validated against disk.

Source

pub fn validate_required_sections(&self, required: &[&str]) -> Result<()>

Validate that required sections exist

Source

pub fn resize_section(&mut self, name: &str, new_capacity: u64) -> Result<()>

Resize a section to a new (larger) capacity

This method:

  1. Reads the current section data
  2. Creates a new section with the larger capacity at EOF
  3. Copies the data to the new location
  4. Removes the old section (becomes dead space)
  5. Flushes to disk

Fails if:

  • Section doesn’t exist
  • New capacity is smaller than current data length
  • Read/write operations fail

Note: The old section’s space becomes dead space in the file. A future compaction operation could reclaim this space.

Trait Implementations§

Source§

impl Debug for SectionedStorage

Sectioned file storage container

File layout (Phase A - Append-Only with Dead Tables):

[0..128)                    - header
[various offsets]            - live section payloads (may have gaps)
[header.section_table_offset..) - current live section table
[section_table_offset..file_len) - dead bytes (old tables) may exist
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.