Skip to content

Commit 81ff1f9

Browse files
committed
Extract GPT types from image_aggregator.cc
Bug: b/436625775
1 parent 63c9518 commit 81ff1f9

3 files changed

Lines changed: 87 additions & 51 deletions

File tree

base/cvd/cuttlefish/host/libs/image_aggregator/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ cf_cc_library(
3434
],
3535
)
3636

37+
cf_cc_library(
38+
name = "gpt",
39+
hdrs = ["gpt.h"],
40+
deps = [
41+
"//cuttlefish/common/libs/utils:size_utils",
42+
"//cuttlefish/host/libs/image_aggregator:mbr",
43+
],
44+
)
45+
3746
cf_cc_library(
3847
name = "image_from_file",
3948
srcs = ["image_from_file.cc"],
@@ -65,6 +74,7 @@ cf_cc_library(
6574
"//cuttlefish/common/libs/utils:subprocess",
6675
"//cuttlefish/host/libs/image_aggregator:cdisk_spec_cc_proto",
6776
"//cuttlefish/host/libs/image_aggregator:composite_disk",
77+
"//cuttlefish/host/libs/image_aggregator:gpt",
6878
"//cuttlefish/host/libs/image_aggregator:image_from_file",
6979
"//cuttlefish/host/libs/image_aggregator:mbr",
7080
"//cuttlefish/host/libs/image_aggregator:sparse_image",
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

base/cvd/cuttlefish/host/libs/image_aggregator/image_aggregator.cc

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -44,64 +44,14 @@
4444
#include "cuttlefish/common/libs/utils/size_utils.h"
4545
#include "cuttlefish/host/libs/image_aggregator/cdisk_spec.pb.h"
4646
#include "cuttlefish/host/libs/image_aggregator/composite_disk.h"
47+
#include "cuttlefish/host/libs/image_aggregator/gpt.h"
4748
#include "cuttlefish/host/libs/image_aggregator/image_from_file.h"
4849
#include "cuttlefish/host/libs/image_aggregator/mbr.h"
4950
#include "cuttlefish/host/libs/image_aggregator/sparse_image.h"
5051

5152
namespace cuttlefish {
5253
namespace {
5354

54-
constexpr int GPT_NUM_PARTITIONS = 128;
55-
56-
struct __attribute__((packed)) GptHeader {
57-
std::uint8_t signature[8];
58-
std::uint8_t revision[4];
59-
std::uint32_t header_size;
60-
std::uint32_t header_crc32;
61-
std::uint32_t reserved;
62-
std::uint64_t current_lba;
63-
std::uint64_t backup_lba;
64-
std::uint64_t first_usable_lba;
65-
std::uint64_t last_usable_lba;
66-
std::uint8_t disk_guid[16];
67-
std::uint64_t partition_entries_lba;
68-
std::uint32_t num_partition_entries;
69-
std::uint32_t partition_entry_size;
70-
std::uint32_t partition_entries_crc32;
71-
};
72-
73-
static_assert(sizeof(GptHeader) == 92);
74-
75-
struct __attribute__((packed)) GptPartitionEntry {
76-
std::uint8_t partition_type_guid[16];
77-
std::uint8_t unique_partition_guid[16];
78-
std::uint64_t first_lba;
79-
std::uint64_t last_lba;
80-
std::uint64_t attributes;
81-
std::uint16_t partition_name[36]; // UTF-16LE
82-
};
83-
84-
static_assert(sizeof(GptPartitionEntry) == 128);
85-
86-
struct __attribute__((packed)) GptBeginning {
87-
MasterBootRecord protective_mbr;
88-
GptHeader header;
89-
std::uint8_t header_padding[kSectorSize - sizeof(GptHeader)];
90-
GptPartitionEntry entries[GPT_NUM_PARTITIONS];
91-
std::uint8_t partition_alignment[3072];
92-
};
93-
94-
static_assert(AlignToPowerOf2(sizeof(GptBeginning), PARTITION_SIZE_SHIFT) ==
95-
sizeof(GptBeginning));
96-
97-
struct __attribute__((packed)) GptEnd {
98-
GptPartitionEntry entries[GPT_NUM_PARTITIONS];
99-
GptHeader footer;
100-
std::uint8_t footer_padding[kSectorSize - sizeof(GptHeader)];
101-
};
102-
103-
static_assert(sizeof(GptEnd) % kSectorSize == 0);
104-
10555
struct PartitionInfo {
10656
ImagePartition source;
10757
std::uint64_t size;

0 commit comments

Comments
 (0)