INT Ext2RecoverJournal( PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb ) { INT rc = 0; ULONG jNo = 0; PEXT2_MCB jcb = NULL; struct block_device * bd = &Vcb->bd; #ifndef __REACTOS__ struct super_block * sb = &Vcb->sb; #endif struct inode * ji = NULL; journal_t * journal = NULL; struct ext3_super_block *esb; /* check journal inode number */ if (!Ext2CheckJournal(Vcb, &jNo)) { return -1; } /* allocate journal Mcb */ jcb = Ext2LoadInternalJournal(Vcb, jNo); if (!jcb) { rc = -6; goto errorout; } /* allocate journal inode */ ji = &jcb->Inode; /* initialize journal file from inode */ journal = journal_init_inode(ji); /* initialzation succeeds ? */ if (!journal) { iput(ji); rc = -8; goto errorout; } /* start journal recovery */ rc = journal_load(journal); if (0 != rc) { rc = -9; DbgPrint("Ext2Fsd: recover_journal: failed " "to recover journal data.\n"); } /* reload super_block and group_description */ Ext2RefreshSuper(IrpContext, Vcb); Ext2RefreshGroup(IrpContext, Vcb); /* wipe journal data and clear recover flag in sb */ if (rc == 0) { journal_wipe_recovery(journal); ClearLongFlag( Vcb->SuperBlock->s_feature_incompat, EXT3_FEATURE_INCOMPAT_RECOVER ); Ext2SaveSuper(IrpContext, Vcb); sync_blockdev(bd); ClearLongFlag(Vcb->Flags, VCB_JOURNAL_RECOVER); } errorout: /* destroy journal structure */ if (journal) { journal_destroy(journal); } /* destory journal Mcb */ if (jcb) { Ext2FreeMcb(Vcb, jcb); } return rc; }
int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty) { int status = -1; struct inode *inode = NULL; /* the journal inode */ journal_t *j_journal = NULL; struct ocfs2_dinode *di = NULL; struct buffer_head *bh = NULL; struct ocfs2_super *osb; int inode_lock = 0; mlog_entry_void(); BUG_ON(!journal); osb = journal->j_osb; /* already have the inode for our journal */ inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE, osb->slot_num); if (inode == NULL) { status = -EACCES; mlog_errno(status); goto done; } if (is_bad_inode(inode)) { mlog(ML_ERROR, "access error (bad inode)\n"); iput(inode); inode = NULL; status = -EACCES; goto done; } SET_INODE_JOURNAL(inode); OCFS2_I(inode)->ip_open_count++; /* Skip recovery waits here - journal inode metadata never * changes in a live cluster so it can be considered an * exception to the rule. */ status = ocfs2_inode_lock_full(inode, &bh, 1, OCFS2_META_LOCK_RECOVERY); if (status < 0) { if (status != -ERESTARTSYS) mlog(ML_ERROR, "Could not get lock on journal!\n"); goto done; } inode_lock = 1; di = (struct ocfs2_dinode *)bh->b_data; if (inode->i_size < OCFS2_MIN_JOURNAL_SIZE) { mlog(ML_ERROR, "Journal file size (%lld) is too small!\n", inode->i_size); status = -EINVAL; goto done; } mlog(0, "inode->i_size = %lld\n", inode->i_size); mlog(0, "inode->i_blocks = %llu\n", (unsigned long long)inode->i_blocks); mlog(0, "inode->ip_clusters = %u\n", OCFS2_I(inode)->ip_clusters); /* call the kernels journal init function now */ j_journal = journal_init_inode(inode); if (j_journal == NULL) { mlog(ML_ERROR, "Linux journal layer error\n"); status = -EINVAL; goto done; } mlog(0, "Returned from journal_init_inode\n"); mlog(0, "j_journal->j_maxlen = %u\n", j_journal->j_maxlen); *dirty = (le32_to_cpu(di->id1.journal1.ij_flags) & OCFS2_JOURNAL_DIRTY_FL); journal->j_journal = j_journal; journal->j_inode = inode; journal->j_bh = bh; ocfs2_set_journal_params(osb); journal->j_state = OCFS2_JOURNAL_LOADED; status = 0; done: if (status < 0) { if (inode_lock) ocfs2_inode_unlock(inode, 1); if (bh != NULL) brelse(bh); if (inode) { OCFS2_I(inode)->ip_open_count--; iput(inode); } } mlog_exit(status); return status; }