ReactOS  0.4.14-dev-50-g13bb5e2
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 
30  PEXT2_VCB Vcb,
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 
49 errorout:
50 
51  return Jcb;
52 }
53 
54 INT
56  PEXT2_VCB Vcb,
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 
89 errorout:
90 
91  return FALSE;
92 }
93 
94 INT
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 
162 errorout:
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 }
PEXT2_MCB Ext2LoadInternalJournal(PEXT2_VCB Vcb, ULONG jNo)
Definition: recover.c:29
#define TRUE
Definition: types.h:120
BOOLEAN Ext2RefreshSuper(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:88
struct inode Inode
Definition: ext2fs.h:936
PEXT2_MCB Ext2AllocateMcb(IN PEXT2_VCB Vcb, IN PUNICODE_STRING FileName, IN PUNICODE_STRING Parent, IN ULONG FileAttr)
Definition: memory.c:1430
#define DbgPrint
Definition: loader.c:25
BOOLEAN Ext2SaveSuper(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:63
superblock * sb
Definition: btrfs.c:4162
Definition: fs.h:64
#define VCB_JOURNAL_RECOVER
Definition: ext2fs.h:792
int journal_load(journal_t *journal)
Definition: replay.c:1121
VOID Ext2FreeMcb(IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb)
Definition: memory.c:1538
int32_t INT
Definition: typedefs.h:56
Definition: fs.h:78
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
__le32 s_journal_dev
Definition: ext3_fs.h:562
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN Ext2LoadInode(IN PEXT2_VCB Vcb, IN struct inode *Inode)
Definition: generic.c:504
#define ClearLongFlag(_F, _SF)
Definition: ext2fs.h:254
void journal_wipe_recovery(journal_t *journal)
Definition: replay.c:659
__le32 s_feature_incompat
Definition: ext3_fs.h:538
INT Ext2RecoverJournal(PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb)
Definition: recover.c:95
if(!(yy_init))
Definition: macro.lex.yy.c:714
__le32 s_journal_inum
Definition: ext3_fs.h:561
#define IsVcbReadOnly(Vcb)
Definition: ext2fs.h:805
BOOLEAN Ext2RefreshGroup(IN PEXT2_IRP_CONTEXT IrpContext, IN PEXT2_VCB Vcb)
Definition: generic.c:405
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
void journal_destroy(journal_t *journal)
Definition: replay.c:678
journal_t * journal_init_inode(struct inode *inode)
Definition: replay.c:592
#define EXT3_FEATURE_INCOMPAT_RECOVER
Definition: ext3_fs.h:680
PEXT2_GLOBAL Ext2Global
Definition: init.c:16
#define SetLongFlag(_F, _SF)
Definition: ext2fs.h:253
unsigned int * PULONG
Definition: retypes.h:1
void iput(struct inode *inode)
Definition: linux.c:984
int sync_blockdev(struct block_device *bdev)
Definition: linux.c:911
unsigned int ULONG
Definition: retypes.h:1
#define DbgBreak()
Definition: ext2fs.h:46
INT Ext2CheckJournal(PEXT2_VCB Vcb, PULONG jNo)
Definition: recover.c:55