summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-05-15 09:57:33 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2013-05-15 09:57:33 +0200
commit7afe29c487f68e7fe3978e3ffd10a6860953c357 (patch)
treeaac40d395f849600495e3a72e48ad9ac45d88509
parent068c665c49be3a6f0efd23175f6e19aaff7733b6 (diff)
New function status_inc() to increment params->status
-rw-r--r--src/photorec.c48
-rw-r--r--src/photorec.h1
-rw-r--r--src/phrecn.c207
3 files changed, 133 insertions, 123 deletions
diff --git a/src/photorec.c b/src/photorec.c
index bc5b7fa..0896e3a 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -1023,3 +1023,51 @@ const char *status_to_name(const photorec_status_t status)
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;
+ }
+}
+
+
diff --git a/src/photorec.h b/src/photorec.h
index 28ff273..eade736 100644
--- a/src/photorec.h
+++ b/src/photorec.h
@@ -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);
void params_reset(struct ph_param *params, const struct ph_options *options);
const char *status_to_name(const photorec_status_t status);
+void status_inc(struct ph_param *params, const struct ph_options *options);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/phrecn.c b/src/phrecn.c
index db5936b..821c280 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -844,142 +844,103 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
wattroff(stdscr, A_REVERSE);
wrefresh(stdscr);
#endif
- if(params->status==STATUS_UNFORMAT)
+ switch(params->status)
{
- ind_stop=fat_unformat(params, options, list_search_space);
- params->blocksize=blocksize_is_known;
- }
- else if(params->status==STATUS_FIND_OFFSET)
- {
- uint64_t start_offset=0;
- if(blocksize_is_known>0)
- {
- ind_stop=PSTATUS_OK;
- if(!td_list_empty(&list_search_space->list))
- start_offset=(td_list_entry(list_search_space->list.next, alloc_data_t, list))->start % params->blocksize;
- }
- else
- {
- ind_stop=photorec_find_blocksize(params, options, list_search_space);
- params->blocksize=find_blocksize(list_search_space, params->disk->sector_size, &start_offset);
- }
+ case STATUS_UNFORMAT:
+ ind_stop=fat_unformat(params, options, list_search_space);
+ params->blocksize=blocksize_is_known;
+ break;
+ case STATUS_FIND_OFFSET:
+ {
+ uint64_t start_offset=0;
+ if(blocksize_is_known>0)
+ {
+ ind_stop=PSTATUS_OK;
+ if(!td_list_empty(&list_search_space->list))
+ start_offset=(td_list_entry(list_search_space->list.next, alloc_data_t, list))->start % params->blocksize;
+ }
+ else
+ {
+ ind_stop=photorec_find_blocksize(params, options, list_search_space);
+ params->blocksize=find_blocksize(list_search_space, params->disk->sector_size, &start_offset);
+ }
#ifdef HAVE_NCURSES
- if(options->expert>0)
- params->blocksize=menu_choose_blocksize(params->blocksize, params->disk->sector_size, &start_offset);
+ if(options->expert>0)
+ params->blocksize=menu_choose_blocksize(params->blocksize, params->disk->sector_size, &start_offset);
#endif
- update_blocksize(params->blocksize, list_search_space, start_offset);
- }
- else if(params->status==STATUS_EXT2_ON_BF || params->status==STATUS_EXT2_OFF_BF)
- {
- ind_stop=photorec_bf(params, options, list_search_space);
- }
- else
- {
- ind_stop=photorec_aux(params, options, list_search_space);
+ update_blocksize(params->blocksize, list_search_space, start_offset);
+ }
+ break;
+ case STATUS_EXT2_ON_BF:
+ case STATUS_EXT2_OFF_BF:
+ ind_stop=photorec_bf(params, options, list_search_space);
+ break;
+ default:
+ ind_stop=photorec_aux(params, options, list_search_space);
+ break;
}
session_save(list_search_space, params, options);
- if(ind_stop==PSTATUS_ENOSPC)
- { /* no more space */
-#ifdef HAVE_NCURSES
- char *dst;
- char *res;
- dst=strdup(params->recup_dir);
- if(dst!=NULL)
- {
- res=strrchr(dst, '/');
- if(res!=NULL)
- *res='\0';
- }
- res=ask_location("Warning: no free space available. Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", dst);
- free(dst);
- if(res==NULL)
- params->status=STATUS_QUIT;
- else
- {
- free(params->recup_dir);
- params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
- strcpy(params->recup_dir,res);
- strcat(params->recup_dir,"/");
- strcat(params->recup_dir,DEFAULT_RECUP_DIR);
- free(res);
- /* Create the directory */
- params->dir_num=photorec_mkdir(params->recup_dir,params->dir_num);
- }
-#else
- params->status=STATUS_QUIT;
-#endif
- }
- else if(ind_stop==PSTATUS_EACCES)
+ switch(ind_stop)
{
- if(interface_cannot_create_file()!=0)
- params->status=STATUS_QUIT;
- }
- else if(ind_stop==PSTATUS_STOP)
- {
- if(session_save(list_search_space, params, options) < 0)
- {
- /* Failed to save the session! */
+ case PSTATUS_ENOSPC:
+ { /* no more space */
#ifdef HAVE_NCURSES
- if(ask_confirmation("PhotoRec has been unable to save its session status. Answer Y to really Quit, N to resume the recovery")!=0)
+ char *dst;
+ char *res;
+ dst=strdup(params->recup_dir);
+ if(dst!=NULL)
+ {
+ res=strrchr(dst, '/');
+ if(res!=NULL)
+ *res='\0';
+ }
+ res=ask_location("Warning: no free space available. Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", dst);
+ free(dst);
+ if(res==NULL)
+ params->status=STATUS_QUIT;
+ else
+ {
+ free(params->recup_dir);
+ params->recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
+ strcpy(params->recup_dir,res);
+ strcat(params->recup_dir,"/");
+ strcat(params->recup_dir,DEFAULT_RECUP_DIR);
+ free(res);
+ /* Create the directory */
+ params->dir_num=photorec_mkdir(params->recup_dir,params->dir_num);
+ }
+#else
params->status=STATUS_QUIT;
#endif
- }
- else
- {
-#ifdef HAVE_NCURSES
- if(ask_confirmation("Answer Y to really Quit, N to resume the recovery")!=0)
+ }
+ break;
+ case PSTATUS_EACCES:
+ if(interface_cannot_create_file()!=0)
params->status=STATUS_QUIT;
-#endif
- }
- }
-
- if(ind_stop==PSTATUS_OK)
- {
- 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
+ break;
+ case PSTATUS_STOP:
+ if(session_save(list_search_space, params, options) < 0)
+ {
+ /* Failed to save the session! */
+#ifdef HAVE_NCURSES
+ if(ask_confirmation("PhotoRec has been unable to save its session status. Answer Y to really Quit, N to resume the recovery")!=0)
params->status=STATUS_QUIT;
- break;
- case STATUS_EXT2_OFF_BF:
- if(options->keep_corrupted_file>0)
- params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
- else
+#endif
+ }
+ else
+ {
+#ifdef HAVE_NCURSES
+ if(ask_confirmation("Answer Y to really Quit, N to resume the recovery")!=0)
params->status=STATUS_QUIT;
- break;
- default:
- params->status=STATUS_QUIT;
- break;
- }
- if(params->status==STATUS_QUIT)
- unlink("photorec.ses");
+#endif
+ }
+ break;
+ case PSTATUS_OK:
+ status_inc(params, options);
+ if(params->status==STATUS_QUIT)
+ unlink("photorec.ses");
+ break;
}
{
const time_t current_time=time(NULL);