Skip to content

Commit 775e579

Browse files
committed
Reapply "Add pretty-printing for liblp types"
This reverts commit 699b44d. Was fixed by google#2032 Bug: b/476228593
1 parent baf1ce5 commit 775e579

9 files changed

Lines changed: 408 additions & 0 deletions

File tree

base/cvd/cuttlefish/host/commands/assemble_cvd/android_build/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ cf_cc_library(
180180
deps = [
181181
"//cuttlefish/common/libs/fs",
182182
"//cuttlefish/host/commands/assemble_cvd/android_build",
183+
"//cuttlefish/pretty/liblp",
183184
"//cuttlefish/result",
185+
"@abseil-cpp//absl/log",
184186
"@abseil-cpp//absl/strings",
185187
"@android_system_core//:liblp",
186188
"@fmt",

base/cvd/cuttlefish/host/commands/assemble_cvd/android_build/super_image.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <utility>
2828
#include <vector>
2929

30+
#include "absl/log/log.h"
3031
#include "absl/strings/match.h"
3132
#include "absl/strings/str_cat.h"
3233
#include "absl/strings/strip.h"
@@ -35,6 +36,7 @@
3536

3637
#include "cuttlefish/common/libs/fs/shared_fd.h"
3738
#include "cuttlefish/host/commands/assemble_cvd/android_build/android_build.h"
39+
#include "cuttlefish/pretty/liblp/liblp.h"
3840
#include "cuttlefish/result/result.h"
3941

4042
namespace cuttlefish {
@@ -221,6 +223,8 @@ Result<std::unique_ptr<AndroidBuild>> SuperImageAsBuild(AndroidBuild& build) {
221223
std::unique_ptr<android::fs_mgr::LpMetadata> lp_metadata =
222224
CF_EXPECT(SuperImageFromAndroidBuild(build));
223225

226+
VLOG(0) << Pretty(*lp_metadata);
227+
224228
auto super_build =
225229
std::make_unique<SuperImageAsBuildImpl>(build, std::move(lp_metadata));
226230

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
load("//cuttlefish/bazel:rules.bzl", "cf_cc_library")
2+
3+
package(
4+
default_visibility = ["//:android_cuttlefish"],
5+
)
6+
7+
cf_cc_library(
8+
name = "builder",
9+
srcs = ["builder.cc"],
10+
hdrs = ["builder.h"],
11+
deps = [
12+
"//cuttlefish/pretty",
13+
"//cuttlefish/pretty:string",
14+
"//cuttlefish/pretty:struct",
15+
"//cuttlefish/pretty:unique_ptr",
16+
"//cuttlefish/pretty:vector",
17+
"@android_system_core//:liblp",
18+
],
19+
)
20+
21+
cf_cc_library(
22+
name = "liblp",
23+
srcs = ["liblp.cc"],
24+
hdrs = ["liblp.h"],
25+
deps = [
26+
"//cuttlefish/pretty",
27+
"//cuttlefish/pretty:struct",
28+
"//cuttlefish/pretty:vector",
29+
"//cuttlefish/pretty/liblp:metadata_format",
30+
"@android_system_core//:liblp",
31+
],
32+
)
33+
34+
cf_cc_library(
35+
name = "metadata_format",
36+
srcs = ["metadata_format.cc"],
37+
hdrs = ["metadata_format.h"],
38+
deps = [
39+
"//cuttlefish/pretty",
40+
"//cuttlefish/pretty:string",
41+
"//cuttlefish/pretty:struct",
42+
"//cuttlefish/pretty:vector",
43+
"@android_system_core//:liblp",
44+
],
45+
)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//
2+
// Copyright (C) 2026 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/pretty/liblp/builder.h"
17+
18+
#include "liblp/builder.h"
19+
20+
#include "cuttlefish/pretty/pretty.h"
21+
#include "cuttlefish/pretty/string.h"
22+
#include "cuttlefish/pretty/struct.h"
23+
#include "cuttlefish/pretty/unique_ptr.h"
24+
#include "cuttlefish/pretty/vector.h"
25+
26+
namespace cuttlefish {
27+
28+
using android::fs_mgr::Extent;
29+
using android::fs_mgr::ExtentType;
30+
using android::fs_mgr::Interval;
31+
using android::fs_mgr::LinearExtent;
32+
using android::fs_mgr::Partition;
33+
using android::fs_mgr::PartitionGroup;
34+
using android::fs_mgr::ZeroExtent;
35+
36+
PrettyStruct Pretty(const Extent& extent, PrettyAdlPlaceholder) {
37+
switch (extent.GetExtentType()) {
38+
case ExtentType::kZero:
39+
return Pretty(static_cast<const ZeroExtent&>(extent));
40+
case ExtentType::kLinear:
41+
return Pretty(static_cast<const LinearExtent&>(extent));
42+
default:
43+
return PrettyStruct("Extent")
44+
.Member("GetExtentType", extent.GetExtentType())
45+
.Member("num_sectors", extent.num_sectors());
46+
}
47+
}
48+
49+
PrettyStruct Pretty(const LinearExtent& linear_extent, PrettyAdlPlaceholder) {
50+
return PrettyStruct("LinearExtent")
51+
.Member("physical_sector", linear_extent.physical_sector())
52+
.Member("end_sector", linear_extent.end_sector())
53+
.Member("device_index", linear_extent.device_index())
54+
.Member("num_sectors", linear_extent.num_sectors());
55+
}
56+
57+
PrettyStruct Pretty(const ZeroExtent& zero_extent, PrettyAdlPlaceholder) {
58+
return PrettyStruct("ZeroExtent")
59+
.Member("num_sectors", zero_extent.num_sectors());
60+
}
61+
62+
PrettyStruct Pretty(const PartitionGroup& partition_group,
63+
PrettyAdlPlaceholder) {
64+
return PrettyStruct("partition_group")
65+
.Member("name", partition_group.name())
66+
.Member("maximum_size", partition_group.maximum_size());
67+
}
68+
69+
PrettyStruct Pretty(const Partition& partition, PrettyAdlPlaceholder) {
70+
return PrettyStruct("Partition")
71+
.Member("BytesOnDisk", partition.BytesOnDisk())
72+
.Member("name", partition.name())
73+
.Member("group_name", partition.group_name())
74+
.Member("attributes", partition.attributes())
75+
.Member("extents", partition.extents())
76+
.Member("size", partition.size());
77+
}
78+
79+
PrettyStruct Pretty(const Interval& interval, PrettyAdlPlaceholder) {
80+
return PrettyStruct("Interval")
81+
.Member("device_index", interval.device_index)
82+
.Member("start", interval.start)
83+
.Member("end", interval.end);
84+
}
85+
86+
} // namespace cuttlefish
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Copyright (C) 2026 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 "liblp/builder.h"
19+
20+
#include "cuttlefish/pretty/pretty.h"
21+
#include "cuttlefish/pretty/struct.h"
22+
23+
namespace cuttlefish {
24+
25+
PrettyStruct Pretty(const android::fs_mgr::Extent&,
26+
PrettyAdlPlaceholder unused = PrettyAdlPlaceholder());
27+
28+
PrettyStruct Pretty(const android::fs_mgr::LinearExtent&,
29+
PrettyAdlPlaceholder unused = PrettyAdlPlaceholder());
30+
31+
PrettyStruct Pretty(const android::fs_mgr::ZeroExtent&,
32+
PrettyAdlPlaceholder unused = PrettyAdlPlaceholder());
33+
34+
PrettyStruct Pretty(const android::fs_mgr::PartitionGroup&,
35+
PrettyAdlPlaceholder unused = PrettyAdlPlaceholder());
36+
37+
PrettyStruct Pretty(const android::fs_mgr::Partition&,
38+
PrettyAdlPlaceholder unused = PrettyAdlPlaceholder());
39+
40+
PrettyStruct Pretty(const android::fs_mgr::Interval&,
41+
PrettyAdlPlaceholder unused = PrettyAdlPlaceholder());
42+
43+
} // namespace cuttlefish
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright (C) 2026 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/pretty/liblp/liblp.h"
17+
18+
#include "liblp/liblp.h"
19+
20+
#include "cuttlefish/pretty/liblp/metadata_format.h"
21+
#include "cuttlefish/pretty/pretty.h"
22+
#include "cuttlefish/pretty/struct.h"
23+
#include "cuttlefish/pretty/vector.h"
24+
25+
namespace cuttlefish {
26+
27+
PrettyStruct Pretty(const android::fs_mgr::LpMetadata& metadata,
28+
PrettyAdlPlaceholder) {
29+
return PrettyStruct("LpMetadata")
30+
.Member("geometry", metadata.geometry)
31+
.Member("header", metadata.header)
32+
.Member("partitions", metadata.partitions)
33+
.Member("extents", metadata.extents)
34+
.Member("groups", metadata.groups)
35+
.Member("block_devices", metadata.block_devices);
36+
}
37+
38+
} // namespace cuttlefish
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Copyright (C) 2026 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 "liblp/liblp.h"
19+
20+
#include "cuttlefish/pretty/pretty.h"
21+
#include "cuttlefish/pretty/struct.h"
22+
23+
namespace cuttlefish {
24+
25+
PrettyStruct Pretty(const android::fs_mgr::LpMetadata&,
26+
PrettyAdlPlaceholder unused = PrettyAdlPlaceholder());
27+
28+
} // namespace cuttlefish
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
//
2+
// Copyright (C) 2026 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/pretty/liblp/metadata_format.h"
17+
18+
#include "liblp/liblp.h"
19+
#include "liblp/metadata_format.h"
20+
21+
#include "cuttlefish/pretty/pretty.h"
22+
#include "cuttlefish/pretty/string.h"
23+
#include "cuttlefish/pretty/struct.h"
24+
#include "cuttlefish/pretty/vector.h"
25+
26+
namespace cuttlefish {
27+
28+
PrettyStruct Pretty(const LpMetadataGeometry& geometry, PrettyAdlPlaceholder) {
29+
std::vector<uint8_t> checksum(
30+
geometry.checksum,
31+
geometry.checksum + (sizeof(geometry.checksum) / sizeof(uint8_t)));
32+
return PrettyStruct("LpMetadataGeometry")
33+
.Member("magic", geometry.magic)
34+
.Member("struct_size", geometry.struct_size)
35+
.Member("checksum", checksum)
36+
.Member("metadata_max_size", geometry.metadata_max_size)
37+
.Member("metadata_slot_count", geometry.metadata_slot_count)
38+
.Member("logical_block_size", geometry.logical_block_size);
39+
}
40+
41+
PrettyStruct Pretty(const LpMetadataTableDescriptor& metadata_table_descriptor,
42+
PrettyAdlPlaceholder) {
43+
return PrettyStruct("LpMetadataTableDescriptor")
44+
.Member("offset", metadata_table_descriptor.offset)
45+
.Member("num_entries", metadata_table_descriptor.num_entries)
46+
.Member("entry_size", metadata_table_descriptor.entry_size);
47+
}
48+
49+
PrettyStruct Pretty(const LpMetadataHeader& metadata_header,
50+
PrettyAdlPlaceholder) {
51+
std::vector<uint8_t> header_checksum(
52+
metadata_header.header_checksum,
53+
metadata_header.header_checksum +
54+
(sizeof(metadata_header.header_checksum) / sizeof(uint8_t)));
55+
std::vector<uint8_t> tables_checksum(
56+
metadata_header.tables_checksum,
57+
metadata_header.tables_checksum +
58+
(sizeof(metadata_header.tables_checksum) / sizeof(uint8_t)));
59+
return PrettyStruct("LpMetadataHeader")
60+
.Member("magic", metadata_header.magic)
61+
.Member("major_version", metadata_header.major_version)
62+
.Member("minor_version", metadata_header.minor_version)
63+
.Member("header_size", metadata_header.header_size)
64+
.Member("header_checksum", header_checksum)
65+
.Member("tables_size", metadata_header.tables_size)
66+
.Member("tables_checksum", tables_checksum)
67+
.Member("partitions", metadata_header.partitions)
68+
.Member("extents", metadata_header.extents)
69+
.Member("groups", metadata_header.groups)
70+
.Member("block_devices", metadata_header.block_devices)
71+
.Member("flags", metadata_header.flags);
72+
}
73+
74+
PrettyStruct Pretty(const LpMetadataPartition& metadata_partition,
75+
PrettyAdlPlaceholder) {
76+
return PrettyStruct("LpMetadataPartition")
77+
.Member("name", android::fs_mgr::GetPartitionName(metadata_partition))
78+
.Member("attributes", metadata_partition.attributes)
79+
.Member("first_extent_index", metadata_partition.first_extent_index)
80+
.Member("num_extents", metadata_partition.num_extents)
81+
.Member("group_index", metadata_partition.group_index);
82+
}
83+
84+
PrettyStruct Pretty(const LpMetadataExtent& metadata_extent,
85+
PrettyAdlPlaceholder) {
86+
return PrettyStruct("LpMetadataExtent")
87+
.Member("num_sectors", metadata_extent.num_sectors)
88+
.Member("target_type", metadata_extent.target_type)
89+
.Member("target_data", metadata_extent.target_data)
90+
.Member("target_source", metadata_extent.target_source);
91+
}
92+
93+
PrettyStruct Pretty(const LpMetadataPartitionGroup& metadata_partition_group,
94+
PrettyAdlPlaceholder) {
95+
return PrettyStruct("LpMetadataPartitionGroup")
96+
.Member("name",
97+
android::fs_mgr::GetPartitionGroupName(metadata_partition_group))
98+
.Member("flags", metadata_partition_group.flags)
99+
.Member("maximum_size", metadata_partition_group.maximum_size);
100+
}
101+
102+
PrettyStruct Pretty(const LpMetadataBlockDevice& block_device,
103+
PrettyAdlPlaceholder) {
104+
std::string_view partition_name(
105+
block_device.partition_name,
106+
sizeof(block_device.partition_name) / sizeof(char));
107+
return PrettyStruct("LpMetadataBlockDevice")
108+
.Member("first_logical_sector", block_device.first_logical_sector)
109+
.Member("alignment", block_device.alignment)
110+
.Member("alignment_offset", block_device.alignment_offset)
111+
.Member("size", block_device.size)
112+
.Member("partition_name", partition_name)
113+
.Member("flags", block_device.flags);
114+
}
115+
116+
} // namespace cuttlefish

0 commit comments

Comments
 (0)