ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
return ret;
- /* FIXME: we should be able to handle this */
- if (ret == 0)
- return ret;
+
+ if (unlikely(ret == 0)) {
+ /*
+ * Key with offset -1 found, there would have to exist a dir
+ * index item with such offset, but this is out of the valid
+ * range.
+ */
+ btrfs_err(root->fs_info,
+ "unexpected exact match for DIR_INDEX key, inode %llu",
+ btrfs_ino(inode));
+ return -EUCLEAN;
+ }
if (path->slots[0] == 0) {
inode->index_cnt = BTRFS_DIR_START_INDEX;