summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrobi <robi>2010-06-19 18:53:52 +0000
committerrobi <robi>2010-06-19 18:53:52 +0000
commit70185b8d0a686f56b06f2a1b1f771284fa22f2ce (patch)
tree16b9596def7eb429ca6cee8446de91e6d6d1a090 /src
parent972f26a10e5f0bacf12b2df2e9a00896b007e600 (diff)
enable debug
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in4
-rw-r--r--src/ext4magic.c13
-rw-r--r--src/hard_link_stack.c4
-rw-r--r--src/inode.c26
-rw-r--r--src/journal.c37
-rw-r--r--src/lookup_local.c6
-rw-r--r--src/recover.c34
7 files changed, 99 insertions, 25 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index 7391b9f..8df23e3 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -240,9 +240,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
exit 1;; \
esac; \
done; \
- echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
$(am__cd) $(top_srcdir) && \
- $(AUTOMAKE) --gnu src/Makefile
+ $(AUTOMAKE) --foreign src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
diff --git a/src/ext4magic.c b/src/ext4magic.c
index a9fb5bf..da9df38 100644
--- a/src/ext4magic.c
+++ b/src/ext4magic.c
@@ -225,6 +225,9 @@ static void open_filesystem(char *device, int open_flags, blk_t superblock,
return;
errout:
+#ifdef DEBUG
+ printf("Errout : open ext2fs\n");
+#endif
retval = ext2fs_close(current_fs);
if (retval)
fprintf(stderr, "%s %d while trying to close filesystem\n", device, retval);
@@ -547,7 +550,9 @@ while ((c = getopt (argc, argv, "TJRLlrQSxi:t:j:f:Vd:B:p:a:I:H")) != EOF) {
if (getuid()) mode = 0;
if (optind < argc)
open_filesystem(argv[optind], open_flags,superblock, blocksize, 0, data_filename);
-
+#ifdef DEBUG
+ printf("Operation-mode = %d\n");
+#endif
//--------------------------------------------------------------------------------------------
// check any parameter an options
@@ -605,7 +610,7 @@ if ((mode & RECOVER_INODE) && (recovermodus & (REC_DIR_NEEDED)) || mode & RECOV
fprintf(stderr,"ERROR: can not use \"%s\" for recover directory. It's the same filesystem : \"%s\"\n", des_dir, argv[optind]);
exitval = EXIT_FAILURE ;
#ifdef DEBUG
- printf("recover_dir_dev : %d filesystem_dev : %d\n",filestat.st_dev, file_rdev);
+ printf("recover_dir_dev : %d filesystem_dev : %d ",filestat.st_dev, file_rdev);
#endif
goto errout;
}
@@ -904,6 +909,10 @@ if ((mode & COMMAND_INODE) && (mode & RECOVER_INODE))
} // end Operation
exitval = EXIT_SUCCESS;
+#ifdef DEBUG
+ printf("EXIT_SUCCESS : %d, close and clear\n",exitval);
+#endif
+
errout:
if (current_fs) {
diff --git a/src/hard_link_stack.c b/src/hard_link_stack.c
index 85af300..547d259 100644
--- a/src/hard_link_stack.c
+++ b/src/hard_link_stack.c
@@ -69,6 +69,10 @@ char* check_link_stack(ext2_ino_t inode_nr, __u32 generation){
break;
head.pointer = head.pointer->next;
}
+#ifdef DEBUG
+ if (head.pointer)
+ printf("HARD_LINK found -> %s\n",head.pointer->name);
+#endif
return (head.pointer) ? head.pointer->name : NULL ;
}
diff --git a/src/inode.c b/src/inode.c
index d617775..b88b89f 100644
--- a/src/inode.c
+++ b/src/inode.c
@@ -598,6 +598,9 @@ r_item* get_last_undel_inode(struct ring_buf* buf){
else {
// if (item->inode->i_generation != generation)
// buf->reuse_flag = 1;
+#ifdef DEBUG
+ printf("UD-Inode %d\n",item->transaction.start);
+#endif
return item;
}
}
@@ -627,6 +630,9 @@ r_item* get_last_undel_inode(struct ring_buf* buf){
}
// if (item->inode->i_generation != generation)
// buf->reuse_flag = 1;
+#ifdef DEBUG
+ printf("UTD-Inode %d\n",item->transaction.start);
+#endif
return item;
}
return NULL;
@@ -663,6 +669,9 @@ struct ring_buf* get_j_inode_list(struct ext2_super_block *es, ext2_ino_t inode_
goto errout;
}
count = get_block_list_count(block) ;
+#ifdef DEBUG
+ fprintf(stdout,"\n\nINODE_RING : %ld/%ld/%ld : ",inode_nr, pos.block, pos.offset);
+#endif
if(! count) {
// no inode block found
@@ -679,6 +688,9 @@ struct ring_buf* get_j_inode_list(struct ext2_super_block *es, ext2_ino_t inode_
if ( ext2fs_read_inode_full(current_fs, inode_nr, (struct ext2_inode*) item->inode, pos.size))
goto errout;
item->transaction.start = item->transaction.end = 0;
+#ifdef DEBUG
+ fprintf(stdout,"*;");
+#endif
}
else {
@@ -706,7 +718,7 @@ struct ring_buf* get_j_inode_list(struct ext2_super_block *es, ext2_ino_t inode_
//FIXME: check more bad Inode
if (get_inode_mode_type(ext2fs_le16_to_cpu(inode_pointer->i_mode)) == ' '){
#ifdef DEBUG
- fprintf(stdout,"Transaction %d has a bad Inode, skip\n",block_list->transaction);
+ fprintf(stdout,"!%ld;",block_list->transaction);
#endif
continue;
}
@@ -716,6 +728,9 @@ struct ring_buf* get_j_inode_list(struct ext2_super_block *es, ext2_ino_t inode_
if ((ext2fs_le32_to_cpu(inode_pointer->i_size) == same_size) &&
(ext2fs_le16_to_cpu(inode_pointer->i_links_count == same_link_count))){
item->transaction.end = block_list->transaction;
+#ifdef DEBUG
+ fprintf(stdout,"-;");
+#endif
continue;
}
}
@@ -745,6 +760,9 @@ struct ring_buf* get_j_inode_list(struct ext2_super_block *es, ext2_ino_t inode_
#else
memcpy(item->inode, inode_buf, pos.size);
#endif
+#ifdef DEBUG
+ fprintf(stdout,"%ld;",block_list->transaction);
+#endif
item->transaction.start = block_list->transaction;
item->transaction.end = block_list->transaction;
ctime = item->inode->i_ctime;
@@ -765,6 +783,9 @@ struct ring_buf* get_j_inode_list(struct ext2_super_block *es, ext2_ino_t inode_
journal_tag_buf = NULL;
}
r_begin(buf);
+#ifdef DEBUG
+ fprintf(stdout,"<OK> %ld\n",buf->count);
+#endif
return buf;
errout:
@@ -781,6 +802,9 @@ errout:
ring_del(buf);
buf = NULL;
}
+#ifdef DEBUG
+ fprintf(stdout,"<NULL>\n");
+#endif
return NULL;
}
diff --git a/src/journal.c b/src/journal.c
index ec75956..07ea4e3 100644
--- a/src/journal.c
+++ b/src/journal.c
@@ -454,6 +454,9 @@ int get_last_block(char *buf, blk_t *block, __u32 t_start, __u32 t_end){
if ((!t_start) && (!t_end)){
//there is no transaction, it is not from a journal Inode
+#ifdef DEBUG
+ printf("DIR_BLOCK (F) %lld\n", (blk64_t)*block);
+#endif
return io_channel_read_blk(current_fs->io, *block, 1, buf);
}
@@ -479,6 +482,9 @@ int get_last_block(char *buf, blk_t *block, __u32 t_start, __u32 t_end){
retval = read_journal_block((j_block) ? (j_block * blksize) : (block_list->j_blocknr * blksize),
buf , current_fs->blocksize , &got);
+#ifdef DEBUG
+ printf("DIR_BLOCK (J) %lld (%ld <-> %ld) JB=%ld : %d\n", (blk64_t)*block,t_start,t_end, j_block, retval );
+#endif
if (retval) {
retval = BLOCK_ERROR ;
}
@@ -486,6 +492,9 @@ int get_last_block(char *buf, blk_t *block, __u32 t_start, __u32 t_end){
}
// if not in journal found, use real block
+#ifdef DEBUG
+ printf("DIR_BLOCK (N) %lld\n", (blk64_t)*block);
+#endif
retval = io_channel_read_blk(current_fs->io, *block, 1, buf);
@@ -569,7 +578,7 @@ static void extract_descriptor_block(char *buf, journal_superblock_t *jsb,
offset = sizeof(journal_header_t);
blocknr = *blockp;
#ifdef DEBUG
- fprintf(stderr, "Dumping descriptor block, sequence %u, at block %u:\n", transaction, blocknr);
+ fprintf(stdout, "D-Block %u & %u: ", transaction, blocknr);
#endif
++blocknr;
if (blocknr >= jsb->s_maxlen) {
@@ -601,9 +610,10 @@ static void extract_descriptor_block(char *buf, journal_superblock_t *jsb,
offset += 16;
#ifdef DEBUG
- fprintf(stderr, " FS block %12lu logged at ", tag_block);
- fprintf(stderr, "sequence %u, ", transaction);
- fprintf(stderr, "journal block %u (flags 0x%x)\n", blocknr,tag_flags);
+// fprintf(stderr, " FS block %12lu logged at ", tag_block);
+// fprintf(stderr, "sequence %u, ", transaction);
+// fprintf(stderr, "journal block %u (flags 0x%x)\n", blocknr,tag_flags);
+ fprintf(stdout,"*");
#endif
pt->f_blocknr = tag_block ;
if (tag_size > JBD_TAG_SIZE32) pt->f_blocknr |= (__u64)be32_to_cpu(tag->t_blocknr_high) << 32;
@@ -664,10 +674,10 @@ static int init_journal(void)
blocknr = (blocksize == 1024) ? 2 : 1;
uuid_unparse(sb->s_uuid, jsb_buffer);
#ifdef DEBUG
- fprintf(stderr, "Ext2 superblock header found.");
- fprintf(stderr, "\tuuid=%s", jsb_buffer);
- fprintf(stderr, "\tblocksize=%d", blocksize);
- fprintf(stderr, "\tjournal data size %lu\n",(unsigned long) sb->s_blocks_count);
+ fprintf(stdout, "Ext2 superblock header found.");
+ fprintf(stdout, "\tuuid=%s", jsb_buffer);
+ fprintf(stdout, "\tblocksize=%d", blocksize);
+ fprintf(stdout, "\tjournal data size %lu\n",(unsigned long) sb->s_blocks_count);
#endif
}
@@ -698,7 +708,7 @@ static int init_journal(void)
}
#ifdef DEBUG
- fprintf(stderr, "Journal starts at block %u, transaction %u\n", blocknr, transaction);
+ fprintf(stdout, "Journal starts at block %u, transaction %u\n", blocknr, transaction);
#endif
while ( blocknr < maxlen ){
retval = read_journal_block(blocknr*blocksize, buf, blocksize, &got);
@@ -714,15 +724,15 @@ static int init_journal(void)
if (magic != JFS_MAGIC_NUMBER) {
#ifdef DEBUG
- fprintf (stderr, "No magic number at block %u: skip this block .\n", blocknr);
+// fprintf (stdout, "No magic number at block %u: skip this block\n", blocknr);
+ fprintf(stdout,"-");
#endif
if ( ! wrapflag ) wrapflag = WRAP_ON ;
blocknr++ ;
continue;
}
#ifdef DEBUG
- fprintf (stderr, "Found expected sequence %u, type %u (%s) at block %u\n",
- sequence, blocktype, type_to_name(blocktype), blocknr);
+ fprintf (stdout, "\n%u (%s) T=%u JB=%u\n", blocktype, type_to_name(blocktype), sequence, blocknr);
#endif
if ( ! wrapflag ) wrapflag = WRAP_OFF ;
@@ -744,6 +754,9 @@ static int init_journal(void)
return JOURNAL_OPEN;
}
}
+#ifdef DEBUG
+ fprintf(stdout,"\nJournal init complete: %ld block copy\n",pt_count);
+#endif
return JOURNAL_OPEN ;
errout:
diff --git a/src/lookup_local.c b/src/lookup_local.c
index 403d4c3..a48daa2 100644
--- a/src/lookup_local.c
+++ b/src/lookup_local.c
@@ -515,6 +515,9 @@ void lookup_local(char* des_dir, struct dir_list_head_t * dir, __u32 t_after , _
lookup_local(des_dir,d_list, t_after, t_before, flag);
}
else {
+#ifdef DEBUG
+ printf(">>%s>>\n",dir->pathname);
+#endif
if (flag & DOUPLE_QUOTES_LIST)
c = '"';
lp = GET_FIRST(dir);
@@ -553,6 +556,9 @@ void lookup_local(char* des_dir, struct dir_list_head_t * dir, __u32 t_after , _
if (d_list){
//recursion for directory
lookup_local(des_dir, d_list, t_after, t_before, flag);
+#ifdef DEBUG
+ printf("<<%s<<\n",dir->pathname);
+#endif
}
else{
//function for all files apart from dir
diff --git a/src/recover.c b/src/recover.c
index e12c675..b0dddd2 100644
--- a/src/recover.c
+++ b/src/recover.c
@@ -81,7 +81,7 @@ void recover_list(char *des_dir, char *input_file,__u32 t_after, __u32 t_before,
struct ext2_inode* r_inode;
r_item *item = NULL;
- f = fopen(input_file,"a+");
+ f = fopen(input_file,"r");
if (f) {
rewind(f);
maxlen = 512;
@@ -102,7 +102,9 @@ void recover_list(char *des_dir, char *input_file,__u32 t_after, __u32 t_before,
continue;
inode_nr = local_namei(NULL,filename,t_after,t_before,DELETED_OPT);
if(! inode_nr){
-// printf("no found %s\n",filename);
+#ifdef DEBUG
+ printf("Filename %s not found\n",filename);
+#endif
continue;
}
i_list = get_j_inode_list(current_fs->super, inode_nr);
@@ -113,19 +115,23 @@ void recover_list(char *des_dir, char *input_file,__u32 t_after, __u32 t_before,
if (! LINUX_S_ISDIR(r_inode->i_mode) )
recover_file(des_dir,"", filename, r_inode, inode_nr ,flag);
}
-// else
-// printf("no found %s\n",filename);
+#ifdef DEBUG
+ else
+ printf("no Inode found for %s\n",filename);
+#endif
if (i_list) ring_del(i_list);
}
-// else
-// printf("no filename found in : \"%s\"",lineptr);
+#ifdef DEBUG
+ else
+ printf("Filename not found in : \"%s\"",lineptr);
+#endif
}
}
}
errout:
- fclose(f);
+ if (f) fclose(f);
if (lineptr)
free(lineptr);
if (filename)
@@ -182,6 +188,10 @@ static int write_block ( ext2_filsys fs, blk_t *blocknr, e2_blkcnt_t blockcnt,
errcode_t retval;
int blocksize = fs->blocksize;
+#ifdef DEBUG
+ printf("%c",(ext2fs_test_block_bitmap ( fs->block_map, *blocknr ))? 'X' : 'O');
+#endif
+
if (((struct privat*)priv)->flag){
int allocated = ext2fs_test_block_bitmap ( fs->block_map, *blocknr );
if ( allocated ){
@@ -268,7 +278,12 @@ int recover_file( char* des_dir,char* pathname, char* filename, struct ext2_inod
struct utimbuf touchtime;
mode_t i_mode;
int major, minor, type;
-
+
+#ifdef DEBUG
+ printf("RECOVER : INODE=%ld FILENAME=%s/%s\n",inode_nr, pathname,filename);
+ dump_inode(stdout, "",inode_nr, (struct ext2_inode *)inode, 0);
+#endif
+
p1 = pathname;
while (*p1 == '/') p1++;
helpname = malloc(strlen(des_dir) + 15);
@@ -335,6 +350,9 @@ int recover_file( char* des_dir,char* pathname, char* filename, struct ext2_inod
priv.error = 0;
// iterate Data Blocks and if not allocated, write to file
retval = local_block_iterate3 ( current_fs, *inode, BLOCK_FLAG_DATA_ONLY, NULL, write_block, &priv );
+#ifdef DEBUG
+ printf("\n");
+#endif
if (retval || priv.error){
// error or blocks allocated , we delete the tempfile and goto out
close(priv.fd);