1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5library fuchsia.hardware.skipblock;
6
7using zx;
8
9// Matches the value of ZBI_PARTITION_GUID_LEN.
10const uint32 GUID_LEN = 16;
11
12struct PartitionInfo {
13    /// Partition type GUID.
14    array<uint8>:GUID_LEN partition_guid;
15    /// Describes the read/write size.
16    uint64 block_size_bytes;
17    /// Describes size of partition in terms of blocks.
18    uint32 partition_block_count;
19};
20
21struct ReadWriteOperation {
22    /// Memory object describing buffer to read into or write from.
23    handle<vmo> vmo;
24    /// VMO offset in bytes.
25    uint64 vmo_offset;
26    /// Block # to begin operation from.
27    uint32 block;
28    /// Number of blocks to read or write.
29    uint32 block_count;
30};
31
32[Layout = "Simple"]
33interface SkipBlock {
34    /// Returns information about the skip-block partition.
35    ///
36    /// The block count can shrink in the event that a bad block is grown. It is
37    /// recommended to call this again after a bad block is grown.
38    1: GetPartitionInfo() -> (zx.status status, PartitionInfo partition_info);
39
40    /// Reads the specified blocks into the provided vmo.
41    2: Read(ReadWriteOperation op) -> (zx.status status);
42
43    /// Erases and writes the specified blocks from the provided vmo.
44    ///
45    /// In the event that bad block is grown, the partition will shrink and
46    /// |bad_block_grown| will be set to true. Since this causes the logical to
47    /// physical block map to change, all previously written blocks at logical
48    /// addresses after the section being written should be considered corrupted,
49    /// and rewritten if applicable.
50    3: Write(ReadWriteOperation op) -> (zx.status status, bool bad_block_grown);
51};
52