#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;
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;
}
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;
}
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;
/* Locate the inode node LEB number and offset */
ino_key_init(c, &key, e->inum);
err = ubifs_tnc_locate(c, &key, ino, &lnum, &offs);
- if (err)
+ if (err) {
+ unsigned int reason = get_failure_reason_callback(c);
+
+ if (reason & FR_DATA_CORRUPTED) {
+ test_and_clear_failure_reason_callback(c, FR_DATA_CORRUPTED);
+ if (handle_failure_callback(c, FR_H_TNC_DATA_CORRUPTED, NULL)) {
+ /* Leave the inode to be deleted by subsequent steps */
+ return 0;
+ }
+ }
goto out;
+ }
/*
* If the size recorded on the inode node is greater than the size that
* was calculated from nodes in the journal then don't change the inode.
*/
static int inode_fix_size(struct ubifs_info *c, __unused struct size_entry *e)
{
- ubifs_assert(c, 0);
-
- // To be implemented
- return -EINVAL;
+ /* Don't remove entry, keep it in the size tree. */
+ /* Remove this assertion after supporting authentication. */
+ ubifs_assert(c, c->ro_mount);
+ return 0;
}
/**
ino_key_init(c, &key, e->inum);
err = ubifs_tnc_lookup(c, &key, c->sbuf);
- if (err && err != -ENOENT)
+ if (err && err != -ENOENT) {
+ unsigned int reason;
+
+ reason = get_failure_reason_callback(c);
+ if (reason & FR_DATA_CORRUPTED) {
+ test_and_clear_failure_reason_callback(c, FR_DATA_CORRUPTED);
+ if (handle_failure_callback(c, FR_H_TNC_DATA_CORRUPTED, NULL)) {
+ /* Leave the inode to be deleted by subsequent steps */
+ goto delete_entry;
+ }
+ }
return err;
+ }
if (err == -ENOENT) {
/* Remove data nodes that have no inode */
dbg_rcvry("removing ino %lu",
}
}
+delete_entry:
rb_erase(&e->rb, &c->size_tree);
kfree(e);
}