summaryrefslogtreecommitdiff
path: root/src/journal.c
diff options
context:
space:
mode:
authorrobi <robi>2011-12-25 20:38:16 +0000
committerrobi <robi>2011-12-25 20:38:16 +0000
commit9d0ee99f1144cec4c00e04ce6a7e3f2653005df7 (patch)
treeea2cbe5c3bf112ab1ceb1c1046ba585e4268b3aa /src/journal.c
parentbe0c55229494231393ae0f122cac8d19753d6804 (diff)
new partial step, recover in journal lost inodes
Diffstat (limited to 'src/journal.c')
-rw-r--r--src/journal.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/journal.c b/src/journal.c
index bfd255a..d8ccd83 100644
--- a/src/journal.c
+++ b/src/journal.c
@@ -64,11 +64,14 @@ struct journal_source
//static variable for work with journal
struct journal_source journal_source;
extern ext2_filsys current_fs ;
+extern time_t now_time ;
struct ext2_super_block *jsb_pointer; //pointer for find & open journal
char jsb_buffer[1024]; //buffer for journal-superblock (be_to_CPU)
void* pt_buff; /*pointer of the privat descriptor Table */
journal_descriptor_tag_t *pt; /*pointer for descriptor Table*/
+__u32 *ptl; /*reverse pointer for lost inodeblocks*/
__u32 pt_count; /*counter for privat descriptor Table */
+__u32 ptl_count; /*counter for lost inodeblocks*/
struct j_bitmap_list_t jbbm ; /* for Block Bitmaps of Journal */
@@ -149,6 +152,7 @@ extern int journal_open( char *journal_file_name, int journal_backup_flag )
ext2_file_t journal_file;
pt_buff = NULL;
+ ptl = NULL;
if (current_fs) jsb_pointer = current_fs->super;
else {
fprintf(stderr,"No filesystem open, this must be a bug\n");
@@ -395,6 +399,43 @@ static const char *type_to_name(int btype)
}
+//check if journal block is a lost inodeblock local function
+int jb_is_inodetable(unsigned char *buf){
+ struct ext2_inode *inode;
+ __u16 mode;
+ __u32 atime;
+ __u32 ctime;
+ __u32 mtime;
+ __u32 dtime;
+ int i;
+ __u32 min = 315601200; // 315601200 = "1980-01-01 20:00:00"
+ __u32 max = (__u32) now_time;
+ int ret = 0;
+ int i_size = EXT2_INODE_SIZE(current_fs->super);
+ int inodes_per_block = (current_fs->blocksize / i_size );
+ int flag = 0;
+
+
+ for (i=0; i<inodes_per_block;i++){
+ inode = (struct ext2_inode*) (buf + (i_size * i));
+ mode = ext2fs_le16_to_cpu(inode->i_mode);
+ atime = ext2fs_le32_to_cpu(inode->i_atime);
+ ctime = ext2fs_le32_to_cpu(inode->i_ctime);
+ mtime = ext2fs_le32_to_cpu(inode->i_mtime);
+ dtime = ext2fs_le32_to_cpu(inode->i_dtime);
+ if ((!mode) && (!atime) && (!ctime) && (!mtime) && (!dtime) && (!i))
+ return 0;
+ if ((!dtime) && (ctime > min) && (ctime < max) && (atime > min) && (atime < max)
+ && (mtime > min) && (mtime < max) && inode->i_size && inode->i_blocks
+ && LINUX_S_ISREG(mode) && inode->i_block[0] )
+ flag++;
+ if (ctime > max)
+ return 0;
+ }
+ return flag;
+}
+
+
//check if block is a inodeblock local function
static int block_is_inodetable(blk64_t block){
int group;
@@ -813,6 +854,8 @@ static int init_journal(void)
fprintf(stderr,"Error: can't allocate %d Memory\n",maxlen * sizeof(journal_descriptor_tag_t));
goto errout;
}
+ ptl = (__u32*)(pt_buff + (maxlen * sizeof(journal_descriptor_tag_t)));
+ ptl_count = 0;
#ifdef DEBUG
fprintf(stdout, "Journal starts at block %u, transaction %u\n", blocknr, transaction);
@@ -834,6 +877,12 @@ static int init_journal(void)
// fprintf (stdout, "No magic number at block %u: skip this block\n", blocknr);
fprintf(stdout,"-");
#endif
+ if (jb_is_inodetable(buf)){
+// printf("lost %d\n", blocknr);
+ ptl--;
+ *ptl = blocknr;
+ ptl_count ++;
+ }
if ( ! wrapflag ) wrapflag = WRAP_ON ;
blocknr++ ;
continue;
@@ -1069,3 +1118,23 @@ errout:
}
+
+//read the next journal-lost inode block
+int get_pool_block(unsigned char *buf){
+ int retval = 0;
+ int ret = 0;
+ int got,i ;
+ int blocksize = current_fs->blocksize;
+
+ if (ptl_count){
+ retval = read_journal_block(*ptl * blocksize ,buf,blocksize,&got);
+ if ((! retval) && (got == blocksize)){
+ ret = 1;
+ }
+ ptl_count--;
+ ptl++;
+ }
+return ret;
+}
+
+