linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hin-Tak Leung <hintak.leung@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: Hin-Tak Leung <htl10@users.sourceforge.net>,
	Sergei Antonov <saproj@gmail.com>, Joe Perches <joe@perches.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] hfs: fix B-tree corruption after insertion at position 0
Date: Sun, 28 Jun 2015 02:39:30 +0100	[thread overview]
Message-ID: <1435455570-8577-3-git-send-email-HinTak.Leung@gmail.com> (raw)
In-Reply-To: <1435455570-8577-1-git-send-email-HinTak.Leung@gmail.com>

From: Hin-Tak Leung <htl10@users.sourceforge.net>

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>
Anton Altaparmakov <anton@tuxera.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 fs/hfs/brec.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c
index 9f4ee7f..6fc766d 100644
--- a/fs/hfs/brec.c
+++ b/fs/hfs/brec.c
@@ -131,13 +131,16 @@ skip:
 	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);
@@ -166,9 +169,6 @@ skip:
 		goto again;
 	}
 
-	if (!rec)
-		hfs_brec_update_parent(fd);
-
 	return 0;
 }
 
@@ -366,6 +366,8 @@ again:
 	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;
 
-- 
2.4.3


      parent reply	other threads:[~2015-06-28  1:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-28  1:39 [PATCH 0/2] two patches about B-tree corruptions in hfs and hfsplus Hin-Tak Leung
2015-06-28  1:39 ` [PATCH v2] hfs,hfsplus: cache pages correctly between bnode_create and bnode_free Hin-Tak Leung
2015-06-28 18:52   ` Sergei Antonov
2015-06-30 15:40     ` Hin-Tak Leung
2015-07-01 16:09       ` Sergei Antonov
2015-07-01 23:24         ` Hin-Tak Leung
2015-07-02 17:04           ` Sergei Antonov
2015-07-02 18:02             ` Hin-Tak Leung
2015-07-07 22:19               ` Andrew Morton
2015-07-07 23:19                 ` Sergei Antonov
2015-07-08 14:58                 ` Sergei Antonov
2015-07-08 15:29                   ` Hin-Tak Leung
2015-08-03 13:33                 ` Luc Pionchon
2015-06-30 15:55   ` Fwd: " Hin-Tak Leung
     [not found]     ` <CABbL6oanheE9JAwevN8Mrf-5o=y-e7JV2Nt4VW_-iW9Pt3jQuQ@mail.gmail.com>
     [not found]       ` <CABbL6oZ2vQsU9xG+vh_GkmfHHdcZvSYPcZYjUpnZq-r3b_HjPQ@mail.gmail.com>
2015-07-01 23:29         ` Hin-Tak Leung
2015-06-28  1:39 ` Hin-Tak Leung [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435455570-8577-3-git-send-email-HinTak.Leung@gmail.com \
    --to=hintak.leung@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=htl10@users.sourceforge.net \
    --cc=joe@perches.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=saproj@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).