summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2011-08-20 19:28:56 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2011-08-20 19:28:56 +0200
commitbde3110ead880ab5557137903bc550885dd6b6b1 (patch)
treee1d037fb42d1923c0224d64825af61cd05ce69a7
parent792e9327235363d883818a6f8eaae5b74ae7fa0f (diff)
Huge code cleanup for Photorec: reduce the numbers of parameters of some functions
-rw-r--r--src/fat_unformat.c71
-rw-r--r--src/fat_unformat.h2
-rw-r--r--src/pdisksel.c31
-rw-r--r--src/pdisksel.h2
-rw-r--r--src/phbf.c100
-rw-r--r--src/phbf.h2
-rw-r--r--src/phbs.c63
-rw-r--r--src/phbs.h2
-rw-r--r--src/phmain.c43
-rw-r--r--src/phnc.c35
-rw-r--r--src/phnc.h2
-rw-r--r--src/photorec.c123
-rw-r--r--src/photorec.h28
-rw-r--r--src/phrecn.c312
-rw-r--r--src/phrecn.h2
-rw-r--r--src/ppartsel.c184
-rw-r--r--src/ppartsel.h2
-rw-r--r--src/sessionp.c13
-rw-r--r--src/sessionp.h2
19 files changed, 497 insertions, 522 deletions
diff --git a/src/fat_unformat.c b/src/fat_unformat.c
index d816074..87e8c05 100644
--- a/src/fat_unformat.c
+++ b/src/fat_unformat.c
@@ -53,7 +53,7 @@
#include "setdate.h"
#define READ_SIZE 1024*512
-static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const int verbose, const int interface, unsigned int *sectors_per_cluster, uint64_t *offset_org, alloc_data_t *list_search_space)
+static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const int verbose, unsigned int *sectors_per_cluster, uint64_t *offset_org, alloc_data_t *list_search_space)
{
uint64_t offset=0;
unsigned int nbr_subdir=0;
@@ -67,20 +67,17 @@ static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const
if(verbose>0)
info_list_search_space(list_search_space, current_search_space, disk->sector_size, 0, verbose);
#ifdef HAVE_NCURSES
- if(interface)
- {
- wmove(stdscr,22,0);
- wattrset(stdscr, A_REVERSE);
- waddstr(stdscr," Stop ");
- wattroff(stdscr, A_REVERSE);
- }
+ wmove(stdscr,22,0);
+ wattrset(stdscr, A_REVERSE);
+ waddstr(stdscr," Stop ");
+ wattroff(stdscr, A_REVERSE);
#endif
disk->pread(disk, buffer_start, READ_SIZE, offset);
while(current_search_space!=list_search_space && nbr_subdir<10)
{
const uint64_t old_offset=offset;
#ifdef HAVE_NCURSES
- if(interface>0 && ((offset&(1024*disk->sector_size-1))==0))
+ if((offset&(1024*disk->sector_size-1))==0)
{
wmove(stdscr,9,0);
wclrtoeol(stdscr);
@@ -177,7 +174,7 @@ static int fat_copy_file(disk_t *disk, const partition_t *partition, const unsig
return 0;
}
-static int fat_unformat_aux(disk_t *disk, partition_t *partition, const int verbose, const char *recup_dir, const int interface, unsigned int *file_nbr, const unsigned int blocksize, const uint64_t start_offset, alloc_data_t *list_search_space, const time_t real_start_time, unsigned int *dir_num)
+static int fat_unformat_aux(struct ph_param *params, const struct ph_options *options, const uint64_t start_offset, alloc_data_t *list_search_space)
{
uint64_t offset;
uint64_t offset_end;
@@ -185,9 +182,13 @@ static int fat_unformat_aux(disk_t *disk, partition_t *partition, const int verb
unsigned char *buffer;
time_t start_time;
time_t previous_time;
+ const unsigned int blocksize=params->blocksize;
const unsigned int read_size=(blocksize>65536?blocksize:65536);
alloc_data_t *current_search_space;
file_recovery_t file_recovery;
+ disk_t *disk=params->disk;
+ const partition_t *partition=params->partition;
+
reset_file_recovery(&file_recovery);
file_recovery.blocksize=blocksize;
buffer_start=(unsigned char *)MALLOC(READ_SIZE);
@@ -203,8 +204,8 @@ static int fat_unformat_aux(disk_t *disk, partition_t *partition, const int verb
offset_end=current_search_space->end;
current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
offset=current_search_space->start;
- if(verbose>0)
- info_list_search_space(list_search_space, current_search_space, disk->sector_size, 0, verbose);
+ if(options->verbose>0)
+ info_list_search_space(list_search_space, current_search_space, disk->sector_size, 0, options->verbose);
disk->pread(disk, buffer, READ_SIZE, offset);
for(;offset < offset_end; offset+=blocksize)
{
@@ -237,9 +238,9 @@ static int fat_unformat_aux(disk_t *disk, partition_t *partition, const int verb
#endif
if(file_end < partition->part_offset + partition->part_size)
{
- if(fat_copy_file(disk, partition, blocksize, start_offset, recup_dir, *dir_num, current_file)==0)
+ if(fat_copy_file(disk, partition, blocksize, start_offset, params->recup_dir, params->dir_num, current_file)==0)
{
- (*file_nbr)++;
+ params->file_nbr++;
del_search_space(list_search_space, file_start, file_end);
}
current_file=current_file->next;
@@ -257,7 +258,7 @@ static int fat_unformat_aux(disk_t *disk, partition_t *partition, const int verb
if(buffer+read_size>buffer_start+READ_SIZE)
{
buffer=buffer_start;
- if(verbose>1)
+ if(options->verbose>1)
{
log_verbose("Reading sector %10llu/%llu\n",
(unsigned long long)((offset-partition->part_offset)/disk->sector_size),
@@ -266,32 +267,28 @@ static int fat_unformat_aux(disk_t *disk, partition_t *partition, const int verb
if(disk->pread(disk, buffer, READ_SIZE, offset) != READ_SIZE)
{
#ifdef HAVE_NCURSES
- if(interface!=0)
- {
- wmove(stdscr,11,0);
- wclrtoeol(stdscr);
- wprintw(stdscr,"Error reading sector %10lu\n",
- (unsigned long)((offset-partition->part_offset)/disk->sector_size));
- }
+ wmove(stdscr,11,0);
+ wclrtoeol(stdscr);
+ wprintw(stdscr,"Error reading sector %10lu\n",
+ (unsigned long)((offset-partition->part_offset)/disk->sector_size));
#endif
}
#ifdef HAVE_NCURSES
- if(interface!=0)
{
time_t current_time;
current_time=time(NULL);
if(current_time>previous_time)
{
- const time_t elapsed_time=current_time-real_start_time;
+ const time_t elapsed_time=current_time - params->real_start_time;
previous_time=current_time;
wmove(stdscr,9,0);
wclrtoeol(stdscr);
log_info("Reading sector %10llu/%llu, %u files found\n",
(unsigned long long)((offset-partition->part_offset)/disk->sector_size),
- (unsigned long long)(partition->part_size/disk->sector_size), *file_nbr);
+ (unsigned long long)(partition->part_size/disk->sector_size), params->file_nbr);
wprintw(stdscr,"Reading sector %10llu/%llu, %u files found\n",
(unsigned long long)((offset-partition->part_offset)/disk->sector_size),
- (unsigned long long)(partition->part_size/disk->sector_size), *file_nbr);
+ (unsigned long long)(partition->part_size/disk->sector_size), params->file_nbr);
wmove(stdscr,10,0);
wclrtoeol(stdscr);
wprintw(stdscr,"Elapsed time %uh%02um%02us",
@@ -320,36 +317,34 @@ static int fat_unformat_aux(disk_t *disk, partition_t *partition, const int verb
return 0;
}
-int fat_unformat(disk_t *disk, partition_t *partition, const struct ph_options *options, const char *recup_dir, const int interface, unsigned int *file_nbr, unsigned int *blocksize, alloc_data_t *list_search_space, const time_t real_start_time, unsigned int *dir_num)
+int fat_unformat(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space)
{
unsigned int sectors_per_cluster=0;
uint64_t start_data=0;
- *blocksize=0;
- if(pfind_sectors_per_cluster(disk, partition, options->verbose, interface, &sectors_per_cluster, &start_data, list_search_space)==0)
+ params->blocksize=0;
+ if(pfind_sectors_per_cluster(params->disk, params->partition, options->verbose, &sectors_per_cluster, &start_data, list_search_space)==0)
{
display_message("Can't find FAT cluster size\n");
return 0;
}
- if(start_data <= partition->part_offset)
+ if(start_data <= params->partition->part_offset)
{
display_message("FAT filesystem was beginning before the actual partition.");
return 0;
}
- start_data *= disk->sector_size;
- del_search_space(list_search_space, partition->part_offset, start_data - 1);
+ start_data *= params->disk->sector_size;
+ del_search_space(list_search_space, params->partition->part_offset, start_data - 1);
{
uint64_t offset=start_data;
- *blocksize=sectors_per_cluster * disk->sector_size;
+ params->blocksize=sectors_per_cluster * params->disk->sector_size;
#ifdef HAVE_NCURSES
if(options->expert>0)
- *blocksize=menu_choose_blocksize(*blocksize, disk->sector_size, &offset);
+ params->blocksize=menu_choose_blocksize(params->blocksize, params->disk->sector_size, &offset);
#endif
- update_blocksize(*blocksize,list_search_space, offset);
+ update_blocksize(params->blocksize, list_search_space, offset);
}
/* start_data is relative to the disk */
- fat_unformat_aux(disk, partition, options->verbose, recup_dir, interface, file_nbr,
- *blocksize, start_data, list_search_space,
- real_start_time, dir_num);
+ fat_unformat_aux(params, options, start_data, list_search_space);
return 0;
}
diff --git a/src/fat_unformat.h b/src/fat_unformat.h
index 2757f08..1868863 100644
--- a/src/fat_unformat.h
+++ b/src/fat_unformat.h
@@ -25,7 +25,7 @@
extern "C" {
#endif
-int fat_unformat(disk_t *disk, partition_t *partition, const struct ph_options *options, const char *recup_dir, const int interface, unsigned int *file_nbr, unsigned int *blocksize, alloc_data_t *list_search_space, const time_t real_start_time, unsigned int *dir_num);
+int fat_unformat(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space);
#ifdef __cplusplus
} /* closing brace for extern "c" */
diff --git a/src/pdisksel.c b/src/pdisksel.c
index ffa6377..c6bedd1 100644
--- a/src/pdisksel.c
+++ b/src/pdisksel.c
@@ -61,13 +61,13 @@
#define INTER_NOTE_Y (LINES-4)
#endif
-static int photorec_disk_selection_cli(struct ph_options *options, const char *recup_dir, const list_disk_t *list_disk, file_enable_t *file_enable, alloc_data_t *list_search_space, const char *cmd_device, char **current_cmd)
+static int photorec_disk_selection_cli(struct ph_param *params, struct ph_options *options, const list_disk_t *list_disk, alloc_data_t *list_search_space)
{
const list_disk_t *element_disk;
disk_t *disk=NULL;
for(element_disk=list_disk;element_disk!=NULL;element_disk=element_disk->next)
{
- if(strcmp(element_disk->disk->device,cmd_device)==0)
+ if(strcmp(element_disk->disk->device, params->cmd_device)==0)
disk=element_disk->disk;
}
if(disk==NULL)
@@ -91,15 +91,15 @@ static int photorec_disk_selection_cli(struct ph_options *options, const char *r
}
}
autodetect_arch(disk);
- if(interface_partition_type(disk, options->verbose, current_cmd)==0)
- menu_photorec(disk, options, recup_dir, file_enable, current_cmd, list_search_space);
+ params->disk=disk;
+ if(interface_partition_type(disk, options->verbose, &params->cmd_run)==0)
+ menu_photorec(params, options, list_search_space);
return 0;
}
#ifdef HAVE_NCURSES
-static int photorec_disk_selection_ncurses(struct ph_options *options, const char *recup_dir, const list_disk_t *list_disk, file_enable_t *file_enable, alloc_data_t *list_search_space)
+static int photorec_disk_selection_ncurses(struct ph_param *params, struct ph_options *options, const list_disk_t *list_disk, alloc_data_t *list_search_space)
{
- char * current_cmd=NULL;
int command;
int real_key;
unsigned int menu=0;
@@ -267,10 +267,11 @@ static int photorec_disk_selection_ncurses(struct ph_options *options, const cha
disk_t *disk=current_disk->disk;
const int hpa_dco=is_hpa_or_dco(disk);
autodetect_arch(disk);
+ params->disk=disk;
if((hpa_dco==0 || interface_check_hidden_ncurses(disk, hpa_dco)==0) &&
(options->expert == 0 ||
- interface_partition_type(disk, options->verbose, &current_cmd)==0))
- menu_photorec(disk, options, recup_dir, file_enable, &current_cmd, list_search_space);
+ interface_partition_type(disk, options->verbose, &params->cmd_run)==0))
+ menu_photorec(params, options, list_search_space);
}
break;
case 's':
@@ -288,13 +289,13 @@ static int photorec_disk_selection_ncurses(struct ph_options *options, const cha
}
#endif
-int do_curses_photorec(struct ph_options *options, const char *recup_dir, const list_disk_t *list_disk, file_enable_t *file_enable, char *cmd_device, char **current_cmd)
+int do_curses_photorec(struct ph_param *params, struct ph_options *options, const list_disk_t *list_disk)
{
static alloc_data_t list_search_space={
.list = TD_LIST_HEAD_INIT(list_search_space.list)
};
#ifdef HAVE_NCURSES
- if(cmd_device==NULL)
+ if(params->cmd_device==NULL)
{
char *saved_device=NULL;
char *saved_cmd=NULL;
@@ -302,8 +303,8 @@ int do_curses_photorec(struct ph_options *options, const char *recup_dir, const
if(saved_device!=NULL && saved_cmd!=NULL && !td_list_empty(&list_search_space.list) && ask_confirmation("Continue previous session ? (Y/N)")!=0)
{
/* yes */
- *current_cmd=saved_cmd;
- cmd_device=saved_device;
+ params->cmd_run=saved_cmd;
+ params->cmd_device=saved_device;
}
else
{
@@ -313,10 +314,10 @@ int do_curses_photorec(struct ph_options *options, const char *recup_dir, const
}
}
#endif
- if(cmd_device!=NULL && *current_cmd!=NULL)
- return photorec_disk_selection_cli(options, recup_dir, list_disk, file_enable, &list_search_space, cmd_device, current_cmd);
+ if(params->cmd_device!=NULL && params->cmd_run!=NULL)
+ return photorec_disk_selection_cli(params, options, list_disk, &list_search_space);
#ifdef HAVE_NCURSES
- return photorec_disk_selection_ncurses(options, recup_dir, list_disk, file_enable, &list_search_space);
+ return photorec_disk_selection_ncurses(params, options, list_disk, &list_search_space);
#else
return 0;
#endif
diff --git a/src/pdisksel.h b/src/pdisksel.h
index 00c0eea..9d34603 100644
--- a/src/pdisksel.h
+++ b/src/pdisksel.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-int do_curses_photorec(struct ph_options *options, const char *recup_dir, const list_disk_t *list_disk, file_enable_t *file_enable, char *cmd_device, char**cmd_run);
+int do_curses_photorec(struct ph_param *params, struct ph_options *options, const list_disk_t *list_disk);
#ifdef __cplusplus
} /* closing brace for extern "C" */
diff --git a/src/phbf.c b/src/phbf.c
index 45be7e6..e055b8b 100644
--- a/src/phbf.c
+++ b/src/phbf.c
@@ -74,8 +74,8 @@
extern file_check_list_t file_check_list;
extern uint64_t free_list_allocation_end;
-static int photorec_bf_aux(disk_t *disk_car, partition_t *partition, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, file_recovery_t *file_recovery, const unsigned int blocksize, alloc_data_t *list_search_space, alloc_data_t *current_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const int phase);
-static int photorec_bf_frag(disk_t *disk_car, partition_t *partition, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, file_recovery_t *file_recovery, const unsigned int blocksize, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const int phase, alloc_data_t **current_search_space, uint64_t *offset, unsigned char *buffer, unsigned char *block_buffer, const unsigned int frag);
+static int photorec_bf_aux(struct ph_param *params, file_recovery_t *file_recovery, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const int phase);
+static int photorec_bf_frag(struct ph_param *params, file_recovery_t *file_recovery, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const int phase, alloc_data_t **current_search_space, uint64_t *offset, unsigned char *buffer, unsigned char *block_buffer, const unsigned int frag);
#ifdef DEBUG_BF
static void list_space_used(const file_recovery_t *file_recovery, const unsigned int sector_size)
@@ -144,21 +144,22 @@ static struct td_list_head *next_file(struct td_list_head *search_walker, alloc_
return search_walker;
}
-int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, const unsigned int blocksize, alloc_data_t *list_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const unsigned int pass)
+int photorec_bf(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space)
{
struct td_list_head *search_walker = NULL;
struct td_list_head *p= NULL;
unsigned char *buffer_start;
+ const unsigned int blocksize=params->blocksize;
const unsigned int read_size=(blocksize>65536?blocksize:65536);
unsigned int buffer_size;
int ind_stop=0;
- int pass2=pass;
+ int pass2=params->pass;
int phase;
buffer_size=blocksize+READ_SIZE;
buffer_start=(unsigned char *)MALLOC(buffer_size);
for(phase=0; phase<2; phase++)
{
- const unsigned int file_nbr_phase_old=*file_nbr;
+ const unsigned int file_nbr_phase_old=params->file_nbr;
for(search_walker=list_search_space->list.prev, p=search_walker->prev;
search_walker!=&list_search_space->list && ind_stop==0;
p=search_walker->prev)
@@ -175,10 +176,10 @@ int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, con
current_search_space=td_list_entry(search_walker, alloc_data_t, list);
offset=current_search_space->start;
buffer_olddata=buffer_start;
- buffer=buffer_olddata+blocksize;
+ buffer=buffer_olddata + blocksize;
memset(buffer_olddata, 0, blocksize);
- disk_car->pread(disk_car, buffer, READ_SIZE, offset);
- info_list_search_space(list_search_space, current_search_space, disk_car->sector_size, 0, verbose);
+ params->disk->pread(params->disk, buffer, READ_SIZE, offset);
+ info_list_search_space(list_search_space, current_search_space, params->disk->sector_size, 0, options->verbose);
#ifdef DEBUG_BF
#endif
log_flush();
@@ -213,12 +214,12 @@ int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, con
if(file_recovery_new.file_stat!=NULL)
{
file_recovery_new.location.start=offset;
- if(verbose>0)
+ if(options->verbose>0)
{
log_info("%s header found at sector %lu\n",
((file_recovery_new.extension!=NULL && file_recovery_new.extension[0]!='\0')?
file_recovery_new.extension:file_recovery_new.file_stat->file_hint->description),
- (unsigned long)((offset-partition->part_offset)/disk_car->sector_size));
+ (unsigned long)((offset - params->partition->part_offset) / params->disk->sector_size));
}
if(file_recovery.file_stat==NULL)
{ /* Header found => file found */
@@ -226,7 +227,7 @@ int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, con
}
else if(file_recovery_new.file_stat->file_hint!=NULL)
{
- if(verbose>0)
+ if(options->verbose>0)
log_verbose("New file found => stop the recovery of current file\n");
need_to_check_file=1;
}
@@ -236,7 +237,7 @@ int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, con
}
if(file_recovery.file_stat!=NULL && file_recovery.handle==NULL)
{ /* Create new file */
- set_filename(&file_recovery, recup_dir, *dir_num, disk_car, partition, 0);
+ set_filename(&file_recovery, params);
if(file_recovery.file_stat->file_hint->recover==1)
{
if(!(file_recovery.handle=fopen(file_recovery.filename,"w+b")))
@@ -289,13 +290,13 @@ int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, con
memcpy(buffer_start, buffer_olddata, blocksize);
buffer_olddata=buffer_start;
buffer=buffer_olddata+blocksize;
- if(verbose>1)
+ if(options->verbose>1)
{
log_verbose("Reading sector %10llu/%llu\n",
- (unsigned long long)((offset-partition->part_offset)/disk_car->sector_size),
- (unsigned long long)((partition->part_size-1)/disk_car->sector_size));
+ (unsigned long long)((offset - params->partition->part_offset) / params->disk->sector_size),
+ (unsigned long long)((params->partition->part_size-1) / params->disk->sector_size));
}
- disk_car->pread(disk_car, buffer, READ_SIZE, offset);
+ params->disk->pread(params->disk, buffer, READ_SIZE, offset);
}
}
} while(need_to_check_file==0);
@@ -303,7 +304,7 @@ int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, con
{
uint64_t offset_next_file=0;
struct td_list_head *tmp_walker;
- const unsigned int file_nbr_old=*file_nbr;
+ const unsigned int file_nbr_old=params->file_nbr;
/* find the offset of the next file */
for(tmp_walker=search_walker;
tmp_walker!=&list_search_space->list && offset_next_file==0;
@@ -316,12 +317,12 @@ int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, con
}
file_recovery.flags=1;
- if(file_finish(&file_recovery, recup_dir, 2, file_nbr, blocksize, list_search_space, &current_search_space, &offset, dir_num, status, disk_car)<0)
+ if(file_finish(&file_recovery, params, list_search_space, &current_search_space, &offset)<0)
{ /* BF */
current_search_space=td_list_entry(search_walker, alloc_data_t, list);
- ind_stop=photorec_bf_aux(disk_car, partition, recup_dir, interface, file_stats, file_nbr, &file_recovery, blocksize, list_search_space, current_search_space, real_start_time, dir_num, status, phase);
+ ind_stop=photorec_bf_aux(params, &file_recovery, list_search_space, current_search_space, phase);
pass2++;
- if(file_nbr_old < *file_nbr && free_list_allocation_end > offset_next_file)
+ if(file_nbr_old < params->file_nbr && free_list_allocation_end > offset_next_file)
go_backward=0;
#ifdef DEBUG_BF
log_info("file_nbr_old %u, file_nbr=%u\n", file_nbr_old, *file_nbr);
@@ -340,19 +341,20 @@ int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, con
search_walker=next_file(search_walker, list_search_space);
}
}
- log_info("phase=%d +%u\n", phase, *file_nbr - file_nbr_phase_old);
+ log_info("phase=%d +%u\n", phase, params->file_nbr - file_nbr_phase_old);
}
free(buffer_start);
#ifdef HAVE_NCURSES
- photorec_info(stdscr, file_stats);
+ photorec_info(stdscr, params->file_stats);
#endif
return ind_stop;
}
enum { BF_FILE_FOUND=0, BF_USER_STOP=1, BF_ERR_STOP=2, BF_FRAG_FOUND=3, BF_EOF=4, BF_NO_FILE=5, BF_TOO_FAR=6};
-static int photorec_bf_pad(disk_t *disk_car, const char *recup_dir, unsigned int *file_nbr, file_recovery_t *file_recovery, const unsigned int blocksize, alloc_data_t *list_search_space, unsigned int *dir_num, const photorec_status_t status, const int phase, const uint64_t file_offset, alloc_data_t **current_search_space, uint64_t *offset, unsigned char *buffer, unsigned char *block_buffer)
+static int photorec_bf_pad(struct ph_param *params, file_recovery_t *file_recovery, alloc_data_t *list_search_space, const int phase, const uint64_t file_offset, alloc_data_t **current_search_space, uint64_t *offset, unsigned char *buffer, unsigned char *block_buffer)
{
+ const unsigned int blocksize=params->blocksize;
{ /* Add remaining data blocs */
unsigned int nbr;
uint64_t offset_error_tmp;
@@ -377,7 +379,7 @@ static int photorec_bf_pad(disk_t *disk_car, const char *recup_dir, unsigned int
(*current_search_space)->file_stat==NULL ||
(*current_search_space)->file_stat->file_hint==NULL)
{
- disk_car->pread(disk_car, block_buffer, blocksize, *offset);
+ params->disk->pread(params->disk, block_buffer, blocksize, *offset);
if(file_recovery->data_check(buffer, 2*blocksize, file_recovery)!=1)
{
stop=1;
@@ -408,7 +410,7 @@ static int photorec_bf_pad(disk_t *disk_car, const char *recup_dir, unsigned int
(*current_search_space)->file_stat==NULL ||
(*current_search_space)->file_stat->file_hint==NULL)
{
- disk_car->pread(disk_car, block_buffer, blocksize, *offset);
+ params->disk->pread(params->disk, block_buffer, blocksize, *offset);
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
@@ -454,12 +456,12 @@ static int photorec_bf_pad(disk_t *disk_car, const char *recup_dir, unsigned int
#ifdef DEBUG_BF
log_info("photorec_bf_aux, call file_finish\n");
#endif
- file_finish(file_recovery, recup_dir, 2, file_nbr, blocksize, list_search_space, current_search_space, offset, dir_num, status, disk_car);
+ file_finish(file_recovery, params, list_search_space, current_search_space, offset);
return BF_FILE_FOUND;
}
/* FIXME +4096 => +blocksize*/
/* 21/11/2009: 2 blocksize */
- else if(file_recovery->offset_error/blocksize*blocksize >= (file_offset / blocksize * blocksize + 2 * blocksize))
+ else if(file_recovery->offset_error / blocksize * blocksize >= (file_offset / blocksize * blocksize + 2 * blocksize))
{ /* Try to recover file composed of multiple fragments */
#ifdef DEBUG_BF
log_info("%s multiple fragment %llu -> %llu, blocksize %u\n",
@@ -474,8 +476,9 @@ static int photorec_bf_pad(disk_t *disk_car, const char *recup_dir, unsigned int
return BF_NO_FILE;
}
-static int photorec_bf_frag_fast(disk_t *disk_car, partition_t *partition, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, file_recovery_t *file_recovery, const unsigned int blocksize, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const int phase, alloc_data_t **current_search_space, uint64_t *offset, unsigned char *buffer, unsigned char *block_buffer, const unsigned int frag)
+static int photorec_bf_frag_fast(struct ph_param *params, file_recovery_t *file_recovery, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const int phase, alloc_data_t **current_search_space, uint64_t *offset, unsigned char *buffer, unsigned char *block_buffer, const unsigned int frag)
{
+ const unsigned int blocksize=params->blocksize;
const uint64_t original_offset_error=file_recovery->offset_error;
const uint64_t original_offset_ok=file_recovery->offset_ok;
const int blocs_to_skip=file_recovery->extra / blocksize;
@@ -519,7 +522,7 @@ static int photorec_bf_frag_fast(disk_t *disk_car, partition_t *partition, const
/* FIXME: Handle ext2/ext3 */
if(file_recovery->data_check!=NULL)
{
- disk_car->pread(disk_car, block_buffer, blocksize, *offset);
+ params->disk->pread(params->disk, block_buffer, blocksize, *offset);
file_recovery->data_check(buffer, 2*blocksize, file_recovery);
memcpy(buffer, block_buffer, blocksize);
}
@@ -534,7 +537,7 @@ static int photorec_bf_frag_fast(disk_t *disk_car, partition_t *partition, const
}
for(k=original_offset_ok/blocksize+1; k<original_offset_error/blocksize; k++)
{
- disk_car->pread(disk_car, block_buffer, blocksize, *offset);
+ params->disk->pread(params->disk, block_buffer, blocksize, *offset);
if(file_recovery->data_check(buffer, 2*blocksize, file_recovery)!=1)
{
/* TODO handle this problem */
@@ -556,12 +559,12 @@ static int photorec_bf_frag_fast(disk_t *disk_car, partition_t *partition, const
{
get_next_sector(list_search_space, current_search_space, offset, blocksize);
}
- res=photorec_bf_pad(disk_car, recup_dir, file_nbr, file_recovery, blocksize, list_search_space, dir_num, status, phase, file_recovery->offset_error, current_search_space, offset, buffer, block_buffer);
+ res=photorec_bf_pad(params, file_recovery, list_search_space, phase, file_recovery->offset_error, current_search_space, offset, buffer, block_buffer);
if(res==BF_FRAG_FOUND)
{
if(frag>5)
return BF_NO_FILE;
- res=photorec_bf_frag(disk_car, partition, recup_dir, interface, file_stats, file_nbr, file_recovery, blocksize, list_search_space, start_search_space, real_start_time, dir_num, status, phase, current_search_space, offset, buffer, block_buffer, frag+1);
+ res=photorec_bf_frag(params, file_recovery, list_search_space, start_search_space, phase, current_search_space, offset, buffer, block_buffer, frag+1);
}
if(res==BF_FILE_FOUND || res==BF_USER_STOP || res==BF_ERR_STOP)
return res;
@@ -571,19 +574,20 @@ static int photorec_bf_frag_fast(disk_t *disk_car, partition_t *partition, const
return BF_NO_FILE;
}
-static int photorec_bf_frag(disk_t *disk_car, partition_t *partition, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, file_recovery_t *file_recovery, const unsigned int blocksize, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const int phase, alloc_data_t **current_search_space, uint64_t *offset, unsigned char *buffer, unsigned char *block_buffer, const unsigned int frag)
+static int photorec_bf_frag(struct ph_param *params, file_recovery_t *file_recovery, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const int phase, alloc_data_t **current_search_space, uint64_t *offset, unsigned char *buffer, unsigned char *block_buffer, const unsigned int frag)
{
uint64_t file_offset;
const uint64_t original_offset_error=file_recovery->offset_error;
+ const unsigned int blocksize=params->blocksize;
int testbf=0;
#if 1
if(file_recovery->extra > 0 &&
file_recovery->offset_error / blocksize > file_recovery->offset_ok / blocksize &&
file_recovery->offset_ok > 0)
{
- int res=photorec_bf_frag_fast(disk_car, partition, recup_dir, interface, file_stats, file_nbr, file_recovery, blocksize, list_search_space, start_search_space, real_start_time, dir_num, status, phase, current_search_space, offset, buffer, block_buffer, frag);
+ int res=photorec_bf_frag_fast(params, file_recovery, list_search_space, start_search_space, phase, current_search_space, offset, buffer, block_buffer, frag);
// if(res==BF_TOO_FAR)
-// res=photorec_bf_frag(disk_car, partition, recup_dir, interface, file_stats, file_nbr, file_recovery, blocksize, list_search_space, start_search_space, real_start_time, dir_num, status, phase, current_search_space, offset, buffer, block_buffer, frag);
+// res=photorec_bf_frag(params, file_recovery, list_search_space, start_search_space, phase, current_search_space, offset, buffer, block_buffer, frag);
if(res!=BF_NO_FILE)
return res;
}
@@ -617,7 +621,7 @@ static int photorec_bf_frag(disk_t *disk_car, partition_t *partition, const char
file_recovery->file_size < file_offset;
file_recovery->file_size += blocksize)
{
- disk_car->pread(disk_car, block_buffer, blocksize, *offset);
+ params->disk->pread(params->disk, block_buffer, blocksize, *offset);
/* FIXME: Handle ext2/ext3 */
file_recovery->data_check(buffer, 2*blocksize, file_recovery);
memcpy(buffer, block_buffer, blocksize);
@@ -678,7 +682,6 @@ static int photorec_bf_frag(disk_t *disk_car, partition_t *partition, const char
#endif
file_recovery->offset_error=0;
list_truncate(&file_recovery->location,file_offset);
- if( interface != 0)
{
static time_t previous_time=0;
time_t current_time;
@@ -688,15 +691,13 @@ static int photorec_bf_frag(disk_t *disk_car, partition_t *partition, const char
int ind_stop=0;
previous_time=current_time;
#ifdef HAVE_NCURSES
- ind_stop=photorec_progressbar(stdscr, testbf, status,
- file_recovery->location.start, disk_car, partition, *file_nbr,
- (current_time > real_start_time ? current_time - real_start_time: 0),
- file_stats);
+ ind_stop=photorec_progressbar(stdscr, testbf, params,
+ file_recovery->location.start, current_time);
#endif
if(ind_stop!=0)
{
file_recovery->flags=0;
- file_finish(file_recovery, recup_dir, 2, file_nbr, blocksize, list_search_space, current_search_space, offset, dir_num, status, disk_car);
+ file_finish(file_recovery, params, list_search_space, current_search_space, offset);
log_info("photorec_bf_aux, user choose to stop\n");
return BF_USER_STOP;
}
@@ -726,7 +727,7 @@ static int photorec_bf_frag(disk_t *disk_car, partition_t *partition, const char
}
}
- switch(photorec_bf_pad(disk_car, recup_dir, file_nbr, file_recovery, blocksize, list_search_space, dir_num, status, phase, file_offset, current_search_space, offset, buffer, block_buffer))
+ switch(photorec_bf_pad(params, file_recovery, list_search_space, phase, file_offset, current_search_space, offset, buffer, block_buffer))
{
case BF_FILE_FOUND:
return BF_FILE_FOUND;
@@ -735,7 +736,7 @@ static int photorec_bf_frag(disk_t *disk_car, partition_t *partition, const char
case BF_FRAG_FOUND:
if(frag>5)
return BF_NO_FILE;
- switch(photorec_bf_frag(disk_car, partition, recup_dir, interface, file_stats, file_nbr, file_recovery, blocksize, list_search_space, start_search_space, real_start_time, dir_num, status, phase, current_search_space, offset, buffer, block_buffer, frag+1))
+ switch(photorec_bf_frag(params, file_recovery, list_search_space, start_search_space, phase, current_search_space, offset, buffer, block_buffer, frag+1))
{
case BF_FILE_FOUND:
return BF_FILE_FOUND;
@@ -772,13 +773,14 @@ static int photorec_bf_frag(disk_t *disk_car, partition_t *partition, const char
return BF_NO_FILE;
}
-static int photorec_bf_aux(disk_t *disk_car, partition_t *partition, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, file_recovery_t *file_recovery, const unsigned int blocksize, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const int phase)
+static int photorec_bf_aux(struct ph_param *params, file_recovery_t *file_recovery, alloc_data_t *list_search_space, alloc_data_t *start_search_space, const int phase)
{
uint64_t offset;
unsigned char *buffer;
unsigned char *block_buffer;
int ind_stop;
alloc_data_t *current_search_space;
+ const unsigned int blocksize=params->blocksize;
//Init. of the brute force
file_recovery->handle=fopen(file_recovery->filename, "w+b");
if(file_recovery->handle==NULL)
@@ -805,7 +807,7 @@ static int photorec_bf_aux(disk_t *disk_car, partition_t *partition, const char
file_recovery->file_size + blocksize -1 < file_recovery->offset_error;
file_recovery->file_size += blocksize)
{
- disk_car->pread(disk_car, block_buffer, blocksize, offset);
+ params->disk->pread(params->disk, block_buffer, blocksize, offset);
/* FIXME: Handle ext2/ext3 */
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
@@ -825,13 +827,13 @@ static int photorec_bf_aux(disk_t *disk_car, partition_t *partition, const char
list_space_used(file_recovery, 512);
log_trace("\n");
#endif
- ind_stop=photorec_bf_frag(disk_car, partition, recup_dir, interface, file_stats, file_nbr, file_recovery, blocksize, list_search_space, start_search_space, real_start_time, dir_num, status, phase, &current_search_space, &offset, buffer, block_buffer, 0);
+ ind_stop=photorec_bf_frag(params, file_recovery, list_search_space, start_search_space, phase, &current_search_space, &offset, buffer, block_buffer, 0);
/* Cleanup */
- file_finish(file_recovery,recup_dir,2, file_nbr,blocksize,list_search_space,&current_search_space, &offset, dir_num,status,disk_car);
+ file_finish(file_recovery, params, list_search_space, &current_search_space, &offset);
free(buffer);
if(ind_stop==BF_TOO_FAR)
{
-// return photorec_bf_aux(disk_car, partition, recup_dir, interface, file_stats, file_nbr, file_recovery, blocksize, list_search_space, start_search_space, real_start_time, dir_num, status, phase);
+// return photorec_bf_aux(params, file_recovery, list_search_space, start_search_space, phase);
return BF_FILE_FOUND;
}
if(ind_stop==BF_NO_FILE)
diff --git a/src/phbf.h b/src/phbf.h
index 6cc38b5..d7018e9 100644
--- a/src/phbf.h
+++ b/src/phbf.h
@@ -22,7 +22,7 @@
#ifdef __cplusplus
extern "C" {
#endif
-int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbose, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, const unsigned int blocksize, alloc_data_t *list_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const unsigned int pass);
+int photorec_bf(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/phbs.c b/src/phbs.c
index f6af9fa..08fe253 100644
--- a/src/phbs.c
+++ b/src/phbs.c
@@ -87,7 +87,7 @@ static inline void file_recovery_cpy(file_recovery_t *dst, file_recovery_t *src)
dst->location.list.next=&dst->location.list;
}
-int photorec_find_blocksize(disk_t *disk_car, partition_t *partition, const int verbose, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, unsigned int *blocksize, alloc_data_t *list_search_space, const time_t real_start_time)
+int photorec_find_blocksize(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space)
{
uint64_t offset=0;
unsigned char *buffer_start;
@@ -96,24 +96,25 @@ int photorec_find_blocksize(disk_t *disk_car, partition_t *partition, const int
time_t start_time;
time_t previous_time;
unsigned int buffer_size;
- const unsigned int read_size=((*blocksize)>65536?(*blocksize):65536);
+ const unsigned int blocksize=params->blocksize;
+ const unsigned int read_size=(blocksize>65536?blocksize:65536);
alloc_data_t *current_search_space;
file_recovery_t file_recovery;
reset_file_recovery(&file_recovery);
- file_recovery.blocksize=*blocksize;
- buffer_size=(*blocksize)+READ_SIZE;
+ file_recovery.blocksize=blocksize;
+ buffer_size=blocksize + READ_SIZE;
buffer_start=(unsigned char *)MALLOC(buffer_size);
buffer_olddata=buffer_start;
- buffer=buffer_olddata+(*blocksize);
+ buffer=buffer_olddata + blocksize;
start_time=time(NULL);
previous_time=start_time;
- memset(buffer_olddata,0,(*blocksize));
+ memset(buffer_olddata, 0, blocksize);
current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
if(current_search_space!=list_search_space)
offset=current_search_space->start;
- if(verbose>0)
- info_list_search_space(list_search_space, current_search_space, disk_car->sector_size, 0, verbose);
- disk_car->pread(disk_car, buffer, READ_SIZE, offset);
+ if(options->verbose>0)
+ info_list_search_space(list_search_space, current_search_space, params->disk->sector_size, 0, options->verbose);
+ params->disk->pread(params->disk, buffer, READ_SIZE, offset);
while(current_search_space!=list_search_space)
{
uint64_t old_offset=offset;
@@ -153,7 +154,7 @@ int photorec_find_blocksize(disk_t *disk_car, partition_t *partition, const int
{
/* A new file begins, backup file offset */
current_search_space=file_found(current_search_space, offset, file_recovery_new.file_stat);
- (*file_nbr)++;
+ params->file_nbr++;
file_recovery_cpy(&file_recovery, &file_recovery_new);
}
}
@@ -163,9 +164,9 @@ int photorec_find_blocksize(disk_t *disk_car, partition_t *partition, const int
{
int res=1;
if(file_recovery.data_check!=NULL)
- res=file_recovery.data_check(buffer_olddata,2*(*blocksize),&file_recovery);
- file_recovery.file_size+=*blocksize;
- file_recovery.file_size_on_disk+=*blocksize;
+ res=file_recovery.data_check(buffer_olddata, 2*blocksize, &file_recovery);
+ file_recovery.file_size+=blocksize;
+ file_recovery.file_size_on_disk+=blocksize;
if(res==2)
{
/* EOF found */
@@ -178,52 +179,48 @@ int photorec_find_blocksize(disk_t *disk_car, partition_t *partition, const int
reset_file_recovery(&file_recovery);
}
- if(*file_nbr>=10)
+ if(params->file_nbr >= 10)
{
current_search_space=list_search_space;
}
else
- get_next_sector(list_search_space, &current_search_space,&offset,*blocksize);
+ get_next_sector(list_search_space, &current_search_space, &offset, blocksize);
if(current_search_space==list_search_space)
{
/* End of disk found => EOF */
reset_file_recovery(&file_recovery);
}
- buffer_olddata+=*blocksize;
- buffer+=*blocksize;
- if( old_offset+*blocksize!=offset ||
+ buffer_olddata+=blocksize;
+ buffer+=blocksize;
+ if( old_offset+blocksize!=offset ||
buffer+read_size>buffer_start+buffer_size)
{
- memcpy(buffer_start,buffer_olddata,*blocksize);
+ memcpy(buffer_start, buffer_olddata, blocksize);
buffer_olddata=buffer_start;
- buffer=buffer_olddata+*blocksize;
- if(verbose>1)
+ buffer=buffer_olddata+blocksize;
+ if(options->verbose>1)
{
log_verbose("Reading sector %10llu/%llu\n",
- (unsigned long long)((offset-partition->part_offset)/disk_car->sector_size),
- (unsigned long long)((partition->part_size-1)/disk_car->sector_size));
+ (unsigned long long)((offset - params->partition->part_offset) / params->disk->sector_size),
+ (unsigned long long)((params->partition->part_size-1) / params->disk->sector_size));
}
- if(disk_car->pread(disk_car, buffer, READ_SIZE, offset) != READ_SIZE)
+ if(params->disk->pread(params->disk, buffer, READ_SIZE, offset) != READ_SIZE)
{
#ifdef HAVE_NCURSES
- if(interface!=0)
- {
- wmove(stdscr,11,0);
- wclrtoeol(stdscr);
- wprintw(stdscr,"Error reading sector %10lu\n",
- (unsigned long)((offset-partition->part_offset)/disk_car->sector_size));
- }
+ wmove(stdscr,11,0);
+ wclrtoeol(stdscr);
+ wprintw(stdscr,"Error reading sector %10lu\n",
+ (unsigned long)((offset - params->partition->part_offset) / params->disk->sector_size));
#endif
}
#ifdef HAVE_NCURSES
- if(interface!=0)
{
time_t current_time;
current_time=time(NULL);
if(current_time>previous_time)
{
previous_time=current_time;
- if(photorec_progressbar(stdscr, 0, STATUS_FIND_OFFSET, offset, disk_car, partition, *file_nbr, current_time-real_start_time, file_stats))
+ if(photorec_progressbar(stdscr, 0, params, offset, current_time))
{
log_info("PhotoRec has been stopped\n");
current_search_space=list_search_space;
diff --git a/src/phbs.h b/src/phbs.h
index 43c9518..08c75ce 100644
--- a/src/phbs.h
+++ b/src/phbs.h
@@ -22,7 +22,7 @@
#ifdef __cplusplus
extern "C" {
#endif
-int photorec_find_blocksize(disk_t *disk_car, partition_t *partition, const int verbose, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, unsigned int *blocksize, alloc_data_t *list_search_space, const time_t real_start_time);
+int photorec_find_blocksize(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/phmain.c b/src/phmain.c
index a735ed4..ac9213c 100644
--- a/src/phmain.c
+++ b/src/phmain.c
@@ -106,11 +106,8 @@ int main( int argc, char **argv )
int create_log=TD_LOG_NONE;
int run_setlocale=1;
int testdisk_mode=TESTDISK_O_RDONLY|TESTDISK_O_READAHEAD_32K;
- const char *recup_dir=NULL;
list_disk_t *list_disk=NULL;
list_disk_t *element_disk;
- char *cmd_device=NULL;
- char *cmd_run=NULL;
const char *logfile="photorec.log";
const arch_fnct_t *arch=&arch_none;
FILE *log_handle=NULL;
@@ -121,8 +118,13 @@ int main( int argc, char **argv )
.mode_ext2=0,
.expert=0,
.lowmem=0,
- .verbose=0
+ .verbose=0,
+ .list_file_format=list_file_enable
};
+ struct ph_param params;
+ params.recup_dir=NULL;
+ params.cmd_device=NULL;
+ params.cmd_run=NULL;
/* random (weak is ok) is need fot GPT */
srand(time(NULL));
#ifdef HAVE_SIGACTION
@@ -169,13 +171,12 @@ int main( int argc, char **argv )
int len=strlen(argv[i+1]);
if(argv[i+1][len-1]=='\\' || argv[i+1][len-1]=='/')
{
- char *new_recup_dir=(char *)MALLOC(len+strlen(DEFAULT_RECUP_DIR)+1);
- strcpy(new_recup_dir,argv[i+1]);
- strcat(new_recup_dir,DEFAULT_RECUP_DIR);
- recup_dir=new_recup_dir; /* small memory leak */
+ params.recup_dir=(char *)MALLOC(len + strlen(DEFAULT_RECUP_DIR) + 1);
+ strcpy(params.recup_dir,argv[i+1]);
+ strcat(params.recup_dir,DEFAULT_RECUP_DIR);
}
else
- recup_dir=argv[i+1];
+ params.recup_dir=strdup(argv[i+1]);
i++;
}
else if((strcmp(argv[i],"/all")==0) || (strcmp(argv[i],"-all")==0))
@@ -198,13 +199,13 @@ int main( int argc, char **argv )
else
{
disk_t *disk_car;
- cmd_device=argv[++i];
- cmd_run=argv[++i];
+ params.cmd_device=argv[++i];
+ params.cmd_run=argv[++i];
/* There is no log currently */
- disk_car=file_test_availability(cmd_device, options.verbose, arch, testdisk_mode);
+ disk_car=file_test_availability(params.cmd_device, options.verbose, arch, testdisk_mode);
if(disk_car==NULL)
{
- printf("\nUnable to open file or device %s\n",cmd_device);
+ printf("\nUnable to open file or device %s\n", params.cmd_device);
help=1;
}
else
@@ -232,6 +233,7 @@ int main( int argc, char **argv )
printf("ext2fs lib: %s, ntfs lib: %s, ewf lib: %s, libjpeg: %s\n",
td_ext2fs_version(), td_ntfs_version(), td_ewf_version(), td_jpeg_version());
printf("OS: %s\n" , get_os());
+ free(params.recup_dir);
return 0;
}
if(help!=0)
@@ -246,6 +248,7 @@ int main( int argc, char **argv )
"in recup_dir directory.\n" \
"\n" \
"If you have problems with PhotoRec or bug reports, please contact me.\n");
+ free(params.recup_dir);
return 0;
}
xml_set_command_line(argc, argv);
@@ -269,7 +272,10 @@ int main( int argc, char **argv )
#ifdef HAVE_NCURSES
/* ncurses need locale for correct unicode support */
if(start_ncurses("PhotoRec", argv[0]))
+ {
+ free(params.recup_dir);
return 1;
+ }
{
const char*filename=logfile;
while(create_log!=TD_LOG_NONE && log_handle==NULL)
@@ -340,9 +346,9 @@ int main( int argc, char **argv )
log_info("\n");
}
log_info("\n");
- reset_list_file_enable(list_file_enable);
- file_options_load(list_file_enable);
- use_sudo=do_curses_photorec(&options, recup_dir, list_disk, list_file_enable, cmd_device, &cmd_run);
+ reset_list_file_enable(options.list_file_format);
+ file_options_load(options.list_file_format);
+ use_sudo=do_curses_photorec(&params, &options, list_disk);
#ifdef HAVE_NCURSES
end_ncurses();
#endif
@@ -352,9 +358,9 @@ int main( int argc, char **argv )
{
printf("PhotoRec: Log file corrupted!\n");
}
- else if(cmd_run!=NULL && cmd_run[0]!='\0')
+ else if(params.cmd_run!=NULL && params.cmd_run[0]!='\0')
{
- printf("PhotoRec syntax error: %s\n", cmd_run);
+ printf("PhotoRec syntax error: %s\n", params.cmd_run);
}
else
{
@@ -364,5 +370,6 @@ int main( int argc, char **argv )
if(use_sudo>0)
run_sudo(argc, argv);
#endif
+ free(params.recup_dir);
return 0;
}
diff --git a/src/phnc.c b/src/phnc.c
index 8d66706..f13dd80 100644
--- a/src/phnc.c
+++ b/src/phnc.c
@@ -81,36 +81,39 @@ void photorec_info(WINDOW *window, const file_stat_t *file_stats)
free(new_file_stats);
}
-int photorec_progressbar(WINDOW *window, const unsigned int pass, const photorec_status_t status, const uint64_t offset, disk_t *disk_car, partition_t *partition, const unsigned int file_nbr, const time_t elapsed_time, const file_stat_t *file_stats)
+int photorec_progressbar(WINDOW *window, const unsigned int pass, const struct ph_param *params, const uint64_t offset, const time_t current_time)
{
+ const partition_t *partition=params->partition;
+ const unsigned int sector_size=params->disk->sector_size;
wmove(window,9,0);
wclrtoeol(window);
- if(status==STATUS_EXT2_ON_BF || status==STATUS_EXT2_OFF_BF)
+ if(params->status==STATUS_EXT2_ON_BF || params->status==STATUS_EXT2_OFF_BF)
{
- wprintw(window,"Bruteforce %10lu sectors remaining (test %u), %u files found\n",
- (unsigned long)((offset-partition->part_offset)/disk_car->sector_size), pass, file_nbr);
+ wprintw(window,"Bruteforce %10lu sectors remaining (test %u), ",
+ (unsigned long)((offset-partition->part_offset)/sector_size),
+ pass);
}
else
{
- wprintw(window, "Pass %u - ", pass);
- if(status==STATUS_FIND_OFFSET)
- wprintw(window,"Reading sector %10llu/%llu, %u/10 headers found\n",
- (unsigned long long)((offset-partition->part_offset)/disk_car->sector_size),
- (unsigned long long)(partition->part_size/disk_car->sector_size), file_nbr);
- else
- wprintw(window,"Reading sector %10llu/%llu, %u files found\n",
- (unsigned long long)((offset-partition->part_offset)/disk_car->sector_size),
- (unsigned long long)(partition->part_size/disk_car->sector_size), file_nbr);
+ wprintw(window,"Pass %u - Reading sector %10llu/%llu, ",
+ pass,
+ (unsigned long long)((offset-partition->part_offset)/sector_size),
+ (unsigned long long)(partition->part_size/sector_size));
}
+ if(params->status==STATUS_FIND_OFFSET)
+ wprintw(window,"%u/10 headers found\n", params->file_nbr);
+ else
+ wprintw(window,"%u files found\n", params->file_nbr);
wmove(window,10,0);
wclrtoeol(window);
- if(elapsed_time>0)
+ if(current_time > params->real_start_time)
{
+ const time_t elapsed_time=current_time - params->real_start_time;
wprintw(window,"Elapsed time %uh%02um%02us",
(unsigned)(elapsed_time/60/60),
(unsigned)(elapsed_time/60%60),
(unsigned)(elapsed_time%60));
- if(offset > partition->part_offset && status!=STATUS_EXT2_ON_BF && status!=STATUS_EXT2_OFF_BF)
+ if(offset > partition->part_offset && params->status!=STATUS_EXT2_ON_BF && params->status!=STATUS_EXT2_OFF_BF)
{
wprintw(window," - Estimated time to completion %uh%02um%02u\n",
(unsigned)((partition->part_offset+partition->part_size-1-offset)*elapsed_time/(offset-partition->part_offset)/3600),
@@ -118,7 +121,7 @@ int photorec_progressbar(WINDOW *window, const unsigned int pass, const photorec
(unsigned)((partition->part_offset+partition->part_size-1-offset)*elapsed_time/(offset-partition->part_offset))%60);
}
}
- photorec_info(window, file_stats);
+ photorec_info(window, params->file_stats);
wrefresh(window);
return check_enter_key_or_s(window);
}
diff --git a/src/phnc.h b/src/phnc.h
index 320a776..0ccc4e0 100644
--- a/src/phnc.h
+++ b/src/phnc.h
@@ -24,7 +24,7 @@ extern "C" {
#endif
#ifdef HAVE_NCURSES
void photorec_info(WINDOW *window, const file_stat_t *file_stats);
-int photorec_progressbar(WINDOW *window, const unsigned int pass, const photorec_status_t status, const uint64_t offset, disk_t *disk_car, partition_t *partition, const unsigned int file_nbr, const time_t elapsed_time, const file_stat_t *file_stats);
+int photorec_progressbar(WINDOW *window, const unsigned int pass, const struct ph_param *params, const uint64_t offset, const time_t current_time);
#endif
#ifdef __cplusplus
} /* closing brace for extern "C" */
diff --git a/src/photorec.c b/src/photorec.c
index 7adc6ec..a171e43 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -577,25 +577,19 @@ static void free_list_allocation(alloc_list_t *list_allocation)
/** file_finish()
@param file_recovery -
- @param recup_dir - where the results go
- @param paranoid
- @param file_nbr
- @param blocksize
+ @param struct ph_param *params
@param alloc_data_t *list_search_space
@param alloc_data_t **current_search_space
@param *offset
- @param dir_num
- @param status
- @param dist_t *disk
@returns:
-1: file not recovered, file_size=0 offset_error!=0
0: file not recovered
1: file recovered
*/
-int file_finish(file_recovery_t *file_recovery, const char *recup_dir, const int paranoid, unsigned int *file_nbr,
- const unsigned int blocksize, alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset,
- unsigned int *dir_num, const photorec_status_t status, const disk_t *disk)
+
+int file_finish(file_recovery_t *file_recovery, struct ph_param *params,
+ alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset)
{
int file_recovered=0;
#ifdef DEBUG_FILE_FINISH
@@ -608,34 +602,31 @@ int file_finish(file_recovery_t *file_recovery, const char *recup_dir, const int
#endif
if(file_recovery->handle)
{
- if(status!=STATUS_EXT2_ON_SAVE_EVERYTHING && status!=STATUS_EXT2_OFF_SAVE_EVERYTHING)
- {
- if(file_recovery->file_stat!=NULL && file_recovery->file_check!=NULL && paranoid>0)
- { /* Check if recovered file is valid */
- file_recovery->file_check(file_recovery);
- }
- /* FIXME: need to adapt read_size to volume size to avoid this */
- if(file_recovery->file_size > disk->disk_size)
- file_recovery->file_size = disk->disk_size;
- if(file_recovery->file_size > disk->disk_real_size)
- file_recovery->file_size = disk->disk_real_size;
- if(file_recovery->file_stat!=NULL && file_recovery->file_size> 0 &&
- file_recovery->file_size < file_recovery->min_filesize)
- {
- log_info("File too small ( %llu < %llu), reject it\n",
- (long long unsigned) file_recovery->file_size,
- (long long unsigned) file_recovery->min_filesize);
- file_recovery->file_size=0;
- file_recovery->file_size_on_disk=0;
- }
+ if(file_recovery->file_stat!=NULL && file_recovery->file_check!=NULL)
+ { /* Check if recovered file is valid */
+ file_recovery->file_check(file_recovery);
+ }
+ /* FIXME: need to adapt read_size to volume size to avoid this */
+ if(file_recovery->file_size > params->disk->disk_size)
+ file_recovery->file_size = params->disk->disk_size;
+ if(file_recovery->file_size > params->disk->disk_real_size)
+ file_recovery->file_size = params->disk->disk_real_size;
+ if(file_recovery->file_stat!=NULL && file_recovery->file_size> 0 &&
+ file_recovery->file_size < file_recovery->min_filesize)
+ {
+ log_info("File too small ( %llu < %llu), reject it\n",
+ (long long unsigned) file_recovery->file_size,
+ (long long unsigned) file_recovery->min_filesize);
+ file_recovery->file_size=0;
+ file_recovery->file_size_on_disk=0;
+ }
#ifdef HAVE_FTRUNCATE
- fflush(file_recovery->handle);
- if(ftruncate(fileno(file_recovery->handle), file_recovery->file_size)<0)
- {
- log_critical("ftruncate failed.\n");
- }
-#endif
+ fflush(file_recovery->handle);
+ if(ftruncate(fileno(file_recovery->handle), file_recovery->file_size)<0)
+ {
+ log_critical("ftruncate failed.\n");
}
+#endif
fclose(file_recovery->handle);
file_recovery->handle=NULL;
// log_debug("%s %llu\n",file_recovery->filename,(long long unsigned)file_recovery->file_size);
@@ -648,12 +639,11 @@ int file_finish(file_recovery_t *file_recovery, const char *recup_dir, const int
{
if(file_recovery->time!=0 && file_recovery->time!=(time_t)-1)
set_date(file_recovery->filename, file_recovery->time, file_recovery->time);
- if((++(*file_nbr))%MAX_FILES_PER_DIR==0)
+ if((++params->file_nbr)%MAX_FILES_PER_DIR==0)
{
- *dir_num=photorec_mkdir(recup_dir,*dir_num+1);
+ params->dir_num=photorec_mkdir(params->recup_dir, params->dir_num+1);
}
- if(status!=STATUS_EXT2_ON_SAVE_EVERYTHING && status!=STATUS_EXT2_OFF_SAVE_EVERYTHING)
- file_recovery->file_stat->recovered++;
+ file_recovery->file_stat->recovered++;
}
}
if(file_recovery->file_stat!=NULL)
@@ -669,13 +659,10 @@ int file_finish(file_recovery_t *file_recovery, const char *recup_dir, const int
}
else
{
- list_space_used(file_recovery, disk->sector_size);
+ list_space_used(file_recovery, params->disk->sector_size);
xml_log_file_recovered(file_recovery);
- if(status!=STATUS_EXT2_ON_SAVE_EVERYTHING && status!=STATUS_EXT2_OFF_SAVE_EVERYTHING && status!=STATUS_FIND_OFFSET)
- {
- update_search_space(file_recovery,list_search_space,current_search_space,offset,blocksize);
- file_recovered=1; /* note that file was recovered */
- }
+ update_search_space(file_recovery, list_search_space, current_search_space, offset, params->blocksize);
+ file_recovered=1; /* note that file was recovered */
}
free_list_allocation(&file_recovery->location);
}
@@ -692,9 +679,7 @@ int file_finish(file_recovery_t *file_recovery, const char *recup_dir, const int
return file_recovered;
}
-alloc_data_t *file_finish2(file_recovery_t *file_recovery, const char *recup_dir, const struct ph_options *options, unsigned int *file_nbr,
- const unsigned int blocksize, alloc_data_t *list_search_space,
- unsigned int *dir_num, const photorec_status_t status, const disk_t *disk)
+alloc_data_t *file_finish2(file_recovery_t *file_recovery, struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space)
{
alloc_data_t *datanext=NULL;
#ifdef DEBUG_FILE_FINISH
@@ -704,17 +689,18 @@ alloc_data_t *file_finish2(file_recovery_t *file_recovery, const char *recup_dir
#endif
if(file_recovery->handle)
{
- if(status!=STATUS_EXT2_ON_SAVE_EVERYTHING && status!=STATUS_EXT2_OFF_SAVE_EVERYTHING)
+ if(params->status!=STATUS_EXT2_ON_SAVE_EVERYTHING &&
+ params->status!=STATUS_EXT2_OFF_SAVE_EVERYTHING)
{
if(file_recovery->file_stat!=NULL && file_recovery->file_check!=NULL && options->paranoid>0)
{ /* Check if recovered file is valid */
file_recovery->file_check(file_recovery);
}
/* FIXME: need to adapt read_size to volume size to avoid this */
- if(file_recovery->file_size > disk->disk_size)
- file_recovery->file_size = disk->disk_size;
- if(file_recovery->file_size > disk->disk_real_size)
- file_recovery->file_size = disk->disk_real_size;
+ if(file_recovery->file_size > params->disk->disk_size)
+ file_recovery->file_size = params->disk->disk_size;
+ if(file_recovery->file_size > params->disk->disk_real_size)
+ file_recovery->file_size = params->disk->disk_real_size;
if(file_recovery->file_stat!=NULL && file_recovery->file_size> 0 &&
file_recovery->file_size < file_recovery->min_filesize)
@@ -745,11 +731,12 @@ alloc_data_t *file_finish2(file_recovery_t *file_recovery, const char *recup_dir
set_date(file_recovery->filename, file_recovery->time, file_recovery->time);
if(file_recovery->file_rename!=NULL)
file_recovery->file_rename(file_recovery->filename);
- if((++(*file_nbr))%MAX_FILES_PER_DIR==0)
+ if((++params->file_nbr)%MAX_FILES_PER_DIR==0)
{
- *dir_num=photorec_mkdir(recup_dir,*dir_num+1);
+ params->dir_num=photorec_mkdir(params->recup_dir, params->dir_num+1);
}
- if(status!=STATUS_EXT2_ON_SAVE_EVERYTHING && status!=STATUS_EXT2_OFF_SAVE_EVERYTHING)
+ if(params->status!=STATUS_EXT2_ON_SAVE_EVERYTHING &&
+ params->status!=STATUS_EXT2_OFF_SAVE_EVERYTHING)
{
file_recovery->file_stat->recovered++;
}
@@ -761,12 +748,12 @@ alloc_data_t *file_finish2(file_recovery_t *file_recovery, const char *recup_dir
{
/* File hasn't been sucessfully recovered */
if(file_recovery->offset_error>0)
- datanext=file_error(list_search_space, file_recovery, blocksize);
+ datanext=file_error(list_search_space, file_recovery, params->blocksize);
}
else
{
xml_log_file_recovered2(list_search_space, file_recovery);
- datanext=file_truncate(list_search_space, file_recovery, disk->sector_size, blocksize);
+ datanext=file_truncate(list_search_space, file_recovery, params->disk->sector_size, params->blocksize);
}
free_list_allocation(&file_recovery->location);
}
@@ -935,19 +922,23 @@ void free_search_space(alloc_data_t *list_search_space)
}
}
-void set_filename(file_recovery_t *file_recovery, const char *recup_dir, const unsigned int dir_num, const disk_t *disk, const partition_t *partition, const int broken)
+void set_filename(file_recovery_t *file_recovery, struct ph_param *params)
{
+ const int broken=(params->status==STATUS_EXT2_ON_SAVE_EVERYTHING ||
+ params->status==STATUS_EXT2_OFF_SAVE_EVERYTHING);
if(file_recovery->extension==NULL || file_recovery->extension[0]=='\0')
{
- snprintf(file_recovery->filename,sizeof(file_recovery->filename)-1,"%s.%u/%c%07u",recup_dir,
- dir_num,(broken?'b':'f'),
- (unsigned int)((file_recovery->location.start-partition->part_offset)/disk->sector_size));
+ snprintf(file_recovery->filename,sizeof(file_recovery->filename)-1,
+ "%s.%u/%c%07u", params->recup_dir,
+ params->dir_num, (broken?'b':'f'),
+ (unsigned int)((file_recovery->location.start - params->partition->part_offset)/ params->disk->sector_size));
}
else
{
- snprintf(file_recovery->filename,sizeof(file_recovery->filename)-1,"%s.%u/%c%07u.%s",recup_dir,
- dir_num, (broken?'b':'f'),
- (unsigned int)((file_recovery->location.start-partition->part_offset)/disk->sector_size), file_recovery->extension);
+ snprintf(file_recovery->filename,sizeof(file_recovery->filename)-1,
+ "%s.%u/%c%07u.%s", params->recup_dir,
+ params->dir_num, (broken?'b':'f'),
+ (unsigned int)((file_recovery->location.start - params->partition->part_offset) / params->disk->sector_size), file_recovery->extension);
}
}
diff --git a/src/photorec.h b/src/photorec.h
index ba8db9b..520f107 100644
--- a/src/photorec.h
+++ b/src/photorec.h
@@ -36,16 +36,30 @@ struct ph_options
unsigned int expert;
unsigned int lowmem;
int verbose;
+ file_enable_t *list_file_format;
};
+struct ph_param
+{
+ char *cmd_device;
+ char *cmd_run;
+ disk_t *disk;
+ partition_t *partition;
+ unsigned int blocksize;
+ unsigned int pass;
+ photorec_status_t status;
+ time_t real_start_time;
+ char *recup_dir;
+ /* */
+ unsigned int dir_num;
+ unsigned int file_nbr;
+ file_stat_t *file_stats;
+};
int get_prev_file_header(alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset);
-int file_finish(file_recovery_t *file_recovery, const char *recup_dir, const int paranoid, unsigned int *file_nbr,
- const unsigned int blocksize, alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset,
- unsigned int *dir_num, const photorec_status_t status, const disk_t *disk);
-alloc_data_t *file_finish2(file_recovery_t *file_recovery, const char *recup_dir, const struct ph_options *options, unsigned int *file_nbr,
- const unsigned int blocksize, alloc_data_t *list_search_space,
- unsigned int *dir_num, const photorec_status_t status, const disk_t *disk);
+int file_finish(file_recovery_t *file_recovery, struct ph_param *params,
+ alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset);
+alloc_data_t *file_finish2(file_recovery_t *file_recovery, struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space);
void write_stats_log(const file_stat_t *file_stats);
void write_stats_stdout(const file_stat_t *file_stats);
void update_stats(file_stat_t *file_stats, alloc_data_t *list_search_space);
@@ -60,7 +74,7 @@ int sorfile_stat_ts(const void *p1, const void *p2);
unsigned int photorec_mkdir(const char *recup_dir, const unsigned int initial_dir_num);
void info_list_search_space(const alloc_data_t *list_search_space, const alloc_data_t *current_search_space, const unsigned int sector_size, const int keep_corrupted_file, const int verbose);
void free_search_space(alloc_data_t *list_search_space);
-void set_filename(file_recovery_t *file_recovery, const char *recup_dir, const unsigned int dir_num, const disk_t *disk, const partition_t *partition, const int broken);
+void set_filename(file_recovery_t *file_recovery, struct ph_param *params);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif
diff --git a/src/phrecn.c b/src/phrecn.c
index 8613629..1cb08c4 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -176,9 +176,9 @@ static alloc_data_t *file_add_data(alloc_data_t *data, const uint64_t offset, co
}
}
-static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct ph_options *options, const char *recup_dir, const int interface, file_stat_t *file_stats, unsigned int *file_nbr, const unsigned int blocksize, alloc_data_t *list_search_space, const time_t real_start_time, unsigned int *dir_num, const photorec_status_t status, const unsigned int pass)
+static int photorec_aux(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space)
{
- uint64_t offset=0;
+ uint64_t offset;
unsigned char *buffer_start;
unsigned char *buffer_olddata;
unsigned char *buffer;
@@ -186,6 +186,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
time_t previous_time;
int ind_stop=0;
unsigned int buffer_size;
+ const unsigned int blocksize=params->blocksize;
const unsigned int read_size=(blocksize>65536?blocksize:65536);
alloc_data_t *current_search_space;
file_recovery_t file_recovery;
@@ -199,30 +200,29 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
previous_time=start_time;
memset(buffer_olddata,0,blocksize);
current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list);
- if(current_search_space!=list_search_space)
- offset=current_search_space->start;
+ offset=current_search_space->start;
if(options->verbose > 0)
- info_list_search_space(list_search_space, current_search_space, disk_car->sector_size, 0, options->verbose);
+ info_list_search_space(list_search_space, current_search_space, params->disk->sector_size, 0, options->verbose);
if(options->verbose > 1)
{
log_verbose("Reading sector %10llu/%llu\n",
- (unsigned long long)((offset-partition->part_offset)/disk_car->sector_size),
- (unsigned long long)((partition->part_size-1)/disk_car->sector_size));
+ (unsigned long long)((offset-params->partition->part_offset)/params->disk->sector_size),
+ (unsigned long long)((params->partition->part_size-1)/params->disk->sector_size));
}
- disk_car->pread(disk_car, buffer, READ_SIZE, offset);
+ params->disk->pread(params->disk, buffer, READ_SIZE, offset);
while(current_search_space!=list_search_space)
{
int move_next=1;
uint64_t old_offset=offset;
#ifdef DEBUG
log_debug("sector %llu\n",
- (unsigned long long)((offset-partition->part_offset)/disk_car->sector_size));
+ (unsigned long long)((offset-params->partition->part_offset)/params->disk->sector_size));
if(!(current_search_space->start<=offset && offset<=current_search_space->end))
{
log_critical("BUG: offset=%llu not in [%llu-%llu]\n",
- (unsigned long long)(offset/disk_car->sector_size),
- (unsigned long long)(current_search_space->start/disk_car->sector_size),
- (unsigned long long)(current_search_space->end/disk_car->sector_size));
+ (unsigned long long)(offset/params->disk->sector_size),
+ (unsigned long long)(current_search_space->start/params->disk->sector_size),
+ (unsigned long long)(current_search_space->end/params->disk->sector_size));
log_close();
exit(1);
}
@@ -241,7 +241,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
if(options->verbose > 1)
{
log_verbose("Currently saving a tar file, sector %lu.\n",
- (unsigned long)((offset-partition->part_offset)/disk_car->sector_size));
+ (unsigned long)((offset-params->partition->part_offset)/params->disk->sector_size));
}
}
else
@@ -274,7 +274,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
log_trace("A known header has been found, recovery of the previous file is finished\n");
{
alloc_data_t *datanext;
- datanext=file_finish2(&file_recovery, recup_dir, options, file_nbr, blocksize, list_search_space, dir_num,status, disk_car);
+ datanext=file_finish2(&file_recovery, params, options, list_search_space);
if(datanext!=NULL)
{
current_search_space=datanext;
@@ -293,9 +293,9 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
log_info("%s header found at sector %lu\n",
((file_recovery.extension!=NULL && file_recovery.extension[0]!='\0')?
file_recovery.extension:file_recovery.file_stat->file_hint->description),
- (unsigned long)((file_recovery.location.start-partition->part_offset)/disk_car->sector_size));
+ (unsigned long)((file_recovery.location.start-params->partition->part_offset)/params->disk->sector_size));
log_info("file_recovery.location.start=%lu\n",
- (unsigned long)(file_recovery.location.start/disk_car->sector_size));
+ (unsigned long)(file_recovery.location.start/params->disk->sector_size));
}
if(file_recovery.file_stat->file_hint==&file_hint_dir && options->verbose > 0)
@@ -305,7 +305,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
if(dir_list!=NULL)
{
log_info("Sector %lu\n",
- (unsigned long)(file_recovery.location.start/disk_car->sector_size));
+ (unsigned long)(file_recovery.location.start/params->disk->sector_size));
dir_aff_log(NULL, dir_list);
delete_list_file(dir_list);
}
@@ -315,8 +315,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
}
if(file_recovery.file_stat!=NULL && file_recovery.handle==NULL)
{
- set_filename(&file_recovery, recup_dir, *dir_num, disk_car, partition,
- (status==STATUS_EXT2_ON_SAVE_EVERYTHING||status==STATUS_EXT2_OFF_SAVE_EVERYTHING));
+ set_filename(&file_recovery, params);
if(file_recovery.file_stat->file_hint->recover==1)
{
#if defined(__CYGWIN__) || defined(__MINGW32__)
@@ -336,7 +335,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
{
int res=1;
/* try to skip ext2/ext3 indirect block */
- if((status==STATUS_EXT2_ON || status==STATUS_EXT2_ON_SAVE_EVERYTHING) &&
+ 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)
{
@@ -345,10 +344,10 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
if(options->verbose > 1)
{
log_verbose("Skipping sector %10lu/%lu\n",
- (unsigned long)((offset-partition->part_offset)/disk_car->sector_size),
- (unsigned long)((partition->part_size-1)/disk_car->sector_size));
+ (unsigned long)((offset-params->partition->part_offset)/params->disk->sector_size),
+ (unsigned long)((params->partition->part_size-1)/params->disk->sector_size));
}
- memcpy(buffer,buffer_olddata,blocksize);
+ memcpy(buffer, buffer_olddata, blocksize);
}
else
{
@@ -389,7 +388,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
log_verbose("File should not be bigger than %llu, stop adding data\n",
(long long unsigned)file_recovery.file_stat->file_hint->max_filesize);
}
- if(res!=2 && file_recovery.file_size + blocksize >= PHOTOREC_MAX_SIZE_32 && is_fat(partition))
+ if(res!=2 && file_recovery.file_size + blocksize >= PHOTOREC_MAX_SIZE_32 && is_fat(params->partition))
{
res=2;
log_verbose("File should not be bigger than %llu, stop adding data\n",
@@ -398,7 +397,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
if(res==2)
{
alloc_data_t *datanext;
- datanext=file_finish2(&file_recovery, recup_dir, options, file_nbr, blocksize, list_search_space, dir_num,status, disk_car);
+ datanext=file_finish2(&file_recovery, params, options, list_search_space);
if(datanext!=NULL)
{
current_search_space=datanext;
@@ -432,7 +431,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
current_search_space, current_search_space->list.prev, current_search_space->list.next);
log_trace("End of media\n");
#endif
- datanext=file_finish2(&file_recovery, recup_dir, options, file_nbr, blocksize, list_search_space, dir_num,status, disk_car);
+ datanext=file_finish2(&file_recovery, params, options, list_search_space);
if(datanext!=NULL)
{
current_search_space=datanext;
@@ -458,33 +457,27 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
if(options->verbose > 1)
{
log_verbose("Reading sector %10llu/%llu\n",
- (unsigned long long)((offset-partition->part_offset)/disk_car->sector_size),
- (unsigned long long)((partition->part_size-1)/disk_car->sector_size));
+ (unsigned long long)((offset-params->partition->part_offset)/params->disk->sector_size),
+ (unsigned long long)((params->partition->part_size-1)/params->disk->sector_size));
}
- if(disk_car->pread(disk_car, buffer, READ_SIZE, offset) != READ_SIZE)
+ if(params->disk->pread(params->disk, buffer, READ_SIZE, offset) != READ_SIZE)
{
#ifdef HAVE_NCURSES
- if(interface!=0)
- {
- wmove(stdscr,11,0);
- wclrtoeol(stdscr);
- wprintw(stdscr,"Error reading sector %10lu\n",
- (unsigned long)((offset-partition->part_offset)/disk_car->sector_size));
- }
+ wmove(stdscr,11,0);
+ wclrtoeol(stdscr);
+ wprintw(stdscr,"Error reading sector %10lu\n",
+ (unsigned long)((offset-params->partition->part_offset)/params->disk->sector_size));
#endif
}
#ifdef HAVE_NCURSES
- if(interface!=0 && ind_stop==0)
+ if(ind_stop==0)
{
time_t current_time;
current_time=time(NULL);
if(current_time>previous_time)
{
previous_time=current_time;
- ind_stop=photorec_progressbar(stdscr, pass, status, offset, disk_car,
- partition, *file_nbr,
- (current_time > real_start_time ? current_time - real_start_time: 0),
- file_stats);
+ ind_stop=photorec_progressbar(stdscr, params->pass, params, offset, current_time);
}
}
#endif
@@ -492,7 +485,7 @@ static int photorec_aux(disk_t *disk_car, partition_t *partition, const struct p
} /* end while(current_search_space!=list_search_space) */
free(buffer_start);
#ifdef HAVE_NCURSES
- photorec_info(stdscr, file_stats);
+ photorec_info(stdscr, params->file_stats);
#endif
return ind_stop;
}
@@ -659,11 +652,11 @@ static inline void list_append_block(alloc_list_t *list, const uint64_t offset,
}
}
-static void test_files_aux(disk_t *disk, partition_t *partition, file_recovery_t *file_recovery, const char *recup_dir, const unsigned int dir_num, const uint64_t start, const uint64_t end)
+static void test_files_aux(file_recovery_t *file_recovery, struct ph_param *params, const uint64_t start, const uint64_t end)
{
uint64_t datasize=end-start+1;
unsigned char *buffer=(unsigned char *) MALLOC(datasize);
- disk->pread(disk, buffer, datasize, start);
+ params->disk->pread(params->disk, buffer, datasize, start);
if(file_recovery->file_stat==NULL)
{
struct td_list_head *tmpl;
@@ -696,7 +689,7 @@ static void test_files_aux(disk_t *disk, partition_t *partition, file_recovery_t
}
if(file_recovery->handle==NULL)
{
- set_filename(file_recovery, recup_dir, dir_num, disk, partition, 0);
+ set_filename(file_recovery, params);
file_recovery->handle=fopen(file_recovery->filename, "w+b");
if(file_recovery->handle==NULL)
{
@@ -708,7 +701,7 @@ static void test_files_aux(disk_t *disk, partition_t *partition, file_recovery_t
if(fwrite(buffer, datasize, 1, file_recovery->handle)<1)
{
log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
- fclose(file_recovery->handle)
+ fclose(file_recovery->handle);
file_recovery->handle=NULL;
free(buffer);
return;
@@ -720,18 +713,18 @@ static void test_files_aux(disk_t *disk, partition_t *partition, file_recovery_t
free(buffer);
}
-static void test_files(disk_t *disk, partition_t *partition, alloc_data_t *list_search_space, char *recup_dir, unsigned int *dir_num, unsigned int *file_nbr)
+static void test_files(alloc_data_t *list_search_space, struct ph_param *params)
{
alloc_data_t *current_search_space=list_search_space;
uint64_t offset;
file_recovery_t file_recovery;
reset_file_recovery(&file_recovery);
- file_recovery->blocksize=512;
+ file_recovery.blocksize=512;
offset=current_search_space->start;
/* Recover a file with a known location */
- test_files_aux(disk, partition, &file_recovery, recup_dir, *dir_num, 1289*512, (1304+1)*512-1);
- test_files_aux(disk, partition, &file_recovery, recup_dir, *dir_num, 2881*512, (3259+1)*512-1);
- file_finish(&file_recovery, recup_dir, 1, file_nbr, disk->sector_size, list_search_space, &current_search_space, &offset, dir_num, STATUS_EXT2_OFF, disk);
+ test_files_aux(&file_recovery, params, 1289*512, (1304+1)*512-1);
+ test_files_aux(&file_recovery, params, 2881*512, (3259+1)*512-1);
+ file_finish(&file_recovery, params, list_search_space, &current_search_space, &offset);
/* Exclude some sectors from the search space */
del_search_space(list_search_space, 121407*512, (121416+1)*512-1);
@@ -740,43 +733,36 @@ static void test_files(disk_t *disk, partition_t *partition, alloc_data_t *list_
}
#endif
-int photorec(disk_t *disk_car, partition_t *partition, const struct ph_options *options, char *recup_dir, const int interface, file_enable_t *files_enable, char **current_cmd, alloc_data_t *list_search_space, unsigned int blocksize, const unsigned int carve_free_space_only)
+int photorec(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space, const unsigned int carve_free_space_only)
{
- char *new_recup_dir=NULL;
- file_stat_t *file_stats;
- time_t real_start_time;
- unsigned int file_nbr=0;
- unsigned int dir_num=1;
int ind_stop=0;
- unsigned int pass;
unsigned int blocksize_is_known=0;
- photorec_status_t status;
+ 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);
+
screen_buffer_reset();
log_info("\nAnalyse\n");
- log_partition(disk_car,partition);
- if(blocksize==0)
- blocksize=disk_car->sector_size;
+ log_partition(params->disk, params->partition);
+ if(params->blocksize==0)
+ params->blocksize=params->disk->sector_size;
else
blocksize_is_known=1;
- file_stats=init_file_stats(files_enable);
- real_start_time=time(NULL);
/* make the first recup_dir */
- dir_num=photorec_mkdir(recup_dir, dir_num);
+ params->dir_num=photorec_mkdir(params->recup_dir, params->dir_num);
/* Open the XML output file */
- xml_open(recup_dir, dir_num);
- xml_setup(disk_car, partition);
+ xml_open(params->recup_dir, params->dir_num);
+ xml_setup(params->disk, params->partition);
-#if 0
- test_files(disk_car, partition, list_search_space, recup_dir, &dir_num, &file_nbr);
-#endif
- status=STATUS_FIND_OFFSET;
- for(pass=0;status!=STATUS_QUIT;pass++)
+ for(params->pass=0; params->status!=STATUS_QUIT; params->pass++)
{
- unsigned int old_file_nbr=file_nbr;
- log_info("Pass %u (blocksize=%u) ",pass,blocksize);
- switch(status)
+ unsigned int old_file_nbr=params->file_nbr;
+ log_info("Pass %u (blocksize=%u) ", params->pass, params->blocksize);
+ switch(params->status)
{
case STATUS_FIND_OFFSET: log_info("STATUS_FIND_OFFSET\n"); break;
case STATUS_UNFORMAT: log_info("STATUS_UNFORMAT\n"); break;
@@ -789,53 +775,50 @@ int photorec(disk_t *disk_car, partition_t *partition, const struct ph_options *
case STATUS_QUIT : log_info("STATUS_QUIT\n"); break;
}
#ifdef HAVE_NCURSES
- if(interface)
- {
- aff_copy(stdscr);
- wmove(stdscr,4,0);
- wprintw(stdscr,"%s",disk_car->description_short(disk_car));
- mvwaddstr(stdscr,5,0,msg_PART_HEADER_LONG);
- wmove(stdscr,6,0);
- aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,partition);
- wmove(stdscr,22,0);
- wattrset(stdscr, A_REVERSE);
- waddstr(stdscr," Stop ");
- wattroff(stdscr, A_REVERSE);
- wrefresh(stdscr);
- }
+ aff_copy(stdscr);
+ wmove(stdscr, 4, 0);
+ wprintw(stdscr, "%s", params->disk->description_short(params->disk));
+ mvwaddstr(stdscr, 5, 0, msg_PART_HEADER_LONG);
+ wmove(stdscr, 6, 0);
+ aff_part(stdscr, AFF_PART_ORDER|AFF_PART_STATUS, params->disk, params->partition);
+ wmove(stdscr, 22, 0);
+ wattrset(stdscr, A_REVERSE);
+ waddstr(stdscr, " Stop ");
+ wattroff(stdscr, A_REVERSE);
+ wrefresh(stdscr);
#endif
- if(status==STATUS_FIND_OFFSET && blocksize_is_known>0)
+ if(params->status==STATUS_FIND_OFFSET && blocksize_is_known>0)
{
ind_stop=0;
}
- else if(status==STATUS_UNFORMAT)
+ else if(params->status==STATUS_UNFORMAT)
{
- const unsigned int old_blocksize=blocksize;
- blocksize=0;
- ind_stop=fat_unformat(disk_car, partition, options, recup_dir, interface, &file_nbr, &blocksize, list_search_space, real_start_time, &dir_num);
- if(blocksize==0)
- blocksize=old_blocksize;
+ const unsigned int old_blocksize=params->blocksize;
+ params->blocksize=0;
+ ind_stop=fat_unformat(params, options, list_search_space);
+ if(params->blocksize==0)
+ params->blocksize=old_blocksize;
}
- else if(status==STATUS_FIND_OFFSET)
+ else if(params->status==STATUS_FIND_OFFSET)
{
- ind_stop=photorec_find_blocksize(disk_car, partition, options->verbose, interface, file_stats, &file_nbr, &blocksize, list_search_space, real_start_time);
+ ind_stop=photorec_find_blocksize(params, options, list_search_space);
}
- else if(status==STATUS_EXT2_ON_BF || status==STATUS_EXT2_OFF_BF)
+ else if(params->status==STATUS_EXT2_ON_BF || params->status==STATUS_EXT2_OFF_BF)
{
- ind_stop=photorec_bf(disk_car, partition, options->verbose, recup_dir, interface, file_stats, &file_nbr, blocksize, list_search_space, real_start_time, &dir_num, status, pass);
- session_save(list_search_space, disk_car, partition, files_enable, blocksize, options, carve_free_space_only);
+ ind_stop=photorec_bf(params, options, list_search_space);
+ session_save(list_search_space, params, options, carve_free_space_only);
}
else
{
- ind_stop=photorec_aux(disk_car, partition, options, recup_dir, interface, file_stats, &file_nbr, blocksize, list_search_space, real_start_time, &dir_num, status, pass);
- session_save(list_search_space, disk_car, partition, files_enable, blocksize, options, carve_free_space_only);
+ ind_stop=photorec_aux(params, options, list_search_space);
+ session_save(list_search_space, params, options, carve_free_space_only);
}
if(ind_stop==3)
{ /* no more space */
#ifdef HAVE_NCURSES
char *dst;
char *res;
- dst=strdup(recup_dir);
+ dst=strdup(params->recup_dir);
if(dst!=NULL)
{
res=strrchr(dst, '/');
@@ -845,134 +828,133 @@ int photorec(disk_t *disk_car, partition_t *partition, const struct ph_options *
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)
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
else
{
- free(new_recup_dir);
- new_recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
- strcpy(new_recup_dir,res);
- strcat(new_recup_dir,"/");
- strcat(new_recup_dir,DEFAULT_RECUP_DIR);
- recup_dir=new_recup_dir;
+ 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 */
- dir_num=photorec_mkdir(recup_dir,dir_num);
+ params->dir_num=photorec_mkdir(params->recup_dir,params->dir_num);
}
#else
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
#endif
}
else if(ind_stop==2)
{
if(interface_cannot_create_file()!=0)
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
}
else if(ind_stop>0)
{
- if(session_save(list_search_space, disk_car, partition, files_enable, blocksize, options, carve_free_space_only) < 0)
+ if(session_save(list_search_space, params, options, carve_free_space_only) < 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)
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
#endif
}
else
{
#ifdef HAVE_NCURSES
if(ask_confirmation("Answer Y to really Quit, N to resume the recovery")!=0)
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
#endif
}
}
else if(options->paranoid>0)
{
- switch(status)
+ switch(params->status)
{
case STATUS_FIND_OFFSET:
{
uint64_t start_offset;
- file_nbr=0;
- status=(options->mode_ext2>0?STATUS_EXT2_ON:STATUS_EXT2_OFF);
+ params->file_nbr=0;
+ params->status=(options->mode_ext2>0?STATUS_EXT2_ON:STATUS_EXT2_OFF);
if(blocksize_is_known==0)
- blocksize=find_blocksize(list_search_space, disk_car->sector_size, &start_offset);
+ params->blocksize=find_blocksize(list_search_space, params->disk->sector_size, &start_offset);
else if(td_list_empty(&list_search_space->list))
start_offset=0;
else
- start_offset=(td_list_entry(list_search_space->list.next, alloc_data_t, list))->start % blocksize;
+ start_offset=(td_list_entry(list_search_space->list.next, alloc_data_t, list))->start % params->blocksize;
#ifdef HAVE_NCURSES
if(options->expert>0)
{
if(ask_confirmation("Try to unformat a FAT filesystem (Y/N)")!=0)
- status=STATUS_UNFORMAT;
+ params->status=STATUS_UNFORMAT;
else
{
- blocksize=menu_choose_blocksize(blocksize, disk_car->sector_size, &start_offset);
- update_blocksize(blocksize,list_search_space, start_offset);
+ params->blocksize=menu_choose_blocksize(params->blocksize, params->disk->sector_size, &start_offset);
+ update_blocksize(params->blocksize, list_search_space, start_offset);
}
}
else
{
- update_blocksize(blocksize,list_search_space, start_offset);
+ update_blocksize(params->blocksize, list_search_space, start_offset);
}
#else
- update_blocksize(blocksize,list_search_space, start_offset);
+ update_blocksize(params->blocksize, list_search_space, start_offset);
#endif
}
break;
case STATUS_UNFORMAT:
{
- status=(options->mode_ext2>0?STATUS_EXT2_ON:STATUS_EXT2_OFF);
- file_nbr=0;
+ params->status=(options->mode_ext2>0?STATUS_EXT2_ON:STATUS_EXT2_OFF);
+ params->file_nbr=0;
}
break;
case STATUS_EXT2_ON:
- status=(options->paranoid>1?STATUS_EXT2_ON_BF:STATUS_EXT2_OFF);
+ params->status=(options->paranoid>1?STATUS_EXT2_ON_BF:STATUS_EXT2_OFF);
break;
case STATUS_EXT2_ON_BF:
- status=STATUS_EXT2_OFF;
+ params->status=STATUS_EXT2_OFF;
break;
case STATUS_EXT2_OFF:
if(options->paranoid>1)
{
- status=STATUS_EXT2_OFF_BF;
+ params->status=STATUS_EXT2_OFF_BF;
}
else
{
if(options->keep_corrupted_file>0)
- status=(options->mode_ext2>0?STATUS_EXT2_ON_SAVE_EVERYTHING:STATUS_EXT2_OFF_SAVE_EVERYTHING);
+ params->status=(options->mode_ext2>0?STATUS_EXT2_ON_SAVE_EVERYTHING:STATUS_EXT2_OFF_SAVE_EVERYTHING);
else
{
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
unlink("photorec.ses");
}
}
break;
case STATUS_EXT2_OFF_BF:
if(options->keep_corrupted_file>0)
- status=(options->mode_ext2>0?STATUS_EXT2_ON_SAVE_EVERYTHING:STATUS_EXT2_OFF_SAVE_EVERYTHING);
+ params->status=(options->mode_ext2>0?STATUS_EXT2_ON_SAVE_EVERYTHING:STATUS_EXT2_OFF_SAVE_EVERYTHING);
else
{
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
unlink("photorec.ses");
}
break;
case STATUS_EXT2_ON_SAVE_EVERYTHING:
- status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
+ params->status=STATUS_EXT2_OFF_SAVE_EVERYTHING;
break;
default:
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
unlink("photorec.ses");
break;
}
}
else
{
- switch(status)
+ switch(params->status)
{
case STATUS_FIND_OFFSET:
- file_nbr=0;
- status=(options->mode_ext2>0?STATUS_EXT2_ON_SAVE_EVERYTHING:STATUS_EXT2_OFF_SAVE_EVERYTHING);
+ params->file_nbr=0;
+ params->status=(options->mode_ext2>0?STATUS_EXT2_ON_SAVE_EVERYTHING:STATUS_EXT2_OFF_SAVE_EVERYTHING);
#ifdef HAVE_NCURSES
if(options->expert>0)
{
@@ -981,21 +963,21 @@ int photorec(disk_t *disk_car, partition_t *partition, const struct ph_options *
{
alloc_data_t *tmp;
tmp=td_list_entry(list_search_space->list.next, alloc_data_t, list);
- offset=tmp->start%blocksize;
+ offset=tmp->start % params->blocksize;
}
- blocksize=menu_choose_blocksize(blocksize, disk_car->sector_size, &offset);
- update_blocksize(blocksize,list_search_space, offset);
+ params->blocksize=menu_choose_blocksize(params->blocksize, params->disk->sector_size, &offset);
+ update_blocksize(params->blocksize, list_search_space, offset);
if(ask_confirmation("Try to unformat a FAT filesystem (Y/N)")!=0)
- status=STATUS_UNFORMAT;
+ params->status=STATUS_UNFORMAT;
}
#endif
break;
case STATUS_UNFORMAT:
- status=(options->mode_ext2>0?STATUS_EXT2_ON_SAVE_EVERYTHING:STATUS_EXT2_OFF_SAVE_EVERYTHING);
- file_nbr=0;
+ params->status=(options->mode_ext2>0?STATUS_EXT2_ON_SAVE_EVERYTHING:STATUS_EXT2_OFF_SAVE_EVERYTHING);
+ params->file_nbr=0;
break;
default:
- status=STATUS_QUIT;
+ params->status=STATUS_QUIT;
unlink("photorec.ses");
break;
}
@@ -1004,21 +986,15 @@ int photorec(disk_t *disk_car, partition_t *partition, const struct ph_options *
time_t current_time;
current_time=time(NULL);
log_info("Elapsed time %uh%02um%02us\n",
- (unsigned)((current_time-real_start_time)/60/60),
- (unsigned)((current_time-real_start_time)/60%60),
- (unsigned)((current_time-real_start_time)%60));
- }
- update_stats(file_stats,list_search_space);
- if(pass>0)
- {
- log_info("Pass %u +%u file%s\n",pass,file_nbr-old_file_nbr,(file_nbr-old_file_nbr<=1?"":"s"));
- write_stats_log(file_stats);
+ (unsigned)((current_time-params->real_start_time)/60/60),
+ (unsigned)((current_time-params->real_start_time)/60%60),
+ (unsigned)((current_time-params->real_start_time)%60));
}
- if(interface==0)
+ update_stats(params->file_stats, list_search_space);
+ if(params->pass>0)
{
- printf("Pass %u +%u file%s\n",pass,file_nbr-old_file_nbr,(file_nbr-old_file_nbr<=1?"":"s"));
- write_stats_stdout(file_stats);
- fflush(stdout);
+ log_info("Pass %u +%u file%s\n",params->pass,params->file_nbr-old_file_nbr,(params->file_nbr-old_file_nbr<=1?"":"s"));
+ write_stats_log(params->file_stats);
}
log_flush();
}
@@ -1041,7 +1017,7 @@ int photorec(disk_t *disk_car, partition_t *partition, const struct ph_options *
{
char *filename;
char *res;
- char *dst_path=strdup(recup_dir);
+ char *dst_path=strdup(params->recup_dir);
res=strrchr(dst_path, '/');
if(res!=NULL)
*res='\0';
@@ -1049,22 +1025,22 @@ int photorec(disk_t *disk_car, partition_t *partition, const struct ph_options *
strcpy(filename, dst_path);
strcat(filename, "/");
strcat(filename, DEFAULT_IMAGE_NAME);
- gen_image(filename, disk_car, list_search_space);
+ gen_image(filename, params->disk, list_search_space);
free(filename);
free(dst_path);
}
}
#endif
- info_list_search_space(list_search_space, NULL, disk_car->sector_size, options->keep_corrupted_file, options->verbose);
+ info_list_search_space(list_search_space, NULL, params->disk->sector_size, options->keep_corrupted_file, options->verbose);
/* Free memory */
free_search_space(list_search_space);
#ifdef HAVE_NCURSES
- if(interface && *current_cmd==NULL)
- recovery_finished(disk_car, partition, file_nbr, recup_dir, ind_stop);
+ if(params->cmd_run==NULL)
+ recovery_finished(params->disk, params->partition, params->file_nbr, params->recup_dir, ind_stop);
#endif
- free(file_stats);
+ free(params->file_stats);
+ params->file_stats=NULL;
free_header_check();
- free(new_recup_dir);
xml_shutdown();
xml_close();
return 0;
diff --git a/src/phrecn.h b/src/phrecn.h
index 63d29e8..07b1d99 100644
--- a/src/phrecn.h
+++ b/src/phrecn.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-int photorec(disk_t *disk_car, partition_t *partition, const struct ph_options *options, char *recup_dir, const int interface, file_enable_t *file_enable, char **current_cmd, alloc_data_t *list_search_space, unsigned int blocksize, const unsigned int carve_free_space_only);
+int photorec(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space, const unsigned int carve_free_space_only);
void interface_file_select(file_enable_t *files_enable, char**current_cmd);
void interface_options_photorec(struct ph_options *options, char**current_cmd);
diff --git a/src/ppartsel.c b/src/ppartsel.c
index 589087f..d2729b1 100644
--- a/src/ppartsel.c
+++ b/src/ppartsel.c
@@ -74,13 +74,12 @@ static int spacerange_cmp(const struct td_list_head *a, const struct td_list_hea
#define INTER_SELECT (LINES-2-7-1)
#endif
-void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *recup_dir, file_enable_t *file_enable, char **current_cmd, alloc_data_t*list_search_space)
+void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_data_t*list_search_space)
{
int insert_error=0;
list_part_t *list_part;
list_part_t *current_element;
unsigned int current_element_num;
- unsigned int blocksize=0;
unsigned int carve_free_space_only=0;
int done=0;
int mode_init_space=(td_list_empty(&list_search_space->list)?INIT_SPACE_WHOLE:INIT_SPACE_PREINIT);
@@ -98,10 +97,11 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
{0,NULL,NULL}
};
#endif
- list_part=disk_car->arch->read_part(disk_car,options->verbose,0);
+ params->blocksize=0;
+ list_part=params->disk->arch->read_part(params->disk,options->verbose,0);
{
partition_t *partition_wd;
- partition_wd=new_whole_disk(disk_car);
+ partition_wd=new_whole_disk(params->disk);
list_part=insert_new_partition(list_part, partition_wd, 0, &insert_error);
if(insert_error>0)
{
@@ -114,7 +114,7 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
list_part_t *element;
for(element=list_part;element!=NULL;element=element->next)
{
- log_partition(disk_car,element->part);
+ log_partition(params->disk,element->part);
}
}
if(list_part->next!=NULL)
@@ -129,23 +129,21 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
}
while(done==0)
{
- if(*current_cmd!=NULL)
+ if(params->cmd_run!=NULL)
{
- while(*current_cmd[0]==',')
- (*current_cmd)++;
- if(*current_cmd[0]=='\0')
+ while(params->cmd_run[0]==',')
+ params->cmd_run++;
+ if(params->cmd_run[0]=='\0')
{
part_free_list(list_part);
return;
}
- if(strncmp(*current_cmd,"search",6)==0)
+ if(strncmp(params->cmd_run,"search",6)==0)
{
- char *res;
- (*current_cmd)+=6;
- if(recup_dir!=NULL)
- res=(char *)recup_dir;
- else
+ params->cmd_run+=6;
+ if(params->recup_dir==NULL)
{
+ char *res;
#ifdef HAVE_NCURSES
res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL);
#else
@@ -153,90 +151,86 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
#endif
if(res!=NULL)
{
- char *new_recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
- strcpy(new_recup_dir,res);
- strcat(new_recup_dir,"/");
- strcat(new_recup_dir,DEFAULT_RECUP_DIR);
- if(res!=recup_dir)
- free(res);
- res=new_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);
}
}
- if(res!=NULL)
+ if(params->recup_dir!=NULL)
{
- partition_t *partition=current_element->part;
+ params->partition=current_element->part;
if(mode_init_space==INIT_SPACE_EXT2_GROUP)
{
- blocksize=ext2_fix_group(list_search_space, disk_car, partition);
- if(blocksize==0)
+ params->blocksize=ext2_fix_group(list_search_space, params->disk, params->partition);
+ if(params->blocksize==0)
display_message("Not a valid ext2/ext3/ext4 filesystem");
}
else if(mode_init_space==INIT_SPACE_EXT2_INODE)
{
- blocksize=ext2_fix_inode(list_search_space, disk_car, partition);
- if(blocksize==0)
+ params->blocksize=ext2_fix_inode(list_search_space, params->disk, params->partition);
+ if(params->blocksize==0)
display_message("Not a valid ext2/ext3/ext4 filesystem");
}
if(td_list_empty(&list_search_space->list))
{
- init_search_space(list_search_space, disk_car, partition);
+ init_search_space(list_search_space, params->disk, params->partition);
}
if(carve_free_space_only>0)
{
- blocksize=remove_used_space(disk_car, partition, list_search_space);
+ params->blocksize=remove_used_space(params->disk, params->partition, list_search_space);
}
- photorec(disk_car, partition, options, res, 1, file_enable, current_cmd, list_search_space, blocksize, carve_free_space_only);
+ photorec(params, options, list_search_space, carve_free_space_only);
}
- if(res!=recup_dir)
- free(res);
}
- else if(strncmp(*current_cmd,"options",7)==0)
+ else if(strncmp(params->cmd_run,"options",7)==0)
{
const int old_allow_partial_last_cylinder=options->allow_partial_last_cylinder;
- (*current_cmd)+=7;
- interface_options_photorec(options, current_cmd);
+ params->cmd_run+=7;
+ interface_options_photorec(options, &params->cmd_run);
if(old_allow_partial_last_cylinder!=options->allow_partial_last_cylinder)
- hd_update_geometry(disk_car, options->allow_partial_last_cylinder, options->verbose);
+ hd_update_geometry(params->disk, options->allow_partial_last_cylinder, options->verbose);
}
- else if(strncmp(*current_cmd,"fileopt",7)==0)
+ else if(strncmp(params->cmd_run,"fileopt",7)==0)
{
- (*current_cmd)+=7;
- interface_file_select(file_enable,current_cmd);
+ params->cmd_run+=7;
+ interface_file_select(options->list_file_format, &params->cmd_run);
}
- else if(strncmp(*current_cmd,"blocksize,",10)==0)
+ else if(strncmp(params->cmd_run,"blocksize,",10)==0)
{
- (*current_cmd)+=10;
- blocksize=atoi(*current_cmd);
- while(*current_cmd[0]!=',' && *current_cmd[0]!='\0')
- (*current_cmd)++;
+ params->cmd_run+=10;
+ params->blocksize=atoi(params->cmd_run);
+ while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0')
+ params->cmd_run++;
}
- else if(strncmp(*current_cmd,"geometry,",9)==0)
+ else if(strncmp(params->cmd_run,"geometry,",9)==0)
{
- (*current_cmd)+=9;
- change_geometry(disk_car,current_cmd);
+ params->cmd_run+=9;
+ change_geometry(params->disk, &params->cmd_run);
}
- else if(strncmp(*current_cmd,"inter",5)==0)
+ else if(strncmp(params->cmd_run,"inter",5)==0)
{ /* Start interactive mode */
- *current_cmd=NULL;
+ params->cmd_run=NULL;
}
- else if(strncmp(*current_cmd,"wholespace",10)==0)
+ else if(strncmp(params->cmd_run,"wholespace",10)==0)
{
- (*current_cmd)+=10;
+ params->cmd_run+=10;
carve_free_space_only=0;
}
- else if(strncmp(*current_cmd,"freespace",9)==0)
+ else if(strncmp(params->cmd_run,"freespace",9)==0)
{
- (*current_cmd)+=9;
+ params->cmd_run+=9;
carve_free_space_only=1;
}
- else if(strncmp(*current_cmd,"ext2_group,",11)==0)
+ else if(strncmp(params->cmd_run,"ext2_group,",11)==0)
{
unsigned int groupnr;
- (*current_cmd)+=11;
+ params->cmd_run+=11;
options->mode_ext2=1;
- groupnr=atoi(*current_cmd);
- while(*current_cmd[0]!=',' && *current_cmd[0]!='\0')
- (*current_cmd)++;
+ groupnr=atoi(params->cmd_run);
+ while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0')
+ params->cmd_run++;
if(mode_init_space==INIT_SPACE_WHOLE)
mode_init_space=INIT_SPACE_EXT2_GROUP;
if(mode_init_space==INIT_SPACE_EXT2_GROUP)
@@ -251,14 +245,14 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
free(new_free_space);
}
}
- else if(strncmp(*current_cmd,"ext2_inode,",11)==0)
+ else if(strncmp(params->cmd_run,"ext2_inode,",11)==0)
{
unsigned int inodenr;
- (*current_cmd)+=11;
+ params->cmd_run+=11;
options->mode_ext2=1;
- inodenr=atoi(*current_cmd);
- while(*current_cmd[0]!=',' && *current_cmd[0]!='\0')
- (*current_cmd)++;
+ inodenr=atoi(params->cmd_run);
+ while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0')
+ params->cmd_run++;
if(mode_init_space==INIT_SPACE_WHOLE)
mode_init_space=INIT_SPACE_EXT2_INODE;
if(mode_init_space==INIT_SPACE_EXT2_INODE)
@@ -273,20 +267,20 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
free(new_free_space);
}
}
- else if(isdigit(*current_cmd[0]))
+ else if(isdigit(params->cmd_run[0]))
{
list_part_t *element;
unsigned int order;
- order= atoi(*current_cmd);
- while(*current_cmd[0]!=',' && *current_cmd[0]!='\0')
- (*current_cmd)++;
+ order= atoi(params->cmd_run);
+ while(params->cmd_run[0]!=',' && params->cmd_run[0]!='\0')
+ params->cmd_run++;
for(element=list_part;element!=NULL && element->part->order!=order;element=element->next);
if(element!=NULL)
current_element=element;
}
else
{
- log_critical("Syntax error in command line: %s\n",*current_cmd);
+ log_critical("Syntax error in command line: %s\n", params->cmd_run);
part_free_list(list_part);
return;
}
@@ -298,7 +292,7 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
unsigned int i;
aff_copy(stdscr);
wmove(stdscr,4,0);
- wprintw(stdscr,"%s",disk_car->description_short(disk_car));
+ wprintw(stdscr,"%s",params->disk->description_short(params->disk));
mvwaddstr(stdscr,6,0,msg_PART_HEADER_LONG);
#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE)
mousemask(ALL_MOUSE_EVENTS, NULL);
@@ -313,12 +307,12 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
{
wattrset(stdscr, A_REVERSE);
waddstr(stdscr, ">");
- aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,element->part);
+ aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part);
wattroff(stdscr, A_REVERSE);
} else
{
waddstr(stdscr, " ");
- aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,disk_car,element->part);
+ aff_part(stdscr,AFF_PART_ORDER|AFF_PART_STATUS,params->disk,element->part);
}
}
wmove(stdscr,7+INTER_SELECT,5);
@@ -392,31 +386,27 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
case 'S':
if(current_element!=NULL)
{
- char *res;
- partition_t *partition=current_element->part;
- ask_mode_ext2(disk_car, partition, &options->mode_ext2, &carve_free_space_only);
+ params->partition=current_element->part;
+ ask_mode_ext2(params->disk, params->partition, &options->mode_ext2, &carve_free_space_only);
menu=0;
- if(recup_dir!=NULL)
- res=(char *)recup_dir;
- else
+ if(params->recup_dir==NULL)
{
+ char *res;
res=ask_location("Please select a destination to save the recovered files.\nDo not choose to write the files to the same partition they were stored on.", "", NULL);
if(res!=NULL)
{
- char *new_recup_dir=(char *)MALLOC(strlen(res)+1+strlen(DEFAULT_RECUP_DIR)+1);
- strcpy(new_recup_dir,res);
- strcat(new_recup_dir,"/");
- strcat(new_recup_dir,DEFAULT_RECUP_DIR);
- if(res!=recup_dir)
- free(res);
- res=new_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);
}
}
- if(res!=NULL)
+ if(params->recup_dir!=NULL)
{
if(td_list_empty(&list_search_space->list))
{
- init_search_space(list_search_space, disk_car, partition);
+ init_search_space(list_search_space, params->disk, params->partition);
}
if(carve_free_space_only>0)
{
@@ -424,42 +414,40 @@ void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *rec
wmove(stdscr,5,0);
wprintw(stdscr, "Filesystem analysis, please wait...\n");
wrefresh(stdscr);
- blocksize=remove_used_space(disk_car, partition, list_search_space);
+ params->blocksize=remove_used_space(params->disk, params->partition, list_search_space);
/* Only free space is carved, list_search_space is modified.
- * To carve the whole space, need to quit and reselect the partition */
+ * To carve the whole space, need to quit and reselect the params->partition */
done = 1;
}
- photorec(disk_car, partition, options, res, 1, file_enable, current_cmd, list_search_space, blocksize, carve_free_space_only);
+ photorec(params, options, list_search_space, carve_free_space_only);
}
- if(res!=recup_dir)
- free(res);
}
break;
case 'o':
case 'O':
{
const int old_allow_partial_last_cylinder=options->allow_partial_last_cylinder;
- interface_options_photorec(options, current_cmd);
+ interface_options_photorec(options, &params->cmd_run);
if(old_allow_partial_last_cylinder!=options->allow_partial_last_cylinder)
- hd_update_geometry(disk_car, options->allow_partial_last_cylinder, options->verbose);
+ hd_update_geometry(params->disk, options->allow_partial_last_cylinder, options->verbose);
menu=1;
}
break;
case 'f':
case 'F':
- interface_file_select(file_enable, current_cmd);
+ interface_file_select(options->list_file_format, &params->cmd_run);
menu=2;
break;
case 'g':
case 'G':
if(options->expert!=0)
- change_geometry(disk_car, current_cmd);
+ change_geometry(params->disk, &params->cmd_run);
break;
case 'a':
case 'A':
- if(disk_car->arch != &arch_none)
+ if(params->disk->arch != &arch_none)
{
- list_part=add_partition(disk_car, list_part, current_cmd);
+ list_part=add_partition(params->disk, list_part, &params->cmd_run);
current_element=list_part;
current_element_num=0;
}
diff --git a/src/ppartsel.h b/src/ppartsel.h
index 956e95e..52d2510 100644
--- a/src/ppartsel.h
+++ b/src/ppartsel.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-void menu_photorec(disk_t *disk_car, struct ph_options *options, const char *recup_dir, file_enable_t *file_enable, char **current_cmd, alloc_data_t*list_search_space);
+void menu_photorec(struct ph_param *params, struct ph_options *options, alloc_data_t*list_search_space);
#ifdef __cplusplus
} /* closing brace for extern "C" */
diff --git a/src/sessionp.c b/src/sessionp.c
index bbf8836..1d792eb 100644
--- a/src/sessionp.c
+++ b/src/sessionp.c
@@ -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, NULL, 0, NULL, 0);
+ session_save(NULL, NULL, NULL, 0);
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, disk_t *disk, const partition_t *partition, const file_enable_t *files_enable, const unsigned int blocksize, 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, const unsigned int carve_free_space_only)
{
FILE *f_session;
f_session=fopen(SESSION_FILENAME,"wb");
@@ -167,16 +167,17 @@ int session_save(alloc_data_t *list_free_space, disk_t *disk, const partition_t
log_critical("Can't create photorec.ses file: %s\n",strerror(errno));
return -1;
}
- if(disk!=NULL)
+ if(params!=NULL)
{
struct td_list_head *free_walker = NULL;
unsigned int i;
+ const file_enable_t *files_enable=options->list_file_format;
if(options->verbose>1)
{
log_trace("session_save\n");
}
fprintf(f_session,"#%u\n%s %s,%u,blocksize,%u,fileopt,",
- (unsigned int)time(NULL), disk->device, disk->arch->part_name_option, partition->order, blocksize);
+ (unsigned int)time(NULL), params->disk->device, params->disk->arch->part_name_option, params->partition->order, params->blocksize);
for(i=0;files_enable[i].file_hint!=NULL;i++)
{
if(files_enable[i].file_hint->extension!=NULL && files_enable[i].file_hint->extension[0]!='\0')
@@ -214,8 +215,8 @@ int session_save(alloc_data_t *list_free_space, disk_t *disk, const partition_t
alloc_data_t *current_free_space;
current_free_space=td_list_entry(free_walker, alloc_data_t, list);
fprintf(f_session,"%llu-%llu\n",
- (long long unsigned)(current_free_space->start/disk->sector_size),
- (long long unsigned)(current_free_space->end/disk->sector_size));
+ (long long unsigned)(current_free_space->start/params->disk->sector_size),
+ (long long unsigned)(current_free_space->end/params->disk->sector_size));
}
}
{ /* Reserve some space */
diff --git a/src/sessionp.h b/src/sessionp.h
index 82d9007..ce06b4f 100644
--- a/src/sessionp.h
+++ b/src/sessionp.h
@@ -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, disk_t *disk, const partition_t *partition, const file_enable_t *files_enable, const unsigned int blocksize, 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, const unsigned int carve_free_space_only);
#ifdef __cplusplus
} /* closing brace for extern "C" */