summaryrefslogtreecommitdiff
path: root/ubifs-utils/fsck.ubifs/fsck.ubifs.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/fsck.ubifs/fsck.ubifs.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/fsck.ubifs/fsck.ubifs.c')
-rw-r--r--ubifs-utils/fsck.ubifs/fsck.ubifs.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ubifs-utils/fsck.ubifs/fsck.ubifs.c b/ubifs-utils/fsck.ubifs/fsck.ubifs.c
index cd498f5..ba1b500 100644
--- a/ubifs-utils/fsck.ubifs/fsck.ubifs.c
+++ b/ubifs-utils/fsck.ubifs/fsck.ubifs.c
@@ -58,6 +58,7 @@ static const char *helptext =
"-b, --rebuild Forcedly repair the filesystem even by rebuilding filesystem.\n"
" Depends on -y option\n"
"-n, --nochange Make no changes to the filesystem, only check filesystem.\n"
+" This mode don't check space, because unclean LEBs are not rewritten in readonly mode.\n"
" Can not be specified at the same time as the -a or -y options\n"
"Examples:\n"
"\t1. Check and repair filesystem from UBI volume /dev/ubi0_0\n"
@@ -329,6 +330,7 @@ static const unsigned int reason_mapping_table[] = {
BUD_CORRUPTED, /* FR_H_BUD_CORRUPTED */
TNC_DATA_CORRUPTED, /* FR_H_TNC_DATA_CORRUPTED */
ORPHAN_CORRUPTED, /* FR_H_ORPHAN_CORRUPTED */
+ LTAB_INCORRECT, /* FR_H_LTAB_INCORRECT */
};
static bool fsck_handle_failure(const struct ubifs_info *c, unsigned int reason,
@@ -471,8 +473,18 @@ static int do_fsck(void)
if (tnc_is_empty(c) && fix_problem(c, EMPTY_TNC, NULL)) {
err = -EINVAL;
FSCK(c)->try_rebuild = true;
+ goto free_disconnected_files;
}
+ err = check_and_correct_space(c);
+ kfree(FSCK(c)->used_lebs);
+ destroy_file_tree(c, &FSCK(c)->scanned_files);
+ if (err)
+ exit_code |= FSCK_ERROR;
+
+ destroy_file_list(c, &FSCK(c)->disconnected_files);
+ return err;
+
free_disconnected_files:
destroy_file_list(c, &FSCK(c)->disconnected_files);
free_used_lebs:
@@ -519,6 +531,7 @@ int main(int argc, char *argv[])
* Step 9: Check and handle unreachable files
* Step 10: Check and correct files
* Step 11: Check whether the TNC is empty
+ * Step 12: Check and correct the space statistics
*/
err = do_fsck();
if (err && FSCK(c)->try_rebuild) {