rlower_bound initialized closest_logical to 0, so a matching item at
offset 0 never passed the `this_logical > closest_logical` check.
Add a `have_closest` flag so the first match is always accepted.
This caused ref_backward to return null when the previous extent was
at offset 0 in the file, which is the common case for the first
extent of any inode.
This has been subtly breaking subvol scans since the extent scan rework
exposed the bug; however, fixing this still doesn't help subvol scans
work at scale, so they're still deprecated.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
#define BTFRLB_DEBUG(x) CRUCIBLE_BTRFS_TREE_DEBUG(x)
#endif
BtrfsTreeItem closest_item;
+ bool have_closest = false;
uint64_t closest_logical = 0;
BtrfsIoctlSearchKey &sk = m_sk;
size_t loops = 0;
BTFRLB_DEBUG("(" << to_hex(scaled_hdr_logical) << " >= " << to_hex(upper_bound) << ")");
break;
}
- if (this_logical <= logical && this_logical > closest_logical) {
+ if (this_logical <= logical && (!have_closest || this_logical > closest_logical)) {
+ have_closest = true;
closest_logical = this_logical;
closest_item = i;
BTFRLB_DEBUG("(closest)");