From 150724593bd7f5cfdb435be356498d2ce7921ac7 Mon Sep 17 00:00:00 2001 From: poeggi <48416618+poeggi@users.noreply.github.com> Date: Fri, 8 May 2026 11:28:45 +0200 Subject: [PATCH] PhotoRec: add sector skip (+5%) and progress percentage - Press '+' during scan to skip ahead 5% of partition sectors, with confirmation prompt and log entry for the skipped range - Progress bar now shows completion percentage next to sector count --- src/phnc.c | 12 +++++++++--- src/photorec.h | 2 +- src/psearchn.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/phnc.c b/src/phnc.c index 0b7b9f6c..c452f569 100644 --- a/src/phnc.c +++ b/src/phnc.c @@ -98,10 +98,12 @@ pstatus_t photorec_progressbar(WINDOW *window, const unsigned int pass, const st } else { - wprintw(window,"Pass %u - Reading sector %10llu/%llu, ", + wprintw(window,"Pass %u - Reading sector %10llu/%llu (%llu.%llu%%), ", pass, (unsigned long long)((offset-partition->part_offset)/sector_size), - (unsigned long long)(partition->part_size/sector_size)); + (unsigned long long)(partition->part_size/sector_size), + (unsigned long long)((offset-partition->part_offset)*100/partition->part_size), + (unsigned long long)((offset-partition->part_offset)*1000/partition->part_size%10)); } if(params->status==STATUS_FIND_OFFSET) wprintw(window,"%u/10 headers found\n", params->file_nbr); @@ -130,6 +132,10 @@ pstatus_t photorec_progressbar(WINDOW *window, const unsigned int pass, const st json_log_progress(params, pass, offset); wrefresh(window); - return(check_enter_key_or_s(window)==0?PSTATUS_OK:PSTATUS_STOP); + { + const int key=check_enter_key_or_s(window); + if(key==3) return PSTATUS_SKIP; + return (key==0?PSTATUS_OK:PSTATUS_STOP); + } } #endif diff --git a/src/photorec.h b/src/photorec.h index 59f9dfd8..cf6fa961 100644 --- a/src/photorec.h +++ b/src/photorec.h @@ -31,7 +31,7 @@ extern "C" { enum photorec_status { STATUS_FIND_OFFSET, STATUS_UNFORMAT, STATUS_EXT2_ON, STATUS_EXT2_ON_BF, STATUS_EXT2_OFF, STATUS_EXT2_OFF_BF, STATUS_EXT2_ON_SAVE_EVERYTHING, STATUS_EXT2_OFF_SAVE_EVERYTHING, STATUS_QUIT }; typedef enum photorec_status photorec_status_t; -typedef enum { PSTATUS_OK=0, PSTATUS_STOP=1, PSTATUS_EACCES=2, PSTATUS_ENOSPC=3} pstatus_t; +typedef enum { PSTATUS_OK=0, PSTATUS_STOP=1, PSTATUS_EACCES=2, PSTATUS_ENOSPC=3, PSTATUS_SKIP=4} pstatus_t; typedef enum { PFSTATUS_BAD=0, PFSTATUS_OK=1, PFSTATUS_OK_TRUNCATED=2} pfstatus_t; struct ph_options diff --git a/src/psearchn.c b/src/psearchn.c index 3aa74dd9..cd4c053c 100644 --- a/src/psearchn.c +++ b/src/psearchn.c @@ -354,6 +354,49 @@ pstatus_t photorec_aux(struct ph_param *params, const struct ph_options *options #endif json_log_progress(params, params->pass, offset); params->offset=offset; + if(ind_stop==PSTATUS_SKIP) + { + const uint64_t skip_bytes=params->partition->part_size/20; + const uint64_t target=offset+skip_bytes; + const uint64_t sector_size=params->disk->sector_size; +#ifdef HAVE_NCURSES + if(ask_confirmation("Skip ahead 5%% from sector %llu to ~%llu? (Y/N)", + (unsigned long long)((offset-params->partition->part_offset)/sector_size), + (unsigned long long)((target-params->partition->part_offset)/sector_size))==0) + { + ind_stop=PSTATUS_OK; + } + else +#endif + { + alloc_data_t *sp; + const uint64_t from_sector=(offset-params->partition->part_offset)/sector_size; + current_search_space=list_search_space; + td_list_for_each_entry(sp, &list_search_space->list, list) + { + if(sp->end>=target) + { + const uint64_t aligned=(target/blocksize)*blocksize; + current_search_space=sp; + offset=(aligned>=sp->start)?aligned:sp->start; + break; + } + } + log_info("User skipped from sector %llu to sector %llu\n", + (unsigned long long)from_sector, + (unsigned long long)((offset-params->partition->part_offset)/sector_size)); + file_recovery_aborted(&file_recovery, params, list_search_space); + reset_file_recovery(&file_recovery); + file_recovery.blocksize=blocksize; + back=0; + memset(buffer_start,0,blocksize); + buffer_olddata=buffer_start; + buffer=buffer_olddata+blocksize; + params->disk->pread(params->disk, buffer, READ_SIZE, offset); + params->offset=offset; + ind_stop=PSTATUS_OK; + } + } if(need_to_stop!=0 || ind_stop!=PSTATUS_OK) { #ifndef DISABLED_FOR_FRAMAC