aboutsummaryrefslogtreecommitdiff
path: root/ubifs-utils/libubifs/master.c
diff options
context:
space:
mode:
authorZhihao Cheng <chengzhihao1@huawei.com>2024-11-11 17:01:04 +0800
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2024-11-11 10:32:45 +0100
commit518e5374471233125a595c5aeff2d0c3f5d27c0b (patch)
treef9f541d1ddcfcd456382ac1cdbb2b458b8f93181 /ubifs-utils/libubifs/master.c
parente17ad291a8da970a4cf64a57796c30437d8c5fbd (diff)
fsck.ubifs: Distinguish reasons when certain failures happen
Read failure caused by scanning corrupted data or invalid data members should be identified, because fsck can handle it. Updating lp failure caused by bad space statistics should be identified too, because fsck can handle it. Add eight callback functions to implement it for fsck: 1. set_failure_reason_callback: Record failure reasons when reading or parsing node failed, there are four reasons: a. FR_DATA_CORRUPTED: scanning corrupted data or invalid nodes found b. FR_TNC_CORRUPTED: invalid index nodes c. FR_LPT_CORRUPTED: invalid pnode/nnode d. FR_LPT_INCORRECT: invalid space statistics or invalid LEB properties 2. get_failure_reason_callback: get failure reasons 3. clear_failure_reason_callback: Clear the error which is caused by above reasons. 4. test_and_clear_failure_reason_callback: Check and clear the error which is caused by above reasons, if so, fsck will handle it according to specific situation. For example, fsck will drop data node rather than fails to return when reading failure is caused by DATA_CORRUPTED. For another example, journal replaying will continue rather than fails to return if updating lpt failure is caused by LPT_CORRUPTED. 5. set_lpt_invalid_callback: Set the invalid lpt status 6. test_lpt_valid_callback: Check whether the lpt is corrupted/incorrect, it should be invoked before updating lp, if lpt status is invalid, returns false (which means that caller should skip updating lp, because updating lp could trigger assertion failed in ubifs_change_lp). 7. can_ignore_failure_callback: Check whether the failure can be ignored, some inconsistent errors won't affect the fsck process, for example wrong space statistics can be fixed after traversing TNC, so failures caused by incorrect space statistics can be ignored. 8. handle_failure_callback: Check whether the failure can be handled, some inconsistent errors could be fixed by fsck, we have fix_problem to do that, but UBIFS needs a callback function to invoke it in common libs. Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubifs-utils/libubifs/master.c')
-rw-r--r--ubifs-utils/libubifs/master.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/ubifs-utils/libubifs/master.c b/ubifs-utils/libubifs/master.c
index cce1a41..61ff4ce 100644
--- a/ubifs-utils/libubifs/master.c
+++ b/ubifs-utils/libubifs/master.c
@@ -146,10 +146,12 @@ static int scan_for_master(struct ubifs_info *c)
return 0;
out:
+ set_failure_reason_callback(c, FR_DATA_CORRUPTED);
ubifs_scan_destroy(sleb);
return -EUCLEAN;
out_dump:
+ set_failure_reason_callback(c, FR_DATA_CORRUPTED);
ubifs_err(c, "unexpected node type %d master LEB %d:%d",
snod->type, lnum, snod->offs);
ubifs_scan_destroy(sleb);
@@ -165,6 +167,7 @@ out_dump:
*/
static int validate_master(const struct ubifs_info *c)
{
+ unsigned int reason = FR_DATA_CORRUPTED;
long long main_sz;
int err;
@@ -254,39 +257,46 @@ static int validate_master(const struct ubifs_info *c)
}
if (c->lst.empty_lebs < 0 || c->lst.empty_lebs > c->main_lebs - 2) {
+ reason = FR_LPT_INCORRECT;
err = 15;
goto out;
}
if (c->lst.idx_lebs < 0 || c->lst.idx_lebs > c->main_lebs - 1) {
+ reason = FR_LPT_INCORRECT;
err = 16;
goto out;
}
if (c->lst.total_free < 0 || c->lst.total_free > main_sz ||
c->lst.total_free & 7) {
+ reason = FR_LPT_INCORRECT;
err = 17;
goto out;
}
if (c->lst.total_dirty < 0 || (c->lst.total_dirty & 7)) {
+ reason = FR_LPT_INCORRECT;
err = 18;
goto out;
}
if (c->lst.total_used < 0 || (c->lst.total_used & 7)) {
+ reason = FR_LPT_INCORRECT;
err = 19;
goto out;
}
if (c->lst.total_free + c->lst.total_dirty +
c->lst.total_used > main_sz) {
+ reason = FR_LPT_INCORRECT;
err = 20;
goto out;
}
if (c->lst.total_dead + c->lst.total_dark +
c->lst.total_used + c->bi.old_idx_sz > main_sz) {
+ reason = FR_LPT_INCORRECT;
err = 21;
goto out;
}
@@ -294,6 +304,7 @@ static int validate_master(const struct ubifs_info *c)
if (c->lst.total_dead < 0 ||
c->lst.total_dead > c->lst.total_free + c->lst.total_dirty ||
c->lst.total_dead & 7) {
+ reason = FR_LPT_INCORRECT;
err = 22;
goto out;
}
@@ -301,6 +312,7 @@ static int validate_master(const struct ubifs_info *c)
if (c->lst.total_dark < 0 ||
c->lst.total_dark > c->lst.total_free + c->lst.total_dirty ||
c->lst.total_dark & 7) {
+ reason = FR_LPT_INCORRECT;
err = 23;
goto out;
}
@@ -308,6 +320,7 @@ static int validate_master(const struct ubifs_info *c)
return 0;
out:
+ set_failure_reason_callback(c, reason);
ubifs_err(c, "bad master node at offset %d error %d", c->mst_offs, err);
ubifs_dump_node(c, c->mst_node, c->mst_node_alsz);
return -EINVAL;
@@ -331,8 +344,10 @@ int ubifs_read_master(struct ubifs_info *c)
err = scan_for_master(c);
if (err) {
- if (err == -EUCLEAN)
+ if (err == -EUCLEAN) {
+ clear_failure_reason_callback(c);
err = ubifs_recover_master_node(c);
+ }
if (err)
/*
* Note, we do not free 'c->mst_node' here because the
@@ -386,6 +401,7 @@ int ubifs_read_master(struct ubifs_info *c)
if (c->leb_cnt < old_leb_cnt ||
c->leb_cnt < UBIFS_MIN_LEB_CNT) {
+ set_failure_reason_callback(c, FR_DATA_CORRUPTED);
ubifs_err(c, "bad leb_cnt on master node");
ubifs_dump_node(c, c->mst_node, c->mst_node_alsz);
return -EINVAL;