ReactOS 0.4.16-dev-112-g52265ae
recover.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYRIGHT.TXT
3 * PROJECT: Ext2 File System Driver for WinNT/2K/XP
4 * FILE: recover.c
5 * PROGRAMMER: Matt Wu <mattwu@163.com>
6 * HOMEPAGE: http://www.ext2fsd.com
7 * UPDATE HISTORY:
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include <ext2fs.h>
13#include <linux/jbd.h>
14#include <linux/ext3_fs.h>
15
16/* GLOBALS ***************************************************************/
17
19
20/* DEFINITIONS *************************************************************/
21
22#ifdef ALLOC_PRAGMA
23#pragma alloc_text(PAGE, Ext2LoadInternalJournal)
24#pragma alloc_text(PAGE, Ext2CheckJournal)
25#pragma alloc_text(PAGE, Ext2RecoverJournal)
26#endif
27
31 ULONG jNo
32)
33{
34 PEXT2_MCB Jcb = NULL;
35
36 Jcb = Ext2AllocateMcb(Vcb, NULL, NULL, 0);
37 if (!Jcb) {
38 goto errorout;
39 }
40
41 Jcb->Inode.i_ino = jNo;
42 Jcb->Inode.i_sb = &Vcb->sb;
43 if (!Ext2LoadInode(Vcb, &Jcb->Inode)) {
44 DbgBreak();
45 Ext2FreeMcb(Vcb, Jcb);
46 goto errorout;
47 }
48
49errorout:
50
51 return Jcb;
52}
53
54INT
57 PULONG jNo
58)
59{
60 struct ext3_super_block* esb = NULL;
61
62 /* check ext3 super block */
63 esb = (struct ext3_super_block *)Vcb->SuperBlock;
67 }
68
69 /* must stop here if volume is read-only */
70 if (IsVcbReadOnly(Vcb)) {
71 goto errorout;
72 }
73
74 /* journal is external ? */
75 if (esb->s_journal_inum == 0) {
76 goto errorout;
77 }
78
79 /* oops: volume is corrupted */
80 if (esb->s_journal_dev) {
81 goto errorout;
82 }
83
84 /* return the journal inode number */
85 *jNo = esb->s_journal_inum;
86
87 return TRUE;
88
89errorout:
90
91 return FALSE;
92}
93
94INT
96 PEXT2_IRP_CONTEXT IrpContext,
98)
99{
100 INT rc = 0;
101 ULONG jNo = 0;
102 PEXT2_MCB jcb = NULL;
103 struct block_device * bd = &Vcb->bd;
104#ifndef __REACTOS__
105 struct super_block * sb = &Vcb->sb;
106#endif
107 struct inode * ji = NULL;
108 journal_t * journal = NULL;
109 struct ext3_super_block *esb;
110
111 ExAcquireResourceExclusiveLite(&Vcb->MainResource, TRUE);
112
113 /* check journal inode number */
114 if (!Ext2CheckJournal(Vcb, &jNo)) {
115 rc = -1;
116 goto errorout;
117 }
118
119 /* allocate journal Mcb */
120 jcb = Ext2LoadInternalJournal(Vcb, jNo);
121 if (!jcb) {
122 rc = -6;
123 goto errorout;
124 }
125
126 /* allocate journal inode */
127 ji = &jcb->Inode;
128
129 /* initialize journal file from inode */
130 journal = journal_init_inode(ji);
131
132 /* initialzation succeeds ? */
133 if (!journal) {
134 iput(ji);
135 rc = -8;
136 goto errorout;
137 }
138
139 /* start journal recovery */
140 rc = journal_load(journal);
141 if (0 != rc) {
142 rc = -9;
143 DbgPrint("Ext2Fsd: recover_journal: failed "
144 "to recover journal data.\n");
145 }
146
147 /* reload super_block and group_description */
148 Ext2RefreshSuper(IrpContext, Vcb);
149 Ext2RefreshGroup(IrpContext, Vcb);
150
151 /* wipe journal data and clear recover flag in sb */
152 if (rc == 0) {
153 journal_wipe_recovery(journal);
155 Vcb->SuperBlock->s_feature_incompat,
157 Ext2SaveSuper(IrpContext, Vcb);
158 sync_blockdev(bd);
160 }
161
162errorout:
163
164 /* destroy journal structure */
165 if (journal) {
166 journal_destroy(journal);
167 }
168
169 /* destory journal Mcb */
170 if (jcb) {
171 Ext2FreeMcb(Vcb, jcb);
172 }
173
174 ExReleaseResourceLite(&Vcb->MainResource);
175
176 return rc;
177}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
superblock * sb
Definition: btrfs.c:4261
void iput(struct inode *inode)
Definition: linux.c:992
INT Ext2CheckJournal(PEXT2_VCB Vcb, PULONG jNo)
Definition: recover.c:55
PEXT2_GLOBAL Ext2Global
Definition: init.c:16
INT Ext2RecoverJournal(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb)
Definition: recover.c:95
PEXT2_MCB Ext2LoadInternalJournal(PEXT2_VCB Vcb, ULONG jNo)
Definition: recover.c:29
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
VOID Ext2FreeMcb(IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb)
Definition: memory.c:1538
#define IsVcbReadOnly(Vcb)
Definition: ext2fs.h:814
#define SetLongFlag(_F, _SF)
Definition: ext2fs.h:258
#define VCB_JOURNAL_RECOVER
Definition: ext2fs.h:801
#define ClearLongFlag(_F, _SF)
Definition: ext2fs.h:259
BOOLEAN Ext2SaveSuper(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:67
#define DbgBreak()
Definition: ext2fs.h:46
BOOLEAN Ext2LoadInode(IN PEXT2_VCB Vcb, IN struct inode *Inode)
Definition: generic.c:508
PEXT2_MCB Ext2AllocateMcb(IN PEXT2_VCB Vcb, IN PUNICODE_STRING FileName, IN PUNICODE_STRING Parent, IN ULONG FileAttr)
Definition: memory.c:1430
BOOLEAN Ext2RefreshGroup(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:409
BOOLEAN Ext2RefreshSuper(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:92
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
#define EXT3_FEATURE_INCOMPAT_RECOVER
Definition: ext3_fs.h:680
#define DbgPrint
Definition: hal.h:12
if(dx< 0)
Definition: linetemp.h:194
int sync_blockdev(struct block_device *bdev)
Definition: linux.c:919
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
#define Vcb
Definition: cdprocs.h:1415
int journal_load(journal_t *journal)
Definition: replay.c:1121
journal_t * journal_init_inode(struct inode *inode)
Definition: replay.c:592
void journal_wipe_recovery(journal_t *journal)
Definition: replay.c:659
void journal_destroy(journal_t *journal)
Definition: replay.c:678
struct inode Inode
Definition: ext2fs.h:945
__le32 s_journal_inum
Definition: ext3_fs.h:561
__le32 s_feature_incompat
Definition: ext3_fs.h:538
__le32 s_journal_dev
Definition: ext3_fs.h:562
Definition: fs.h:78
Definition: fs.h:64
uint32_t * PULONG
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59