PhotoRec: save current progress every 5 minutes

This commit is contained in:
Christophe Grenier 2013-03-24 19:49:37 +01:00
parent 8b9047aa4e
commit 8dfd9a7a46
7 changed files with 26 additions and 17 deletions

View file

@ -122,6 +122,7 @@ int main( int argc, char **argv )
params.recup_dir=NULL;
params.cmd_device=NULL;
params.cmd_run=NULL;
params.carve_free_space_only=0;
/* random (weak is ok) is need fot GPT */
srand(time(NULL));
#ifdef HAVE_SIGACTION

View file

@ -44,6 +44,7 @@ struct ph_param
char *cmd_run;
disk_t *disk;
partition_t *partition;
unsigned int carve_free_space_only;
unsigned int blocksize;
unsigned int pass;
photorec_status_t status;

View file

@ -150,7 +150,7 @@ static FILE *fopen_with_retry(const char *path, const char *mode)
}
#endif
static alloc_data_t *file_add_data(alloc_data_t *data, const uint64_t offset, const unsigned int content)
static inline alloc_data_t *file_add_data(alloc_data_t *data, const uint64_t offset, const unsigned int content)
{
if(!(data->start <= offset && offset <= data->end))
{
@ -197,6 +197,7 @@ static int photorec_aux(struct ph_param *params, const struct ph_options *option
unsigned char *buffer;
time_t start_time;
time_t previous_time;
time_t next_checkpoint;
int ind_stop=0;
unsigned int buffer_size;
const unsigned int blocksize=params->blocksize;
@ -212,6 +213,7 @@ static int photorec_aux(struct ph_param *params, const struct ph_options *option
buffer=buffer_olddata+blocksize;
start_time=time(NULL);
previous_time=start_time;
next_checkpoint=start_time+5*60;
memset(buffer_olddata,0,blocksize);
current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
offset=set_search_start(params, &current_search_space, list_search_space);
@ -477,6 +479,12 @@ static int photorec_aux(struct ph_param *params, const struct ph_options *option
params->offset=file_recovery.location.start;
else
params->offset=offset;
if(current_time >= next_checkpoint)
{
/* Save current progress */
session_save(list_search_space, params, options);
next_checkpoint=current_time+5*60;
}
}
}
#endif
@ -732,7 +740,7 @@ static void test_files(alloc_data_t *list_search_space, struct ph_param *params)
}
#endif
int photorec(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space, const unsigned int carve_free_space_only)
int photorec(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space)
{
int ind_stop=0;
const unsigned int blocksize_is_known=params->blocksize;
@ -873,7 +881,7 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
{
ind_stop=photorec_aux(params, options, list_search_space);
}
session_save(list_search_space, params, options, carve_free_space_only);
session_save(list_search_space, params, options);
if(ind_stop==3)
{ /* no more space */
@ -913,7 +921,7 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
}
else if(ind_stop==1)
{
if(session_save(list_search_space, params, options, carve_free_space_only) < 0)
if(session_save(list_search_space, params, options) < 0)
{
/* Failed to save the session! */
#ifdef HAVE_NCURSES

View file

@ -23,7 +23,7 @@
extern "C" {
#endif
int photorec(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space, const unsigned int carve_free_space_only);
int photorec(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space);
void interface_file_select(file_enable_t *files_enable, char**current_cmd);
void interface_options_photorec(struct ph_options *options, char**current_cmd);

View file

@ -79,7 +79,6 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da
list_part_t *list_part;
list_part_t *current_element;
unsigned int current_element_num;
unsigned int carve_free_space_only=0;
unsigned int user_blocksize=0;
int done=0;
int mode_init_space=(td_list_empty(&list_search_space->list)?INIT_SPACE_WHOLE:INIT_SPACE_PREINIT);
@ -178,13 +177,13 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da
{
init_search_space(list_search_space, params->disk, params->partition);
}
if(carve_free_space_only>0)
if(params->carve_free_space_only>0)
{
params->blocksize=remove_used_space(params->disk, params->partition, list_search_space);
}
if(user_blocksize > 0)
params->blocksize=user_blocksize;
photorec(params, options, list_search_space, carve_free_space_only);
photorec(params, options, list_search_space);
}
}
else if(strncmp(params->cmd_run,"options",7)==0)
@ -216,12 +215,12 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da
else if(strncmp(params->cmd_run,"wholespace",10)==0)
{
params->cmd_run+=10;
carve_free_space_only=0;
params->carve_free_space_only=0;
}
else if(strncmp(params->cmd_run,"freespace",9)==0)
{
params->cmd_run+=9;
carve_free_space_only=1;
params->carve_free_space_only=1;
}
else if(strncmp(params->cmd_run,"ext2_group,",11)==0)
{
@ -387,7 +386,7 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da
if(current_element!=NULL)
{
params->partition=current_element->part;
ask_mode_ext2(params->disk, params->partition, &options->mode_ext2, &carve_free_space_only);
ask_mode_ext2(params->disk, params->partition, &options->mode_ext2, &params->carve_free_space_only);
menu=0;
if(params->recup_dir==NULL)
{
@ -408,7 +407,7 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da
{
init_search_space(list_search_space, params->disk, params->partition);
}
if(carve_free_space_only>0)
if(params->carve_free_space_only>0)
{
aff_copy(stdscr);
wmove(stdscr,5,0);
@ -419,7 +418,7 @@ void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_da
* To carve the whole space, need to quit and reselect the params->partition */
done = 1;
}
photorec(params, options, list_search_space, carve_free_space_only);
photorec(params, options, list_search_space);
}
}
break;

View file

@ -67,7 +67,7 @@ int session_load(char **cmd_device, char **current_cmd, alloc_data_t *list_free_
if(!f_session)
{
log_info("Can't open photorec.ses file: %s\n",strerror(errno));
session_save(NULL, NULL, NULL, 0);
session_save(NULL, NULL, NULL);
return -1;
}
if(fstat(fileno(f_session), &stat_rec)<0)
@ -158,7 +158,7 @@ int session_load(char **cmd_device, char **current_cmd, alloc_data_t *list_free_
}
}
int session_save(alloc_data_t *list_free_space, struct ph_param *params, const struct ph_options *options, const unsigned int carve_free_space_only)
int session_save(alloc_data_t *list_free_space, struct ph_param *params, const struct ph_options *options)
{
FILE *f_session;
f_session=fopen(SESSION_FILENAME,"wb");
@ -248,7 +248,7 @@ int session_save(alloc_data_t *list_free_space, struct ph_param *params, const
if(options->lowmem>0)
fprintf(f_session, "lowmem,");
/* Save options - End */
if(carve_free_space_only>0)
if(params->carve_free_space_only>0)
fprintf(f_session,"freespace,");
else
fprintf(f_session,"wholespace,");

View file

@ -24,7 +24,7 @@ extern "C" {
#endif
int session_load(char **cmd_device, char **current_cmd, alloc_data_t *list_free_space);
int session_save(alloc_data_t *list_free_space, struct ph_param *params, const struct ph_options *options, const unsigned int carve_free_space_only);
int session_save(alloc_data_t *list_free_space, struct ph_param *params, const struct ph_options *options);
#ifdef __cplusplus
} /* closing brace for extern "C" */