summaryrefslogtreecommitdiff
path: root/ubifs-utils/libubifs/lpt.c
diff options
context:
space:
mode:
authorZhihao Cheng <chengzhihao1@huawei.com>2024-11-11 17:08:09 +0800
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2024-11-11 10:32:46 +0100
commit83b7477eae174e974237685f83f0fec4fb794892 (patch)
treecb5e6c3b0e9de5178124fb761e44466b092a55e2 /ubifs-utils/libubifs/lpt.c
parent47c1cfd5e8ec289597f7342f88e103811511f0a8 (diff)
fsck.ubifs: check and correct the space statistics
This is the 12/18 step of fsck. Check and correct the space statistics. There could be following steps and possible errors: Step 1. Exit for check mode, if %FR_LPT_CORRUPTED or %FR_LPT_INCORRECT is set in lpt status, the exit code should have %FSCK_UNCORRECTED. Step 2. Check lpt status, if %FR_LPT_CORRUPTED is set in lpt status, normal mode with 'no' answer will exit, other modes will rebuild lpt. Step 3. Traverse LPT nodes, check the correctness of nnode and pnode, compare LEB scanning result with LEB properties. a. LPT node is corrupted, normal mode with 'no' answer will exit, rebuild lpt for other modes. b. Incorrect nnode/pnode, normal mode with 'no' answer will exit, other other modes will correct the nnode/pnode. c. Inconsistent comparing result, normal mode with 'no' answer will exit, other modes will correct the space statistics. Step 4. Check and correct the lprops table information. Step 5. Set gc lnum(ubifs_rcvry_gc_commit / take_gc_lnum). Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubifs-utils/libubifs/lpt.c')
-rw-r--r--ubifs-utils/libubifs/lpt.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ubifs-utils/libubifs/lpt.c b/ubifs-utils/libubifs/lpt.c
index fc70cad..8e20a17 100644
--- a/ubifs-utils/libubifs/lpt.c
+++ b/ubifs-utils/libubifs/lpt.c
@@ -605,6 +605,7 @@ static int calc_pnode_num_from_parent(const struct ubifs_info *c,
* @lps: array of logical eraseblock properties
* @lp_cnt: the length of @lps
* @hash: hash of the LPT is returned here
+ * @free_ltab: %true means to release c->ltab after creating lpt
*
* This function creates lpt, the pnode will be initialized based on
* corresponding elements in @lps. If there are no corresponding lprops
@@ -612,7 +613,7 @@ static int calc_pnode_num_from_parent(const struct ubifs_info *c,
* as free state.
*/
int ubifs_create_lpt(struct ubifs_info *c, struct ubifs_lprops *lps, int lp_cnt,
- u8 *hash)
+ u8 *hash, bool free_ltab)
{
int lnum, err = 0, i, j, cnt, len, alen, row;
int blnum, boffs, bsz, bcnt;
@@ -910,10 +911,12 @@ int ubifs_create_lpt(struct ubifs_info *c, struct ubifs_lprops *lps, int lp_cnt,
if (c->big_lpt)
dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs);
out:
- c->ltab = NULL;
+ if (free_ltab || err) {
+ c->ltab = NULL;
+ vfree(ltab);
+ }
kfree(desc);
kfree(lsave);
- vfree(ltab);
vfree(buf);
kfree(nnode);
kfree(pnode);