diff options
Diffstat (limited to 'fs_mgr/liblp/builder.cpp')
-rw-r--r-- | fs_mgr/liblp/builder.cpp | 22 |
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; } } |