errcode_t ext2fs_open_journal(ext2_filsys fs, journal_t **j) { journal_t *journal; errcode_t retval; journal_init_revoke_caches(); retval = ext2fs_get_journal(fs, &journal); if (retval) return retval; retval = ext2fs_journal_load(journal); if (retval) goto errout; retval = journal_init_revoke(journal, 1024); if (retval) goto errout; if (journal->j_failed_commit) { journal->j_superblock->s_errno = -EINVAL; mark_buffer_dirty(journal->j_sb_buffer); } *j = journal; return 0; errout: journal_destroy_revoke(journal); journal_destroy_revoke_caches(); ext2fs_journal_release(fs, journal, 1, 0); return retval; }
/* * This function makes sure that the superblock fields regarding the * journal are consistent. */ errcode_t ext2fs_check_ext3_journal(ext2_filsys fs) { struct ext2_super_block *sb = fs->super; journal_t *journal; int recover = fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER; errcode_t retval; /* If we don't have any journal features, don't do anything more */ if (!(sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) && !recover && sb->s_journal_inum == 0 && sb->s_journal_dev == 0 && uuid_is_null(sb->s_journal_uuid)) return 0; retval = ext2fs_get_journal(fs, &journal); if (retval) return retval; retval = ext2fs_journal_load(journal); if (retval) goto err; /* * We want to make the flags consistent here. We will not leave with * needs_recovery set but has_journal clear. We can't get in a loop * with -y, -n, or -p, only if a user isn't making up their mind. */ if (!(sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { retval = EXT2_ET_JOURNAL_FLAGS_WRONG; goto err; } if (sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL && !(sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) && journal->j_superblock->s_start != 0) { retval = EXT2_ET_JOURNAL_FLAGS_WRONG; goto err; } /* * If we don't need to do replay the journal, check to see if * the journal's errno is set; if so, we need to mark the file * system as being corrupt and clear the journal's s_errno. */ if (!(sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) && journal->j_superblock->s_errno) { fs->super->s_state |= EXT2_ERROR_FS; ext2fs_mark_super_dirty(fs); journal->j_superblock->s_errno = 0; ext2fs_journal_sb_csum_set(journal, journal->j_superblock); mark_buffer_dirty(journal->j_sb_buffer); } err: ext2fs_journal_release(fs, journal, 0, retval ? 1 : 0); return retval; }