summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-05-14 09:08:37 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2013-05-14 09:08:37 +0200
commita643146280fffb97ff681d17a9b35fc15e6b67f8 (patch)
tree2fc0acc8a7ce0ec6dd175c66feb5c552eb285667 /src
parent3c70faa00155a6a6d2ecb404a7f558a3ee638e86 (diff)
Move some code to new functions params_reset() and status_to_name()
Diffstat (limited to 'src')
-rw-r--r--src/photorec.c42
-rw-r--r--src/photorec.h2
-rw-r--r--src/phrecn.c40
3 files changed, 50 insertions, 34 deletions
diff --git a/src/photorec.c b/src/photorec.c
index de1d45f..bc5b7fa 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -35,6 +35,12 @@
#include <string.h>
#endif
#include <errno.h>
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
#include "types.h"
#include "common.h"
#include "fnctdsk.h"
@@ -980,4 +986,40 @@ uint64_t set_search_start(struct ph_param *params, alloc_data_t **new_current_se
return offset;
}
+void params_reset(struct ph_param *params, const struct ph_options *options)
+{
+ params->file_nbr=0;
+ params->status=STATUS_FIND_OFFSET;
+ params->real_start_time=time(NULL);
+ params->dir_num=1;
+ params->file_stats=init_file_stats(options->list_file_format);
+ params->offset=-1;
+ if(params->blocksize==0)
+ params->blocksize=params->disk->sector_size;
+}
+const char *status_to_name(const photorec_status_t status)
+{
+ switch(status)
+ {
+ case STATUS_UNFORMAT:
+ return "STATUS_UNFORMAT";
+ case STATUS_FIND_OFFSET:
+ return "STATUS_FIND_OFFSET";
+ case STATUS_EXT2_ON:
+ return "STATUS_EXT2_ON";
+ case STATUS_EXT2_ON_BF:
+ return "STATUS_EXT2_ON_BF";
+ case STATUS_EXT2_OFF:
+ return "STATUS_EXT2_OFF";
+ case STATUS_EXT2_OFF_BF:
+ return "STATUS_EXT2_OFF_BF";
+ case STATUS_EXT2_ON_SAVE_EVERYTHING:
+ return "STATUS_EXT2_ON_SAVE_EVERYTHING";
+ case STATUS_EXT2_OFF_SAVE_EVERYTHING:
+ return "STATUS_EXT2_OFF_SAVE_EVERYTHING";
+ case STATUS_QUIT :
+ default:
+ return "STATUS_QUIT";
+ }
+}
diff --git a/src/photorec.h b/src/photorec.h
index 49c15d0..0e5949b 100644
--- a/src/photorec.h
+++ b/src/photorec.h
@@ -77,6 +77,8 @@ void info_list_search_space(const alloc_data_t *list_search_space, const alloc_d
void free_search_space(alloc_data_t *list_search_space);
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);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/phrecn.c b/src/phrecn.c
index 9a72e4d..b765e27 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -756,12 +756,7 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
{
int ind_stop=0;
const unsigned int blocksize_is_known=params->blocksize;
- params->file_nbr=0;
- params->status=STATUS_FIND_OFFSET;
- params->real_start_time=time(NULL);
- params->dir_num=1;
- params->file_stats=init_file_stats(options->list_file_format);
- params->offset=-1;
+ params_reset(params, options);
if(params->cmd_run!=NULL && params->cmd_run[0]!='\0')
{
while(params->cmd_run[0]==',')
@@ -819,8 +814,6 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
screen_buffer_reset();
log_info("\nAnalyse\n");
log_partition(params->disk, params->partition);
- if(params->blocksize==0)
- params->blocksize=params->disk->sector_size;
/* make the first recup_dir */
params->dir_num=photorec_mkdir(params->recup_dir, params->dir_num);
@@ -833,20 +826,10 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
for(params->pass=0; params->status!=STATUS_QUIT; params->pass++)
{
- unsigned int old_file_nbr=params->file_nbr;
+ const unsigned int old_file_nbr=params->file_nbr;
log_info("Pass %u (blocksize=%u) ", params->pass, params->blocksize);
- switch(params->status)
- {
- case STATUS_UNFORMAT: log_info("STATUS_UNFORMAT\n"); break;
- case STATUS_FIND_OFFSET: log_info("STATUS_FIND_OFFSET\n"); break;
- case STATUS_EXT2_ON: log_info("STATUS_EXT2_ON\n"); break;
- case STATUS_EXT2_ON_BF: log_info("STATUS_EXT2_ON_BF\n"); break;
- case STATUS_EXT2_OFF: log_info("STATUS_EXT2_OFF\n"); break;
- case STATUS_EXT2_OFF_BF: log_info("STATUS_EXT2_OFF_BF\n"); break;
- case STATUS_EXT2_ON_SAVE_EVERYTHING: log_info("STATUS_EXT2_ON_SAVE_EVERYTHING\n"); break;
- case STATUS_EXT2_OFF_SAVE_EVERYTHING: log_info("STATUS_EXT2_OFF_SAVE_EVERYTHING\n"); break;
- case STATUS_QUIT : log_info("STATUS_QUIT\n"); break;
- }
+ log_info("%s\n", status_to_name(params->status));
+
#ifdef HAVE_NCURSES
aff_copy(stdscr);
wmove(stdscr, 4, 0);
@@ -968,19 +951,13 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
else if(options->paranoid==1 && options->keep_corrupted_file>0)
params->status=STATUS_EXT2_ON_SAVE_EVERYTHING;
else
- {
params->status=STATUS_QUIT;
- unlink("photorec.ses");
- }
break;
case STATUS_EXT2_ON_BF:
if(options->keep_corrupted_file>0)
params->status=STATUS_EXT2_ON_SAVE_EVERYTHING;
else
- {
params->status=STATUS_QUIT;
- unlink("photorec.ses");
- }
break;
case STATUS_EXT2_OFF:
if(options->paranoid>1)
@@ -988,25 +965,20 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
else if(options->paranoid==1 && options->keep_corrupted_file>0)
params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
else
- {
params->status=STATUS_QUIT;
- unlink("photorec.ses");
- }
break;
case STATUS_EXT2_OFF_BF:
if(options->keep_corrupted_file>0)
params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
else
- {
params->status=STATUS_QUIT;
- unlink("photorec.ses");
- }
break;
default:
params->status=STATUS_QUIT;
- unlink("photorec.ses");
break;
}
+ if(params->status==STATUS_QUIT)
+ unlink("photorec.ses");
}
{
const time_t current_time=time(NULL);