class Metadata
Defined at line 27 of file ../../src/storage/fvm/metadata.h
Metadata is an in-memory representation of the metadata for an FVM image.
At construction, |Metadata| objects are well-formed, since they validate the underlying metadata
when first created by |Metadata::Create| or |Metadata::Synthesize|. Subsequent updates by clients
can, of course, corrupt the metadata.
This class owns the underlying buffer (see |MetadataBuffer)|.
This class is not thread-safe.
Public Methods
void Metadata ()
Constructs a default, uninitialized instance.
Defined at line 30 of file ../../src/storage/fvm/metadata.h
void Metadata (const Metadata & )
Defined at line 31 of file ../../src/storage/fvm/metadata.h
Metadata & operator= (const Metadata & )
Defined at line 32 of file ../../src/storage/fvm/metadata.h
void Metadata (Metadata && )
Defined at line 50 of file ../../src/storage/fvm/metadata.cc
Metadata & operator= (Metadata && )
Defined at line 52 of file ../../src/storage/fvm/metadata.cc
size_t BytesNeeded (const Header & header)
Returns the minimum number of bytes needed for a |MetadataBuffer| object to back FVM metadata
described by |header|.
Defined at line 43 of file ../../src/storage/fvm/metadata.cc
zx::result<Metadata> Synthesize (const fvm::Header & header, std::span<const VPartitionEntry> vpartitions, std::span<const SliceEntry> slices)
See Synthesize(fvm::Header, const VPartition,* size_t, const SliceEntry*, size_t);
Defined at line 70 of file ../../src/storage/fvm/metadata.h
zx::result<Metadata> Create (std::unique_ptr<MetadataBuffer> data_a, std::unique_ptr<MetadataBuffer> data_b)
Attempts to parse the FVM metadata stored at |data_a| and |data_b|, picking the latest copy.
The copy with the latest generation (that is also valid) will be retained; the other is
discarded.
Returns a |Metadata| instance over the passed metadata on success, or a failure if neither was
valid.
Defined at line 159 of file ../../src/storage/fvm/metadata.cc
zx::result<Metadata> Create (size_t disk_size, size_t disk_block_size, std::unique_ptr<MetadataBuffer> data_a, std::unique_ptr<MetadataBuffer> data_b)
Override of |Create| that allows specifying disk dimensions; the sizes of each metadata copy
will be checked against these sizes (see |::fvm::PickValidHeader|) and only deemed valid if
they fit within the disk.
Defined at line 165 of file ../../src/storage/fvm/metadata.cc
zx::result<Metadata> Synthesize (const fvm::Header & header, const VPartitionEntry * partitions, size_t num_partitions, const SliceEntry * slices, size_t num_slices)
Creates an instance of |Metadata|, initialized by copying the contents of |header|,
|partitions| and |slices|.
All of the passed metadata is copied into both the A and B slots. Any additional partitions
and slices in the tables past |partitions| and |slices| are default-initialized.
The passed |header| must be configured appropriately to manage tables at least as big as
|num_partitions| and |num_slices| respectively. If not, an error is returned.
Note: The user has no need to concern themselves with reserved pslice zero, since this is
adjusted internally. Though, all vpartitions' indexes must be in the range [1,
VPartitionEntryCount).
Defined at line 202 of file ../../src/storage/fvm/metadata.cc
bool CheckValidity (uint64_t disk_size, uint64_t disk_block_size)
Checks the validity of the metadata. The underlying device's information is passed in, see
fvm::Header::IsValid(). The defaults for the disk information skips validation of the metadata
relative to these values.
Should be called before serializing the contents to disk.
Defined at line 62 of file ../../src/storage/fvm/metadata.cc
void UpdateHash ()
Updates the hash stored in the metadata, based on its contents.
Defined at line 71 of file ../../src/storage/fvm/metadata.cc
size_t GetInactiveHeaderOffset ()
Returns the disk offset where the metadata should be persisted. This points to the
offset of the *inactive* copy (see |inactive_header()|).
Defined at line 75 of file ../../src/storage/fvm/metadata.cc
void SwitchActiveHeaders ()
Switches whether the Metadata represents an active A or B copy.
Defined at line 79 of file ../../src/storage/fvm/metadata.cc
Header & GetHeader ()
Accesses the header managed by the Metadata instance.
Defined at line 81 of file ../../src/storage/fvm/metadata.cc
VPartitionEntry & GetPartitionEntry (size_t idx)
Accesses the partition table. Note that |idx| is one-based.
Defined at line 85 of file ../../src/storage/fvm/metadata.cc
SuperblockType active_header ()
Returns whether the Metadata represents an active A copy or B copy.
Defined at line 92 of file ../../src/storage/fvm/metadata.h
SuperblockType inactive_header ()
Defined at line 93 of file ../../src/storage/fvm/metadata.h
SliceEntry & GetSliceEntry (size_t idx)
Accesses the allocation table. Note that |idx| is one-based.
Defined at line 98 of file ../../src/storage/fvm/metadata.cc
const MetadataBuffer * Get ()
Gets a view of the raw metadata buffer.
Defined at line 115 of file ../../src/storage/fvm/metadata.cc
zx::result<Metadata> CopyWithNewDimensions (const Header & dimensions)
Creates a copy of this Metadata instance, with additional room described by |dimensions|.
The metadata is not copied verbatim; for instance, which of the A/B copies is active
may change, and old generations may be lost. The only guarantee is that all partition/slice
entries in the active tables will be copied over from this instance.
TODO(jfsulliv): Only fvm/host needs this method, and it is not very graceful. Consider removal.
Defined at line 117 of file ../../src/storage/fvm/metadata.cc