blob: 1b732aea26ab577fe10f1e45602dada140579d92 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/zx/status.h>
#include <zircon/types.h>
#include <limits>
#include "src/storage/fvm/format.h"
namespace fvm {
// MetadataBuffer is an interface for a buffer that contains FVM metadata.
class MetadataBuffer {
virtual ~MetadataBuffer() = default;
// Creates an uninitialized |MetadataBuffer| which has capacity for at least |size| bytes.
// This is intentionally non-static so inheriting classes can override it to return the
// appropriate type. In general the instance's fields/methods will not be accessed.
virtual std::unique_ptr<MetadataBuffer> Create(size_t size) const = 0;
virtual void* data() const = 0;
virtual size_t size() const = 0;
// HeapMetadataBuffer is an instance of |MetadataBuffer| backed by a heap-allocated buffer.
class HeapMetadataBuffer : public MetadataBuffer {
HeapMetadataBuffer(std::unique_ptr<uint8_t[]> buffer, size_t size);
~HeapMetadataBuffer() override;
std::unique_ptr<MetadataBuffer> Create(size_t size) const override;
void* data() const override { return buffer_.get(); }
size_t size() const override { return size_; }
std::unique_ptr<uint8_t[]> buffer_;
size_t size_;
} // namespace fvm