summaryrefslogtreecommitdiff
path: root/fs_mgr/liblp/builder.cpp
diff options
context:
space:
mode:
authorSteven Laver <lavers@google.com>2020-04-26 19:23:49 -0700
committerSteven Laver <lavers@google.com>2020-04-26 19:23:49 -0700
commit4ac5a687c56a98bc54783c53d3a7ed38c93c4386 (patch)
tree36ded3563a964ecb44ef7fda3bb373aed83353d8 /fs_mgr/liblp/builder.cpp
parentbe3a52c076b2355e6ef6e4c37e8a2d99310151b5 (diff)
parent60264d77dc3e467004412af972ac5a80e8d12059 (diff)
Merge RP1A.200426.001
Change-Id: Ibf1e9770ee4685621e932873dbbebd97e4b4801a
Diffstat (limited to 'fs_mgr/liblp/builder.cpp')
-rw-r--r--fs_mgr/liblp/builder.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp
index d4964669a6..2f516fa9b9 100644
--- a/fs_mgr/liblp/builder.cpp
+++ b/fs_mgr/liblp/builder.cpp
@@ -40,6 +40,20 @@ bool LinearExtent::AddTo(LpMetadata* out) const {
return true;
}
+bool LinearExtent::OverlapsWith(const LinearExtent& other) const {
+ if (device_index_ != other.device_index()) {
+ return false;
+ }
+ return physical_sector() < other.end_sector() && other.physical_sector() < end_sector();
+}
+
+bool LinearExtent::OverlapsWith(const Interval& interval) const {
+ if (device_index_ != interval.device_index) {
+ return false;
+ }
+ return physical_sector() < interval.end && interval.start < end_sector();
+}
+
Interval LinearExtent::AsInterval() const {
return Interval(device_index(), physical_sector(), end_sector());
}
@@ -774,8 +788,7 @@ std::unique_ptr<LinearExtent> MetadataBuilder::ExtendFinalExtent(
bool MetadataBuilder::IsAnyRegionCovered(const std::vector<Interval>& regions,
const LinearExtent& candidate) const {
for (const auto& region : regions) {
- if (region.device_index == candidate.device_index() &&
- (candidate.OwnsSector(region.start) || candidate.OwnsSector(region.end))) {
+ if (candidate.OverlapsWith(region)) {
return true;
}
}
@@ -786,11 +799,10 @@ bool MetadataBuilder::IsAnyRegionAllocated(const LinearExtent& candidate) const
for (const auto& partition : partitions_) {
for (const auto& extent : partition->extents()) {
LinearExtent* linear = extent->AsLinearExtent();
- if (!linear || linear->device_index() != candidate.device_index()) {
+ if (!linear) {
continue;
}
- if (linear->OwnsSector(candidate.physical_sector()) ||
- linear->OwnsSector(candidate.end_sector() - 1)) {
+ if (linear->OverlapsWith(candidate)) {
return true;
}
}