Skip to content

Commit

Permalink
hfs: fix B-tree corruption after insertion at position 0
Browse files Browse the repository at this point in the history
Fix B-tree corruption when a new record is inserted at position 0 in the
node in hfs_brec_insert().

This is an identical change to the corresponding hfs b-tree code to Sergei
Antonov's "hfsplus: fix B-tree corruption after insertion at position 0",
to keep similar code paths in the hfs and hfsplus drivers in sync, where
appropriate.

Signed-off-by: Hin-Tak Leung <[email protected]>
Cc: Sergei Antonov <[email protected]>
Cc: Joe Perches <[email protected]>
Reviewed-by: Vyacheslav Dubeyko <[email protected]>
Cc: Anton Altaparmakov <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
HinTak authored and torvalds committed Sep 10, 2015
1 parent 7cb74be commit b4cc0ef
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions fs/hfs/brec.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len)
hfs_bnode_write(node, entry, data_off + key_len, entry_len);
hfs_bnode_dump(node);

if (new_node) {
/* update parent key if we inserted a key
* at the start of the first node
*/
if (!rec && new_node != node)
hfs_brec_update_parent(fd);
/*
* update parent key if we inserted a key
* at the start of the node and it is not the new node
*/
if (!rec && new_node != node) {
hfs_bnode_read_key(node, fd->search_key, data_off + size);
hfs_brec_update_parent(fd);
}

if (new_node) {
hfs_bnode_put(fd->bnode);
if (!new_node->parent) {
hfs_btree_inc_height(tree);
Expand Down Expand Up @@ -166,9 +169,6 @@ int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len)
goto again;
}

if (!rec)
hfs_brec_update_parent(fd);

return 0;
}

Expand Down Expand Up @@ -366,6 +366,8 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd)
if (IS_ERR(parent))
return PTR_ERR(parent);
__hfs_brec_find(parent, fd);
if (fd->record < 0)
return -ENOENT;
hfs_bnode_dump(parent);
rec = fd->record;

Expand Down

0 comments on commit b4cc0ef

Please sign in to comment.