|
| 1 | +/* |
| 2 | + * Copyright (C) 2019 The Android Open Source Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#pragma once |
| 17 | + |
| 18 | +#include <cstdint> |
| 19 | + |
| 20 | +#include "cuttlefish/common/libs/utils/size_utils.h" |
| 21 | +#include "cuttlefish/host/libs/image_aggregator/mbr.h" |
| 22 | + |
| 23 | +namespace cuttlefish { |
| 24 | + |
| 25 | +constexpr int GPT_NUM_PARTITIONS = 128; |
| 26 | + |
| 27 | +struct __attribute__((packed)) GptHeader { |
| 28 | + std::uint8_t signature[8]; |
| 29 | + std::uint8_t revision[4]; |
| 30 | + std::uint32_t header_size; |
| 31 | + std::uint32_t header_crc32; |
| 32 | + std::uint32_t reserved; |
| 33 | + std::uint64_t current_lba; |
| 34 | + std::uint64_t backup_lba; |
| 35 | + std::uint64_t first_usable_lba; |
| 36 | + std::uint64_t last_usable_lba; |
| 37 | + std::uint8_t disk_guid[16]; |
| 38 | + std::uint64_t partition_entries_lba; |
| 39 | + std::uint32_t num_partition_entries; |
| 40 | + std::uint32_t partition_entry_size; |
| 41 | + std::uint32_t partition_entries_crc32; |
| 42 | +}; |
| 43 | + |
| 44 | +static_assert(sizeof(GptHeader) == 92); |
| 45 | + |
| 46 | +struct __attribute__((packed)) GptPartitionEntry { |
| 47 | + std::uint8_t partition_type_guid[16]; |
| 48 | + std::uint8_t unique_partition_guid[16]; |
| 49 | + std::uint64_t first_lba; |
| 50 | + std::uint64_t last_lba; |
| 51 | + std::uint64_t attributes; |
| 52 | + std::uint16_t partition_name[36]; // UTF-16LE |
| 53 | +}; |
| 54 | + |
| 55 | +static_assert(sizeof(GptPartitionEntry) == 128); |
| 56 | + |
| 57 | +struct __attribute__((packed)) GptBeginning { |
| 58 | + MasterBootRecord protective_mbr; |
| 59 | + GptHeader header; |
| 60 | + std::uint8_t header_padding[kSectorSize - sizeof(GptHeader)]; |
| 61 | + GptPartitionEntry entries[GPT_NUM_PARTITIONS]; |
| 62 | + std::uint8_t partition_alignment[3072]; |
| 63 | +}; |
| 64 | + |
| 65 | +static_assert(AlignToPowerOf2(sizeof(GptBeginning), PARTITION_SIZE_SHIFT) == |
| 66 | + sizeof(GptBeginning)); |
| 67 | + |
| 68 | +struct __attribute__((packed)) GptEnd { |
| 69 | + GptPartitionEntry entries[GPT_NUM_PARTITIONS]; |
| 70 | + GptHeader footer; |
| 71 | + std::uint8_t footer_padding[kSectorSize - sizeof(GptHeader)]; |
| 72 | +}; |
| 73 | + |
| 74 | +static_assert(sizeof(GptEnd) % kSectorSize == 0); |
| 75 | + |
| 76 | +} // namespace cuttlefish |
0 commit comments