Skip to content

Commit fe72870

Browse files
committed
Move ProtectiveMbr to mbr.[cc,h]
Bug: b/435760503
1 parent 002c34b commit fe72870

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ cf_cc_library(
7777

7878
cf_cc_library(
7979
name = "mbr",
80+
srcs = ["mbr.cc"],
8081
hdrs = ["mbr.h"],
8182
)
8283

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@ namespace {
5353

5454
constexpr int GPT_NUM_PARTITIONS = 128;
5555

56-
/**
57-
* Creates a "Protective" MBR Partition Table header. The GUID
58-
* Partition Table Specification recommends putting this on the first sector
59-
* of the disk, to protect against old disk formatting tools from misidentifying
60-
* the GUID Partition Table later and doing the wrong thing.
61-
*/
62-
MasterBootRecord ProtectiveMbr(std::uint64_t size) {
63-
MasterBootRecord mbr = {
64-
.partitions = {{
65-
.partition_type = 0xEE,
66-
.first_lba = 1,
67-
.num_sectors = (std::uint32_t)size / kSectorSize,
68-
}},
69-
.boot_signature = {0x55, 0xAA},
70-
};
71-
return mbr;
72-
}
73-
7456
struct __attribute__((packed)) GptHeader {
7557
std::uint8_t signature[8];
7658
std::uint8_t revision[4];
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2020 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+
#include "cuttlefish/host/libs/image_aggregator/mbr.h"
17+
18+
#include <stdint.h>
19+
20+
namespace cuttlefish {
21+
22+
MasterBootRecord ProtectiveMbr(uint64_t size) {
23+
MasterBootRecord mbr = {
24+
.partitions = {{
25+
.partition_type = 0xEE,
26+
.first_lba = 1,
27+
.num_sectors = (uint32_t)size / kSectorSize,
28+
}},
29+
.boot_signature = {0x55, 0xAA},
30+
};
31+
return mbr;
32+
}
33+
34+
} // namespace cuttlefish

base/cvd/cuttlefish/host/libs/image_aggregator/mbr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ struct __attribute__((packed)) MasterBootRecord {
3939

4040
static_assert(sizeof(MasterBootRecord) == kSectorSize);
4141

42+
/**
43+
* Creates a "Protective" MBR Partition Table header. The GUID
44+
* Partition Table Specification recommends putting this on the first sector
45+
* of the disk, to protect against old disk formatting tools from misidentifying
46+
* the GUID Partition Table later and doing the wrong thing.
47+
*/
48+
MasterBootRecord ProtectiveMbr(uint64_t size);
49+
4250
} // namespace cuttlefish

0 commit comments

Comments
 (0)