summaryrefslogtreecommitdiffstats
path: root/src/qpsearch.cpp
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-12-21 18:18:55 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2013-12-21 18:18:55 +0100
commitb47b36998a17dccb922bc8a9591c8071f951c14f (patch)
tree9702e81b4ad3b3ac7c7933390711ff869e76f7b5 /src/qpsearch.cpp
parent5f4faee1f6f82fb3667653a951714c80932522db (diff)
Remove loc field from struct file_recovery_struct, use location instead
Diffstat (limited to 'src/qpsearch.cpp')
-rw-r--r--src/qpsearch.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/qpsearch.cpp b/src/qpsearch.cpp
index 87962f3..8e4e93e 100644
--- a/src/qpsearch.cpp
+++ b/src/qpsearch.cpp
@@ -57,6 +57,7 @@
#include "fat_dir.h"
#include "list.h"
#include "filegen.h"
+#include "photorec.h"
#include "sessionp.h"
#include "log.h"
#include "file_tar.h"
@@ -144,6 +145,7 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
params->disk->pread(params->disk, buffer, READ_SIZE, offset);
while(current_search_space!=list_search_space)
{
+ data_check_t res=DC_SCAN;
int file_recovered=0;
uint64_t old_offset=offset;
#ifdef DEBUG
@@ -199,17 +201,15 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
}
if(file_recovery_new.file_stat!=NULL && file_recovery_new.file_stat->file_hint!=NULL)
{
- current_search_space=file_found(current_search_space, offset, file_recovery_new.file_stat);
- file_recovery_new.loc=current_search_space;
file_recovery_new.location.start=offset;
- if(options->verbose > 1)
- log_trace("A known header has been found, recovery of the previous file is finished\n");
+ if(file_recovery.file_stat!=NULL)
{
- file_recovered=file_finish2(&file_recovery, params, options, list_search_space, &current_search_space, &offset);
+ if(options->verbose > 1)
+ log_trace("A known header has been found, recovery of the previous file is finished\n");
+ file_recovered=file_finish2(&file_recovery, params, options, list_search_space);
+ if(options->lowmem > 0)
+ forget(list_search_space,current_search_space);
}
- reset_file_recovery(&file_recovery);
- if(options->lowmem > 0)
- forget(list_search_space,current_search_space);
if(file_recovered==0)
{
file_recovery_cpy(&file_recovery, &file_recovery_new);
@@ -262,13 +262,13 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
}
if(file_recovery.file_stat!=NULL)
{
- data_check_t res=DC_CONTINUE;
/* try to skip ext2/ext3 indirect block */
if((params->status==STATUS_EXT2_ON || params->status==STATUS_EXT2_ON_SAVE_EVERYTHING) &&
file_recovery.file_size_on_disk>=12*blocksize &&
ind_block(buffer,blocksize)!=0)
{
- current_search_space=file_add_data(current_search_space, offset, 0);
+ file_block_append(&file_recovery, list_search_space, &current_search_space, &offset, blocksize, 0);
+ res=DC_CONTINUE;
file_recovery.file_size_on_disk+=blocksize;
if(options->verbose > 1)
{
@@ -300,9 +300,11 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
}
if(ind_stop==PSTATUS_OK)
{
- current_search_space=file_add_data(current_search_space, offset, 1);
+ file_block_append(&file_recovery, list_search_space, &current_search_space, &offset, blocksize, 1);
if(file_recovery.data_check!=NULL)
res=file_recovery.data_check(buffer_olddata,2*blocksize,&file_recovery);
+ else
+ res=DC_CONTINUE;
file_recovery.file_size+=blocksize;
file_recovery.file_size_on_disk+=blocksize;
if(res==DC_STOP)
@@ -326,8 +328,7 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
}
if(res==DC_STOP || res==DC_ERROR)
{
- file_recovered=file_finish2(&file_recovery, params, options, list_search_space, &current_search_space, &offset);
- reset_file_recovery(&file_recovery);
+ file_recovered=file_finish2(&file_recovery, params, options, list_search_space);
if(options->lowmem > 0)
forget(list_search_space,current_search_space);
}
@@ -339,9 +340,12 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
}
else if(file_recovered==0)
{
- get_next_sector(list_search_space, &current_search_space,&offset,blocksize);
- if(offset > offset_before_back)
- back=0;
+ if(res==DC_SCAN)
+ {
+ get_next_sector(list_search_space, &current_search_space,&offset,blocksize);
+ if(offset > offset_before_back)
+ back=0;
+ }
}
else if(file_recovered>0)
{
@@ -360,8 +364,7 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
current_search_space, current_search_space->list.prev, current_search_space->list.next);
log_trace("End of media\n");
#endif
- file_recovered=file_finish2(&file_recovery, params, options, list_search_space, &current_search_space, &offset);
- reset_file_recovery(&file_recovery);
+ file_recovered=file_finish2(&file_recovery, params, options, list_search_space);
if(options->lowmem > 0)
forget(list_search_space,current_search_space);
}
@@ -388,8 +391,7 @@ pstatus_t QPhotorec::photorec_aux(alloc_data_t *list_search_space)
}
if(ind_stop==PSTATUS_OK)
{
- time_t current_time;
- current_time=time(NULL);
+ const time_t current_time=time(NULL);
if(current_time > previous_time)
{
previous_time=current_time;