diff options
author | Zhihao Cheng <chengzhihao1@huawei.com> | 2024-11-11 17:07:59 +0800 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2024-11-11 10:32:46 +0100 |
commit | acedb85997d7b04b4546154d8acc5d916c020630 (patch) | |
tree | 4a279bb48a709eead122ab37a2c7782015dd6c93 /ubifs-utils/fsck.ubifs/load_fs.c | |
parent | 0fbfbf59714b73a0d0c487c454c22d72b2c78e68 (diff) |
fsck.ubifs: Recover isize
This is the 5/18 step of fsck. Recover isize. There could be following
steps and possible errors:
Step 1. Traverse size tree, lookup corresponding inode from TNC
a. corrupted node searched from TNC: skip node for danger mode and
normal mode with 'yes' answer, other modes will exit.
b. corrupted index node read from TNC: danger mode with rebuild_fs and
normal mode with 'yes' answer will turn to rebuild filesystem, other
modes will exit.
Step 2. update isize for inode. Keep <inum, isize> in size tree for check
mode, update inode node in place for other modes.
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/load_fs.c')
-rw-r--r-- | ubifs-utils/fsck.ubifs/load_fs.c | 79 |
1 files changed, 46 insertions, 33 deletions
diff --git a/ubifs-utils/fsck.ubifs/load_fs.c b/ubifs-utils/fsck.ubifs/load_fs.c index 42b1afa..5854054 100644 --- a/ubifs-utils/fsck.ubifs/load_fs.c +++ b/ubifs-utils/fsck.ubifs/load_fs.c @@ -17,6 +17,33 @@ #include "misc.h" #include "fsck.ubifs.h" +enum { HAS_DATA_CORRUPTED = 1, HAS_TNC_CORRUPTED = 2 }; + +static void handle_error(const struct ubifs_info *c, int reason_set) +{ + bool handled = false; + unsigned int reason = get_failure_reason_callback(c); + + clear_failure_reason_callback(c); + if ((reason_set & HAS_DATA_CORRUPTED) && (reason & FR_DATA_CORRUPTED)) { + handled = true; + reason &= ~FR_DATA_CORRUPTED; + if (fix_problem(c, LOG_CORRUPTED, NULL)) + FSCK(c)->try_rebuild = true; + } + if ((reason_set & HAS_TNC_CORRUPTED) && (reason & FR_TNC_CORRUPTED)) { + ubifs_assert(c, !handled); + handled = true; + reason &= ~FR_TNC_CORRUPTED; + if (fix_problem(c, TNC_CORRUPTED, NULL)) + FSCK(c)->try_rebuild = true; + } + + ubifs_assert(c, reason == 0); + if (!handled) + exit_code |= FSCK_ERROR; +} + int ubifs_load_filesystem(struct ubifs_info *c) { int err; @@ -164,19 +191,7 @@ int ubifs_load_filesystem(struct ubifs_info *c) log_out(c, "Replay journal"); err = ubifs_replay_journal(c); if (err) { - unsigned int reason = get_failure_reason_callback(c); - - clear_failure_reason_callback(c); - if (reason & FR_DATA_CORRUPTED) { - if (fix_problem(c, LOG_CORRUPTED, NULL)) - FSCK(c)->try_rebuild = true; - } else if (reason & FR_TNC_CORRUPTED) { - if (fix_problem(c, TNC_CORRUPTED, NULL)) - FSCK(c)->try_rebuild = true; - } else { - ubifs_assert(c, reason == 0); - exit_code |= FSCK_ERROR; - } + handle_error(c, HAS_DATA_CORRUPTED | HAS_TNC_CORRUPTED); goto out_journal; } @@ -186,16 +201,7 @@ int ubifs_load_filesystem(struct ubifs_info *c) log_out(c, "Handle orphan nodes"); err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount); if (err) { - unsigned int reason = get_failure_reason_callback(c); - - clear_failure_reason_callback(c); - if (reason & FR_TNC_CORRUPTED) { - if (fix_problem(c, TNC_CORRUPTED, NULL)) - FSCK(c)->try_rebuild = true; - } else { - ubifs_assert(c, reason == 0); - exit_code |= FSCK_ERROR; - } + handle_error(c, HAS_TNC_CORRUPTED); goto out_orphans; } @@ -210,19 +216,26 @@ int ubifs_load_filesystem(struct ubifs_info *c) log_out(c, "Consolidate log"); err = ubifs_consolidate_log(c); if (err) { - unsigned int reason = get_failure_reason_callback(c); - - clear_failure_reason_callback(c); - if (reason & FR_DATA_CORRUPTED) { - if (fix_problem(c, LOG_CORRUPTED, NULL)) - FSCK(c)->try_rebuild = true; - } else { - ubifs_assert(c, reason == 0); - exit_code |= FSCK_ERROR; - } + handle_error(c, HAS_DATA_CORRUPTED); + goto out_orphans; + } + } + + if (c->need_recovery) { + log_out(c, "Recover isize"); + err = ubifs_recover_size(c, true); + if (err) { + handle_error(c, HAS_TNC_CORRUPTED); goto out_orphans; } } + } else if (c->need_recovery) { + log_out(c, "Recover isize"); + err = ubifs_recover_size(c, false); + if (err) { + handle_error(c, HAS_TNC_CORRUPTED); + goto out_orphans; + } } c->mounting = 0; |