From 3f8ee068870a046b0dcf2921ed7ee375f405e49f Mon Sep 17 00:00:00 2001 From: Zhihao Cheng Date: Mon, 11 Nov 2024 17:01:21 +0800 Subject: fsck.ubifs: Read master node & init lpt This is the 1/18 step of fsck. Read and check master node, init lpt. There could be following errors: 1. corrupted scanning data in master area or invalid master node: danger mode with rebuild_fs and normal mode with 'yes' answer will turn to rebuild filesystem, other modes will exit. 2. incorrect space statistics in master node: Set %FR_LPT_INCORRECT for for lpt status. Ignore the error. 3. corrupted lpt: Set %FR_LPT_CORRUPTED for lpt status. Ignore the error. Signed-off-by: Zhihao Cheng Signed-off-by: David Oberhollenzer --- ubifs-utils/libubifs/lpt.c | 18 ++++++++++++++---- ubifs-utils/libubifs/master.c | 7 ++++++- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'ubifs-utils/libubifs') diff --git a/ubifs-utils/libubifs/lpt.c b/ubifs-utils/libubifs/lpt.c index c0df7c7..b07f1f7 100644 --- a/ubifs-utils/libubifs/lpt.c +++ b/ubifs-utils/libubifs/lpt.c @@ -1883,8 +1883,13 @@ static int lpt_init_rd(struct ubifs_info *c) c->dirty_idx.max_cnt = LPT_HEAP_SZ; err = read_ltab(c); - if (err) - return err; + if (err) { + if (test_and_clear_failure_reason_callback(c, FR_LPT_CORRUPTED) && + can_ignore_failure_callback(c, FR_LPT_CORRUPTED)) + err = 0; + else + return err; + } err = lpt_check_hash(c); if (err) @@ -1938,8 +1943,13 @@ static int lpt_init_wr(struct ubifs_info *c) if (!c->lsave) return -ENOMEM; err = read_lsave(c); - if (err) - return err; + if (err) { + if (test_and_clear_failure_reason_callback(c, FR_LPT_CORRUPTED) && + can_ignore_failure_callback(c, FR_LPT_CORRUPTED)) + err = 0; + else + return err; + } } for (i = 0; i < c->lpt_lebs; i++) diff --git a/ubifs-utils/libubifs/master.c b/ubifs-utils/libubifs/master.c index 61ff4ce..54d2a78 100644 --- a/ubifs-utils/libubifs/master.c +++ b/ubifs-utils/libubifs/master.c @@ -323,7 +323,12 @@ 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; + err = -EINVAL; + if (can_ignore_failure_callback(c, reason)) { + clear_failure_reason_callback(c); + err = 0; + } + return err; } /** -- cgit v1.2.3