//
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// A subset of system/update_engine/update_metadata.proto. A separate file is
// used here because:
// - The original file is optimized for LITE_RUNTIME, but fuzzing needs
// reflection.
// - The definition here has less fields. libsnapshot only uses fields declared
// here, and all fields declared here are fuzzed by libsnapshot_fuzzer. If
// libsnapshot uses more fields in system/update_engine/update_metadata.proto
// in the future, they must be added here too, otherwise it will fail to
// compile.
//
// It is okay that this file is older than
// system/update_engine/update_metadata.proto as long as the messages defined
// here can also be parsed by protobuf defined there. However, it is not
// okay to add fields here without adding them to
// system/update_engine/update_metadata.proto. Doing so will cause a compiler
// error when libsnapshot code starts to use these dangling fields.

syntax = "proto2";

package chromeos_update_engine;

message Extent {
    optional uint64 start_block = 1;
    optional uint64 num_blocks = 2;
}

message PartitionInfo {
    optional uint64 size = 1;
}

message InstallOperation {
    enum Type {
        SOURCE_COPY = 4;
        // Not used by libsnapshot. Declared here so that the fuzzer has an
        // alternative value to use for |type|.
        ZERO = 6;
    }
    required Type type = 1;
    repeated Extent src_extents = 4;
    repeated Extent dst_extents = 6;
}

message PartitionUpdate {
    required string partition_name = 1;
    optional PartitionInfo new_partition_info = 7;
    repeated InstallOperation operations = 8;
    optional Extent hash_tree_extent = 11;
    optional Extent fec_extent = 15;
    optional uint64 estimate_cow_size = 19;
}

message DynamicPartitionGroup {
    required string name = 1;
    optional uint64 size = 2;
    repeated string partition_names = 3;
}

message DynamicPartitionMetadata {
    repeated DynamicPartitionGroup groups = 1;
    optional bool vabc_enabled = 3;
}

message DeltaArchiveManifest {
    repeated PartitionUpdate partitions = 13;
    optional DynamicPartitionMetadata dynamic_partition_metadata = 15;
    optional bool partial_update = 16;
}
