UBIFS: small amendments in the LEB scanning code
This patch fixes few minor things I've spotted while going through code: 1. Better document return codes 2. If 'ubifs_scan_a_node()' returns some thing we do not expect, treat this as an error. 3. Try to do recovery only when 'ubifs_scan()' returns %-EUCLEAN, not on any error. 4. If empty space starts at a non-aligned address, print a message. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Reviewed-by: Adrian Hunter <Adrian.Hunter@nokia.com>
This commit is contained in:
parent
086b3640c1
commit
ed43f2f06c
3 changed files with 17 additions and 11 deletions
|
@ -543,8 +543,8 @@ static int drop_incomplete_group(struct ubifs_scan_leb *sleb, int *offs)
|
||||||
*
|
*
|
||||||
* This function does a scan of a LEB, but caters for errors that might have
|
* This function does a scan of a LEB, but caters for errors that might have
|
||||||
* been caused by the unclean unmount from which we are attempting to recover.
|
* been caused by the unclean unmount from which we are attempting to recover.
|
||||||
*
|
* Returns %0 in case of success, %-EUCLEAN if an unrecoverable corruption is
|
||||||
* This function returns %0 on success and a negative error code on failure.
|
* found, and a negative error code in case of failure.
|
||||||
*/
|
*/
|
||||||
struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
|
struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
|
||||||
int offs, void *sbuf, int grouped)
|
int offs, void *sbuf, int grouped)
|
||||||
|
@ -643,7 +643,8 @@ struct ubifs_scan_leb *ubifs_recover_leb(struct ubifs_info *c, int lnum,
|
||||||
goto corrupted;
|
goto corrupted;
|
||||||
default:
|
default:
|
||||||
dbg_err("unknown");
|
dbg_err("unknown");
|
||||||
goto corrupted;
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -837,9 +837,10 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf)
|
||||||
|
|
||||||
dbg_mnt("replay log LEB %d:%d", lnum, offs);
|
dbg_mnt("replay log LEB %d:%d", lnum, offs);
|
||||||
sleb = ubifs_scan(c, lnum, offs, sbuf);
|
sleb = ubifs_scan(c, lnum, offs, sbuf);
|
||||||
if (IS_ERR(sleb)) {
|
if (IS_ERR(sleb) ) {
|
||||||
if (c->need_recovery)
|
if (PTR_ERR(sleb) != -EUCLEAN || !c->need_recovery)
|
||||||
sleb = ubifs_recover_log_leb(c, lnum, offs, sbuf);
|
return PTR_ERR(sleb);
|
||||||
|
sleb = ubifs_recover_log_leb(c, lnum, offs, sbuf);
|
||||||
if (IS_ERR(sleb))
|
if (IS_ERR(sleb))
|
||||||
return PTR_ERR(sleb);
|
return PTR_ERR(sleb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,9 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
|
||||||
* @sbuf: scan buffer (must be c->leb_size)
|
* @sbuf: scan buffer (must be c->leb_size)
|
||||||
*
|
*
|
||||||
* This function scans LEB number @lnum and returns complete information about
|
* This function scans LEB number @lnum and returns complete information about
|
||||||
* its contents. Returns an error code in case of failure.
|
* its contents. Returns the scaned information in case of success and,
|
||||||
|
* %-EUCLEAN if the LEB neads recovery, and other negative error codes in case
|
||||||
|
* of failure.
|
||||||
*/
|
*/
|
||||||
struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
|
struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
|
||||||
int offs, void *sbuf)
|
int offs, void *sbuf)
|
||||||
|
@ -279,7 +281,6 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
|
||||||
cond_resched();
|
cond_resched();
|
||||||
|
|
||||||
ret = ubifs_scan_a_node(c, buf, len, lnum, offs, 0);
|
ret = ubifs_scan_a_node(c, buf, len, lnum, offs, 0);
|
||||||
|
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
/* Padding bytes or a valid padding node */
|
/* Padding bytes or a valid padding node */
|
||||||
offs += ret;
|
offs += ret;
|
||||||
|
@ -304,7 +305,8 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
|
||||||
goto corrupted;
|
goto corrupted;
|
||||||
default:
|
default:
|
||||||
dbg_err("unknown");
|
dbg_err("unknown");
|
||||||
goto corrupted;
|
err = -EINVAL;
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ubifs_add_snod(c, sleb, buf, offs);
|
err = ubifs_add_snod(c, sleb, buf, offs);
|
||||||
|
@ -317,8 +319,10 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
|
||||||
len -= node_len;
|
len -= node_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offs % c->min_io_size)
|
if (offs % c->min_io_size) {
|
||||||
goto corrupted;
|
ubifs_err("empty space starts at non-aligned offset %d", offs);
|
||||||
|
goto corrupted;;
|
||||||
|
}
|
||||||
|
|
||||||
ubifs_end_scan(c, sleb, lnum, offs);
|
ubifs_end_scan(c, sleb, lnum, offs);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue