Skip to content

Commit b4cc0ef

Browse files
HinTaktorvalds
authored andcommitted
hfs: fix B-tree corruption after insertion at position 0
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 <htl10@users.sourceforge.net> Cc: Sergei Antonov <saproj@gmail.com> Cc: Joe Perches <joe@perches.com> Reviewed-by: Vyacheslav Dubeyko <slava@dubeyko.com> Cc: Anton Altaparmakov <anton@tuxera.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christoph Hellwig <hch@infradead.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7cb74be commit b4cc0ef

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎fs/hfs/brec.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,16 @@ int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len)
131131
hfs_bnode_write(node, entry, data_off + key_len, entry_len);
132132
hfs_bnode_dump(node);
133133

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

143+
if (new_node) {
141144
hfs_bnode_put(fd->bnode);
142145
if (!new_node->parent) {
143146
hfs_btree_inc_height(tree);
@@ -166,9 +169,6 @@ int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len)
166169
goto again;
167170
}
168171

169-
if (!rec)
170-
hfs_brec_update_parent(fd);
171-
172172
return 0;
173173
}
174174

@@ -366,6 +366,8 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd)
366366
if (IS_ERR(parent))
367367
return PTR_ERR(parent);
368368
__hfs_brec_find(parent, fd);
369+
if (fd->record < 0)
370+
return -ENOENT;
369371
hfs_bnode_dump(parent);
370372
rec = fd->record;
371373

0 commit comments

Comments
 (0)