diff mbox

[v3] UBIFS: fix master node recovery

Message ID 1310034302-9201-1-git-send-email-agust@denx.de
State Accepted
Commit 19495f70d1ebcdc732dd3c94f5968a4bff198ae5
Headers show

Commit Message

Anatolij Gustschin July 7, 2011, 10:25 a.m. UTC
When the 1st LEB was unmapped and written but 2nd LEB not,
the master node recovery doesn't succeed after power cut.
We see following error when mounting UBIFS partition on NOR
flash:

UBIFS error (pid 1137): ubifs_recover_master_node: failed to recover master node

Correct 2nd master node offset check is needed to fix the
problem. If the 2nd master node is at the end in the 2nd LEB,
first master node is used for recovery. When checking for this
condition we should check whether the master node is exactly at
the end of the LEB (without remaining empty space) or whether
it is followed by an empty space less than the master node size.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
---
v3:
  - drop unneeded brackets

v2:
  - drop incorrect check
  - revise commit description

 fs/ubifs/recovery.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Comments

Artem Bityutskiy July 8, 2011, 3:55 a.m. UTC | #1
On Thu, 2011-07-07 at 12:25 +0200, Anatolij Gustschin wrote:
> When the 1st LEB was unmapped and written but 2nd LEB not,
> the master node recovery doesn't succeed after power cut.
> We see following error when mounting UBIFS partition on NOR
> flash:
> 
> UBIFS error (pid 1137): ubifs_recover_master_node: failed to recover master node
> 
> Correct 2nd master node offset check is needed to fix the
> problem. If the 2nd master node is at the end in the 2nd LEB,
> first master node is used for recovery. When checking for this
> condition we should check whether the master node is exactly at
> the end of the LEB (without remaining empty space) or whether
> it is followed by an empty space less than the master node size.
> 
> Signed-off-by: Anatolij Gustschin <agust@denx.de>

Pushed, thanks for fixing this!
diff mbox

Patch

diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index 783d8e0..9820903 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -274,7 +274,8 @@  int ubifs_recover_master_node(struct ubifs_info *c)
 				if (cor1)
 					goto out_err;
 				mst = mst1;
-			} else if (offs1 == 0 && offs2 + sz >= c->leb_size) {
+			} else if (offs1 == 0 &&
+				   c->leb_size - offs2 - sz < sz) {
 				/* 1st LEB was unmapped and written, 2nd not */
 				if (cor1)
 					goto out_err;