struct Header
Defined at line 157 of file ../../src/storage/fvm/format.h
FVM header which describes the contents and layout of the volume manager.
Public Members
uint64_t magic
uint64_t major_version
uint64_t pslice_count
uint64_t slice_size
uint64_t fvm_partition_size
uint64_t vpartition_table_size
uint64_t allocation_table_size
uint64_t generation
uint8_t[32] hash
uint64_t oldest_minor_version
uint8_t[0] reserved
Public Methods
Header FromDiskSize (size_t usable_partitions, size_t disk_size, size_t slice_size)
Creates headers representing structures with the given information. FVM allows for growth, so
the "growable" variants takes the initial size as well as the max size that the metadata tables
can represent to allow for future growth up until that limit. FromDiskSize()/FromSliceCount()
will not necessarily allow for future growth (table padding up to a block boundary may allow
some growth).
The partition and slice tables will end up both being one larger than the number of usable
entries passed in to this function. So don't pass even numbers to make the tables
nicely aligned, pass one less.
TODO(https://fxbug.dev/42138108) make table_size == usable_count.
Currently the partition table size is fixed, so usable_partitions must be kMaxUsablePartitions
or it will assert.
TODO(https://fxbug.dev/42116137): Allow usable partitions to vary.
Defined at line 70 of file ../../src/storage/fvm/format.cc
Header FromGrowableDiskSize (size_t usable_partitions, size_t initial_disk_size, size_t max_disk_size, size_t slice_size)
Defined at line 74 of file ../../src/storage/fvm/format.cc
Header FromSliceCount (size_t usable_partitions, size_t usable_slices, size_t slice_size)
Defined at line 99 of file ../../src/storage/fvm/format.cc
Header FromGrowableSliceCount (size_t usable_partitions, size_t initial_usable_slices, size_t max_usable_slices, size_t slice_size)
Defined at line 103 of file ../../src/storage/fvm/format.cc
void SetSliceCount (size_t usable_slices)
Sets the number of slices.
0
<
= usable_slices
<
= GetAllocationTableAllocatedEntryCount();
This will update the pslice_count as well as the fvm_partition_size accordingly.
Defined at line 516 of file ../../src/storage/fvm/format.h
bool IsValid (uint64_t disk_size, uint64_t disk_block_size, std::string & out_err)
Validates the header. This does NOT check the hash because that covers the entire metadata
which is not available to just the header class.
The disk size is passed to validate that the specified disk image does not overflow the device.
To disable checking, pass std::numeric_limits
<uint64
_t>::max() for the disk_size.
The underlying device's disk_block_size is passed to ensure that it is a multiple of of the
slice size. To disable checking this, pass fvm::kBlockSize for the device block size.
A description of the error (if present) will be placed into the given output parameter
(required).
Defined at line 128 of file ../../src/storage/fvm/format.cc
bool HasValidTableSizes (std::string & out_err)
Like IsValid but perfoms the minimal possible validation only on the partition and allocation
table sizes. This does not check any other data, even the signature.
This function is useful when reading the primary superblock and we need to find the secondary
superblock. The secondary header is located after the allocation and partition tables, so the
primary header must have valid sizes for these tables before we can consider which variant is
valid.
Defined at line 203 of file ../../src/storage/fvm/format.cc
size_t GetPartitionTableOffset ()
The partition table always starts at a block offset, and is always a multiple of blocks
long in bytes.
Partition IDs count from 1 but the partition table is indexed from 0, leaving an unused
VPartitionEntry at the beginning of this table. The "entry count" is therefore one less than
the size of the table.
Defined at line 521 of file ../../src/storage/fvm/format.h
size_t GetPartitionTableEntryCount ()
Defined at line 526 of file ../../src/storage/fvm/format.h
size_t GetPartitionTableByteSize ()
Defined at line 536 of file ../../src/storage/fvm/format.h
size_t GetPartitionEntryOffset (size_t index)
Returns the offset of the given VPartitionEntry struct from the beginning of the Header. The
valid input range is:
0
<
index
<
= GetPartitionTableEntryCount()
Defined at line 542 of file ../../src/storage/fvm/format.h
size_t GetAllocationTableOffset ()
The allocation table begins on a block boundary after the partition table. It has a "used"
portion which are available for use by partitions (though they may not be used yet). Then it
has a potentially-larger "allocated" portion which allows FVM to grow assuming the underlying
device has room.
Defined at line 546 of file ../../src/storage/fvm/format.h
size_t GetAllocationTableUsedEntryCount ()
Defined at line 551 of file ../../src/storage/fvm/format.h
size_t GetAllocationTableUsedByteSize ()
Defined at line 553 of file ../../src/storage/fvm/format.h
size_t GetAllocationTableAllocatedEntryCount ()
Defined at line 558 of file ../../src/storage/fvm/format.h
size_t GetAllocationTableAllocatedByteSize ()
Defined at line 567 of file ../../src/storage/fvm/format.h
size_t GetMaxAllocationTableEntriesForDiskSize (size_t disk_size)
Computes the number of allocation table entries that are needed for the given disk size,
capping it at the maximum number representable using the current allocation table size.
This is used when growing the FVM partition.
Defined at line 569 of file ../../src/storage/fvm/format.h
size_t GetSliceEntryOffset (size_t pslice)
Byte offset from the beginning of the Header to the allocation table entry (SliceEntry struct)
with the given ID. Physical slice IDs are 1-based so valid input is:
1
<
= pslice
<
= pslice_count
To get the actual slice data, see GetSliceOffset().
Defined at line 581 of file ../../src/storage/fvm/format.h
size_t GetMetadataUsedBytes ()
The metadata counts the header, partition table, and allocation table. The allocation table
may contain unused entries (allowing FVM to grow as long as there is space on the underlying
device), in which case the used bytes will be less than the allocated bytes.
When the Header is default-initialized and the disk or slice size is 0, the metadata size
is defined to be 0.
Defined at line 587 of file ../../src/storage/fvm/format.h
size_t GetMetadataAllocatedBytes ()
Defined at line 597 of file ../../src/storage/fvm/format.h
size_t GetSuperblockOffset (SuperblockType type)
Returns the offset in bytes of the given superblock from the beginning of the device.
Defined at line 607 of file ../../src/storage/fvm/format.h
size_t GetDataStartOffset ()
Returns the offset in the device (counting both copies of the metadata) where the first slice
data starts.
Defined at line 611 of file ../../src/storage/fvm/format.h
size_t GetSliceDataOffset (size_t pslice)
Byte offset from the beginning of the device to the slice data. Physical slice IDs are 1-based
so valid input is:
1
<
= pslice
<
= pslice_count
This gets the actual slice data. To get the slice's allocation table entry, see
GetSliceEntryOffset().
Defined at line 616 of file ../../src/storage/fvm/format.h
std::string ToString ()
Returns a multi-line stringified representation of the header, useful for debugging. See also
"operator<<" for a more compact representation.
Defined at line 231 of file ../../src/storage/fvm/format.cc