Skip to content

Commit

Permalink
UBIFS: fix corruption dump
Browse files Browse the repository at this point in the history
In the 'ubifs_recover_leb()' function, when we find corrupted
empty space, we dump 8K starting from the offset where the last
node ends. This is OK if the corrupted empty space is somewhere
near that offset. But if the corruption is far at the end of the
LEB, we will dump all 0xFF bytes and complitely ignore the
interesting data. This is observed on a PPC ("kilauea") with
NOR flash.

This patch changes the behavior and teaches UBIFS to print only
interesting data. I.e., now we find where corruption starts and
start dumping from that offset.

Signed-off-by: Artem Bityutskiy <[email protected]>
Reviewed-by: Adrian Hunter <[email protected]>
  • Loading branch information
Artem Bityutskiy authored and Artem Bityutskiy committed Jul 9, 2009
1 parent 431102f commit 0611254
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions fs/ubifs/recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ static int is_empty(void *buf, int len)
return 1;
}

/**
* first_non_ff - find offset of the first non-0xff byte.
* @buf: buffer to search in
* @len: length of buffer
*
* This function returns offset of the first non-0xff byte in @buf or %-1 if
* the buffer contains only 0xff bytes.
*/
static int first_non_ff(void *buf, int len)
{
uint8_t *p = buf;
int i;

for (i = 0; i < len; i++)
if (*p++ != 0xff)
return i;
return -1;
}

/**
* get_master_node - get the last valid master node allowing for corruption.
* @c: UBIFS file-system description object
Expand Down Expand Up @@ -649,8 +668,13 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
clean_buf(c, &buf, lnum, &offs, &len);
need_clean = 1;
} else {
ubifs_err("corrupt empty space at LEB %d:%d",
lnum, offs);
int corruption = first_non_ff(buf, len);

ubifs_err("corrupt empty space LEB %d:%d, corruption "
"starts at %d", lnum, offs, corruption);
/* Make sure we dump interesting non-0xFF data */
offs = corruption;
buf += corruption;
goto corrupted;
}
}
Expand Down

0 comments on commit 0611254

Please sign in to comment.