Android-cuttlefish cvd tool
gpt.h
Go to the documentation of this file.
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 <stdint.h>
19
22
23namespace cuttlefish {
24
25constexpr int GPT_NUM_PARTITIONS = 128;
26
27struct __attribute__((packed)) GptHeader {
28 uint8_t signature[8];
29 uint8_t revision[4];
30 uint32_t header_size;
31 uint32_t header_crc32;
32 uint32_t reserved;
33 uint64_t current_lba;
34 uint64_t backup_lba;
35 uint64_t first_usable_lba;
36 uint64_t last_usable_lba;
37 uint8_t disk_guid[16];
38 uint64_t partition_entries_lba;
39 uint32_t num_partition_entries;
40 uint32_t partition_entry_size;
41 uint32_t partition_entries_crc32;
42};
43
44static_assert(sizeof(GptHeader) == 92);
45
46struct __attribute__((packed)) GptPartitionEntry {
47 uint8_t partition_type_guid[16];
48 uint8_t unique_partition_guid[16];
49 uint64_t first_lba;
50 uint64_t last_lba;
51 uint64_t attributes;
52 uint16_t partition_name[36]; // UTF-16LE
53};
54
55static_assert(sizeof(GptPartitionEntry) == 128);
56
57struct __attribute__((packed)) GptBeginning {
58 MasterBootRecord protective_mbr;
59 GptHeader header;
60 uint8_t header_padding[kSectorSize - sizeof(GptHeader)];
61 GptPartitionEntry entries[GPT_NUM_PARTITIONS];
62 uint8_t partition_alignment[3072];
63};
64
65static_assert(AlignToPowerOf2(sizeof(GptBeginning), PARTITION_SIZE_SHIFT) ==
66 sizeof(GptBeginning));
67
68struct __attribute__((packed)) GptEnd {
69 GptPartitionEntry entries[GPT_NUM_PARTITIONS];
70 GptHeader footer;
71 uint8_t footer_padding[kSectorSize - sizeof(GptHeader)];
72};
73
74static_assert(sizeof(GptEnd) % kSectorSize == 0);
75
76} // namespace cuttlefish
ResponseHeader header
Definition: incremental_server.cpp:0
Definition: alloc_utils.cpp:23
constexpr int GPT_NUM_PARTITIONS
Definition: gpt.h:25
struct __attribute__((__packed__)) tpm_message_header
Definition: in_process_tpm.cpp:50
constexpr int PARTITION_SIZE_SHIFT
Definition: size_utils.h:26
constexpr int kSectorSize
Definition: mbr.h:23
constexpr uint64_t AlignToPowerOf2(uint64_t val, uint8_t align_log)
Definition: size_utils.h:29