Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ cf_cc_library(
],
)

cf_cc_library(
name = "physical_partitions",
srcs = ["physical_partitions.cc"],
hdrs = ["physical_partitions.h"],
deps = [
"//cuttlefish/host/commands/assemble_cvd/android_build",
"//cuttlefish/result",
],
)

cf_cc_library(
name = "super_image",
srcs = ["super_image.cc"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// Copyright (C) 2025 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "cuttlefish/host/commands/assemble_cvd/android_build/physical_partitions.h"

#include <functional>
#include <memory>
#include <ostream>
#include <set>

#include "cuttlefish/host/commands/assemble_cvd/android_build/android_build.h"
#include "cuttlefish/result/result.h"

namespace cuttlefish {
namespace {

class PhysicalPartitionsImpl : public AndroidBuild {
public:
PhysicalPartitionsImpl(AndroidBuild& build) : build_(build) {}

Result<std::set<std::string, std::less<void>>> PhysicalPartitions() override {
if (auto res = build_.PhysicalPartitions(); res.ok()) {
return *res;
}

std::set<std::string, std::less<void>> partitions =
CF_EXPECT(build_.Images());
for (std::string logical : CF_EXPECT(build_.LogicalPartitions())) {
partitions.erase(logical);
}

if (partitions.count("super_empty")) {
partitions.erase("super_empty");
partitions.insert("super");
}

return partitions;
}

private:
std::ostream& Format(std::ostream& out) const override {
return out << "PhysicalPartitions";
}

AndroidBuild& build_;
};

} // namespace

Result<std::unique_ptr<AndroidBuild>> PhysicalPartitions(AndroidBuild& build) {
auto partitions = std::make_unique<PhysicalPartitionsImpl>(build);

CF_EXPECT(partitions->PhysicalPartitions());

return partitions;
}

} // namespace cuttlefish
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright (C) 2025 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <memory>

#include "cuttlefish/host/commands/assemble_cvd/android_build/android_build.h"
#include "cuttlefish/result/result.h"

namespace cuttlefish {

/**
* Wrap an `AndroidBuild` with fallback physical partition detection logic.
*
* If the `AndroidBuild` does not already provide GPT entry information, this
* makes a best guess based on known logical partitions and image files.
*
* One use case is the android product directory or `m` case, where the build
* system produces a collection of `.img` files including a `super.img`, but no
* explicit list of physical partitions.
*/
Result<std::unique_ptr<AndroidBuild>> PhysicalPartitions(AndroidBuild&);

} // namespace cuttlefish
Loading