summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Mills <hugo@carfax.org.uk>2014-05-05 18:07:49 +0100
committerDavid Sterba <dsterba@suse.cz>2014-08-22 14:43:10 +0200
commitb5fc0b90144c37532f68839f36be08e05c0767bf (patch)
tree31d9c1dbd14c582e529003f466cc1ea2e79839bc
parent8efdd3ca4cbeaf51908f04ba9ea1fb689a30241f (diff)
btrfs-progs: check: Fix wrong level access
There's no reason to assume that the bad key order is in a leaf block, so accessing level 0 of the path is going to be an error if it's actually a node block that's bad. Reported-by: Chris Mason <clm@fb.com> Signed-off-by: Hugo Mills <hugo@carfax.org.uk> Signed-off-by: David Sterba <dsterba@suse.cz>
-rw-r--r--cmds-check.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/cmds-check.c b/cmds-check.c
index da94079c..df4af9a1 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -2418,6 +2418,7 @@ static int try_to_fix_bad_block(struct btrfs_trans_handle *trans,
struct btrfs_path *path;
struct btrfs_key k1, k2;
int i;
+ int level;
int ret;
if (status != BTRFS_TREE_BLOCK_BAD_KEY_ORDER)
@@ -2435,9 +2436,10 @@ static int try_to_fix_bad_block(struct btrfs_trans_handle *trans,
if (!path)
return -EIO;
- path->lowest_level = btrfs_header_level(buf);
+ level = btrfs_header_level(buf);
+ path->lowest_level = level;
path->skip_check_block = 1;
- if (btrfs_header_level(buf))
+ if (level)
btrfs_node_key_to_cpu(buf, &k1, 0);
else
btrfs_item_key_to_cpu(buf, &k1, 0);
@@ -2448,9 +2450,9 @@ static int try_to_fix_bad_block(struct btrfs_trans_handle *trans,
return -EIO;
}
- buf = path->nodes[0];
+ buf = path->nodes[level];
for (i = 0; i < btrfs_header_nritems(buf) - 1; i++) {
- if (btrfs_header_level(buf)) {
+ if (level) {
btrfs_node_key_to_cpu(buf, &k1, i);
btrfs_node_key_to_cpu(buf, &k2, i + 1);
} else {