summaryrefslogtreecommitdiff
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
parent972f26a10e5f0bacf12b2df2e9a00896b007e600 (diff)
enable debug
-rwxr-xr-xconfigure36
-rw-r--r--configure.in3
-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
9 files changed, 124 insertions, 39 deletions
diff --git a/configure b/configure
index 3d258c4..b3fbfac 100755
--- a/configure
+++ b/configure
@@ -902,6 +902,7 @@ with_pic
enable_fast_install
with_gnu_ld
enable_libtool_lock
+enable_debug
'
ac_precious_vars='build_alias
host_alias
@@ -1547,6 +1548,7 @@ Optional Features:
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
+ --enable-debug Turn on debugging
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@@ -4359,13 +4361,13 @@ if test "${lt_cv_nm_interface+set}" = set; then
else
lt_cv_nm_interface="BSD nm"
echo "int some_variable = 0;" > conftest.$ac_ext
- (eval echo "\"\$as_me:4362: $ac_compile\"" >&5)
+ (eval echo "\"\$as_me:4364: $ac_compile\"" >&5)
(eval "$ac_compile" 2>conftest.err)
cat conftest.err >&5
- (eval echo "\"\$as_me:4365: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+ (eval echo "\"\$as_me:4367: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
cat conftest.err >&5
- (eval echo "\"\$as_me:4368: output\"" >&5)
+ (eval echo "\"\$as_me:4370: output\"" >&5)
cat conftest.out >&5
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
lt_cv_nm_interface="MS dumpbin"
@@ -5571,7 +5573,7 @@ ia64-*-hpux*)
;;
*-*-irix6*)
# Find out which ABI we are using.
- echo '#line 5574 "configure"' > conftest.$ac_ext
+ echo '#line 5576 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
@@ -7424,11 +7426,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7427: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7429: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:7431: \$? = $ac_status" >&5
+ echo "$as_me:7433: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -7763,11 +7765,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7766: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7768: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:7770: \$? = $ac_status" >&5
+ echo "$as_me:7772: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -7868,11 +7870,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7871: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7873: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:7875: \$? = $ac_status" >&5
+ echo "$as_me:7877: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -7923,11 +7925,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7926: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7928: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:7930: \$? = $ac_status" >&5
+ echo "$as_me:7932: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -10723,7 +10725,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 10726 "configure"
+#line 10728 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -10819,7 +10821,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 10822 "configure"
+#line 10824 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -11046,6 +11048,12 @@ CC="$lt_save_CC"
# Only expand once:
+# Check whether --enable-debug was given.
+if test "${enable_debug+set}" = set; then
+ enableval=$enable_debug; if test "$GCC" = "yes"; then CPPFLAGS="$CPPFLAGS -DDEBUG"; fi
+fi
+
+
ac_config_files="$ac_config_files Makefile src/Makefile"
diff --git a/configure.in b/configure.in
index 3577f40..1062f89 100644
--- a/configure.in
+++ b/configure.in
@@ -6,5 +6,8 @@ AM_INIT_AUTOMAKE(ext4magic, 0.1.2)
AC_LANG_C
AC_PROG_CC
AM_PROG_LIBTOOL
+AC_ARG_ENABLE(debug,[ --enable-debug Turn on debugging ],
+ [if test "$GCC" = "yes"; then CPPFLAGS="$CPPFLAGS -DDEBUG"; fi])
+
AC_OUTPUT(Makefile src/Makefile)
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);