ReactOS  0.4.13-dev-563-g0561610
recover.c File Reference
#include <ext2fs.h>
#include <linux/jbd.h>
#include <linux/ext3_fs.h>
Include dependency graph for recover.c:

Go to the source code of this file.

Functions

PEXT2_MCB Ext2LoadInternalJournal (PEXT2_VCB Vcb, ULONG jNo)
 
INT Ext2CheckJournal (PEXT2_VCB Vcb, PULONG jNo)
 
INT Ext2RecoverJournal (PEXT2_IRP_CONTEXT IrpContext, PEXT2_VCB Vcb)
 

Variables

PEXT2_GLOBAL Ext2Global
 

Function Documentation

◆ Ext2CheckJournal()

INT Ext2CheckJournal ( PEXT2_VCB  Vcb,
PULONG  jNo 
)

Definition at line 55 of file recover.c.

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 }
#define TRUE
Definition: types.h:120
#define VCB_JOURNAL_RECOVER
Definition: ext2fs.h:792
__le32 s_journal_dev
Definition: ext3_fs.h:562
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
smooth NULL
Definition: ftsmooth.c:416
__le32 s_feature_incompat
Definition: ext3_fs.h:538
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
#define Vcb
Definition: cdprocs.h:1425
#define EXT3_FEATURE_INCOMPAT_RECOVER
Definition: ext3_fs.h:680
#define SetLongFlag(_F, _SF)
Definition: ext2fs.h:253

Referenced by Ext2RecoverJournal().

◆ Ext2LoadInternalJournal()

PEXT2_MCB Ext2LoadInternalJournal ( PEXT2_VCB  Vcb,
ULONG  jNo 
)

Definition at line 29 of file recover.c.

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 }
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
VOID Ext2FreeMcb(IN PEXT2_VCB Vcb, IN PEXT2_MCB Mcb)
Definition: memory.c:1538
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN Ext2LoadInode(IN PEXT2_VCB Vcb, IN struct inode *Inode)
Definition: generic.c:504
#define Vcb
Definition: cdprocs.h:1425
#define DbgBreak()
Definition: ext2fs.h:46

Referenced by Ext2RecoverJournal().

◆ Ext2RecoverJournal()

INT Ext2RecoverJournal ( PEXT2_IRP_CONTEXT  IrpContext,
PEXT2_VCB  Vcb 
)

Definition at line 95 of file recover.c.

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
#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:3952
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
smooth NULL
Definition: ftsmooth.c:416
#define ClearLongFlag(_F, _SF)
Definition: ext2fs.h:254
void journal_wipe_recovery(journal_t *journal)
Definition: replay.c:659
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
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
INT Ext2CheckJournal(PEXT2_VCB Vcb, PULONG jNo)
Definition: recover.c:55

Referenced by Ext2InitializeVcb(), and Ext2ProcessVolumeProperty().

Variable Documentation

◆ Ext2Global

PEXT2_GLOBAL Ext2Global

Definition at line 16 of file init.c.