New function status_inc() to increment params->status

This commit is contained in:
Christophe Grenier 2013-05-15 09:57:33 +02:00
parent 068c665c49
commit 7afe29c487
3 changed files with 133 additions and 123 deletions

View file

@ -1023,3 +1023,51 @@ const char *status_to_name(const photorec_status_t status)
return "STATUS_QUIT"; return "STATUS_QUIT";
} }
} }
void status_inc(struct ph_param *params, const struct ph_options *options)
{
params->offset=-1;
switch(params->status)
{
case STATUS_UNFORMAT:
params->status=STATUS_FIND_OFFSET;
break;
case STATUS_FIND_OFFSET:
params->status=(options->mode_ext2>0?STATUS_EXT2_ON:STATUS_EXT2_OFF);
params->file_nbr=0;
break;
case STATUS_EXT2_ON:
if(options->paranoid>1)
params->status=STATUS_EXT2_ON_BF;
else if(options->paranoid==1 && options->keep_corrupted_file>0)
params->status=STATUS_EXT2_ON_SAVE_EVERYTHING;
else
params->status=STATUS_QUIT;
break;
case STATUS_EXT2_ON_BF:
if(options->keep_corrupted_file>0)
params->status=STATUS_EXT2_ON_SAVE_EVERYTHING;
else
params->status=STATUS_QUIT;
break;
case STATUS_EXT2_OFF:
if(options->paranoid>1)
params->status=STATUS_EXT2_OFF_BF;
else if(options->paranoid==1 && options->keep_corrupted_file>0)
params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
else
params->status=STATUS_QUIT;
break;
case STATUS_EXT2_OFF_BF:
if(options->keep_corrupted_file>0)
params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
else
params->status=STATUS_QUIT;
break;
default:
params->status=STATUS_QUIT;
break;
}
}

View file

@ -82,6 +82,7 @@ void set_filename(file_recovery_t *file_recovery, struct ph_param *params);
uint64_t set_search_start(struct ph_param *params, alloc_data_t **new_current_search_space, alloc_data_t *list_search_space); uint64_t set_search_start(struct ph_param *params, alloc_data_t **new_current_search_space, alloc_data_t *list_search_space);
void params_reset(struct ph_param *params, const struct ph_options *options); void params_reset(struct ph_param *params, const struct ph_options *options);
const char *status_to_name(const photorec_status_t status); const char *status_to_name(const photorec_status_t status);
void status_inc(struct ph_param *params, const struct ph_options *options);
#ifdef __cplusplus #ifdef __cplusplus
} /* closing brace for extern "C" */ } /* closing brace for extern "C" */
#endif #endif

View file

@ -844,12 +844,13 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
wattroff(stdscr, A_REVERSE); wattroff(stdscr, A_REVERSE);
wrefresh(stdscr); wrefresh(stdscr);
#endif #endif
if(params->status==STATUS_UNFORMAT) switch(params->status)
{ {
case STATUS_UNFORMAT:
ind_stop=fat_unformat(params, options, list_search_space); ind_stop=fat_unformat(params, options, list_search_space);
params->blocksize=blocksize_is_known; params->blocksize=blocksize_is_known;
} break;
else if(params->status==STATUS_FIND_OFFSET) case STATUS_FIND_OFFSET:
{ {
uint64_t start_offset=0; uint64_t start_offset=0;
if(blocksize_is_known>0) if(blocksize_is_known>0)
@ -869,17 +870,20 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
#endif #endif
update_blocksize(params->blocksize, list_search_space, start_offset); update_blocksize(params->blocksize, list_search_space, start_offset);
} }
else if(params->status==STATUS_EXT2_ON_BF || params->status==STATUS_EXT2_OFF_BF) break;
{ case STATUS_EXT2_ON_BF:
case STATUS_EXT2_OFF_BF:
ind_stop=photorec_bf(params, options, list_search_space); ind_stop=photorec_bf(params, options, list_search_space);
} break;
else default:
{
ind_stop=photorec_aux(params, options, list_search_space); ind_stop=photorec_aux(params, options, list_search_space);
break;
} }
session_save(list_search_space, params, options); session_save(list_search_space, params, options);
if(ind_stop==PSTATUS_ENOSPC) switch(ind_stop)
{
case PSTATUS_ENOSPC:
{ /* no more space */ { /* no more space */
#ifdef HAVE_NCURSES #ifdef HAVE_NCURSES
char *dst; char *dst;
@ -910,13 +914,12 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
params->status=STATUS_QUIT; params->status=STATUS_QUIT;
#endif #endif
} }
else if(ind_stop==PSTATUS_EACCES) break;
{ case PSTATUS_EACCES:
if(interface_cannot_create_file()!=0) if(interface_cannot_create_file()!=0)
params->status=STATUS_QUIT; params->status=STATUS_QUIT;
} break;
else if(ind_stop==PSTATUS_STOP) case PSTATUS_STOP:
{
if(session_save(list_search_space, params, options) < 0) if(session_save(list_search_space, params, options) < 0)
{ {
/* Failed to save the session! */ /* Failed to save the session! */
@ -932,54 +935,12 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
params->status=STATUS_QUIT; params->status=STATUS_QUIT;
#endif #endif
} }
}
if(ind_stop==PSTATUS_OK)
{
params->offset=-1;
switch(params->status)
{
case STATUS_UNFORMAT:
params->status=STATUS_FIND_OFFSET;
break; break;
case STATUS_FIND_OFFSET: case PSTATUS_OK:
params->status=(options->mode_ext2>0?STATUS_EXT2_ON:STATUS_EXT2_OFF); status_inc(params, options);
params->file_nbr=0;
break;
case STATUS_EXT2_ON:
if(options->paranoid>1)
params->status=STATUS_EXT2_ON_BF;
else if(options->paranoid==1 && options->keep_corrupted_file>0)
params->status=STATUS_EXT2_ON_SAVE_EVERYTHING;
else
params->status=STATUS_QUIT;
break;
case STATUS_EXT2_ON_BF:
if(options->keep_corrupted_file>0)
params->status=STATUS_EXT2_ON_SAVE_EVERYTHING;
else
params->status=STATUS_QUIT;
break;
case STATUS_EXT2_OFF:
if(options->paranoid>1)
params->status=STATUS_EXT2_OFF_BF;
else if(options->paranoid==1 && options->keep_corrupted_file>0)
params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
else
params->status=STATUS_QUIT;
break;
case STATUS_EXT2_OFF_BF:
if(options->keep_corrupted_file>0)
params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
else
params->status=STATUS_QUIT;
break;
default:
params->status=STATUS_QUIT;
break;
}
if(params->status==STATUS_QUIT) if(params->status==STATUS_QUIT)
unlink("photorec.ses"); unlink("photorec.ses");
break;
} }
{ {
const time_t current_time=time(NULL); const time_t current_time=time(NULL);