aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhihao Cheng <chengzhihao1@huawei.com>2024-11-11 17:08:16 +0800
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2024-11-11 10:32:46 +0100
commit3188e0e0577991922ebaf4cccc36cdf7d3ad6566 (patch)
treef6272efd574fc418903affa1acb6a1bea8cc514e
parent2400ee616991542f39a154fe8c3cafe8ef940003 (diff)
fsck.ubifs: Do final committing
This is the 18/18 step of fsck. Do final committing, commit problem fixing modifications(which are generated since step 14) to disk, and clear %UBIFS_MST_DIRTY flag for master node. Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--ubifs-utils/fsck.ubifs/fsck.ubifs.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/ubifs-utils/fsck.ubifs/fsck.ubifs.c b/ubifs-utils/fsck.ubifs/fsck.ubifs.c
index 423a753..6ca0b57 100644
--- a/ubifs-utils/fsck.ubifs/fsck.ubifs.c
+++ b/ubifs-utils/fsck.ubifs/fsck.ubifs.c
@@ -432,28 +432,25 @@ void handle_error(const struct ubifs_info *c, int reason_set)
exit_code |= FSCK_ERROR;
}
-static int commit_fix_modifications(struct ubifs_info *c)
+static int commit_fix_modifications(struct ubifs_info *c, bool final_commit)
{
int err;
- if (exit_code & FSCK_NONDESTRUCT) {
+ if (final_commit) {
+ log_out(c, "Final committing");
+ c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
+ c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum);
+ /* Force UBIFS to do commit by setting @c->mounting. */
+ c->mounting = 1;
+ } else if (exit_code & FSCK_NONDESTRUCT) {
log_out(c, "Commit problem fixing modifications");
-
- /*
- * Force UBIFS to do commit by setting @c->mounting if changes
- * happen on disk. Committing is required once before allocating
- * new space(subsequent steps may need), because building lpt
- * could mark LEB(which holds stale data nodes) as unused, if
- * the LEB is overwritten by new data, old data won't be found
- * in next fsck run(assume that first fsck run is interrupted by
- * the powercut), which could affect the correctness of LEB
- * properties after replaying journal in the second fsck run.
- */
+ /* Force UBIFS to do commit by setting @c->mounting. */
c->mounting = 1;
}
+
err = ubifs_run_commit(c);
- if (exit_code & FSCK_NONDESTRUCT)
+ if (c->mounting)
c->mounting = 0;
return err;
@@ -511,7 +508,16 @@ static int do_fsck(void)
goto free_disconnected_files_2;
}
- err = commit_fix_modifications(c);
+ /*
+ * Committing is required once before allocating new space(subsequent
+ * steps may need), because building lpt could mark LEB(which holds
+ * stale data nodes) as unused, if the LEB is overwritten by new data,
+ * old data won't be found in the next fsck run(assume that first fsck
+ * run is interrupted by the powercut), which could affect the
+ * correctness of LEB properties after replaying journal in the second
+ * fsck run.
+ */
+ err = commit_fix_modifications(c, false);
if (err) {
exit_code |= FSCK_ERROR;
goto free_disconnected_files_2;
@@ -532,7 +538,7 @@ static int do_fsck(void)
}
if (list_empty(&FSCK(c)->disconnected_files))
- return err;
+ goto final_commit;
log_out(c, "Check and create lost+found");
err = check_and_create_lost_found(c);
@@ -548,6 +554,13 @@ static int do_fsck(void)
goto free_disconnected_files_2;
}
+final_commit:
+ err = commit_fix_modifications(c, true);
+ if (err)
+ exit_code |= FSCK_ERROR;
+
+ return err;
+
free_disconnected_files_2:
destroy_file_list(c, &FSCK(c)->disconnected_files);
return err;
@@ -604,6 +617,7 @@ int main(int argc, char *argv[])
* Step 15: Check and create root dir
* Step 16: Check and create lost+found
* Step 17: Handle disconnected files
+ * Step 18: Do final committing
*/
err = do_fsck();
if (err && FSCK(c)->try_rebuild) {