MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / pfind_sectors_per_cluster

Function pfind_sectors_per_cluster

src/fat_unformat.c:62–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61#define READ_SIZE 4*1024*1024
62static int pfind_sectors_per_cluster(disk_t *disk, const partition_t *partition, const int verbose, unsigned int *sectors_per_cluster, uint64_t *offset_org, alloc_data_t *list_search_space)
63{
64 uint64_t offset=0;
65 uint64_t next_offset=0;
66 uint64_t diff_offset=0;
67 time_t previous_time=0;
68 unsigned int nbr_subdir=0;
69 sector_cluster_t sector_cluster[10];
70 alloc_data_t *current_search_space;
71 unsigned char *buffer_start=(unsigned char *)MALLOC(READ_SIZE);
72 unsigned char *buffer=buffer_start;
73 assert(disk->sector_size!=0);
74 current_search_space=td_list_first_entry(&list_search_space->list, alloc_data_t, list);
75 if(current_search_space!=list_search_space)
76 offset=current_search_space->start;
77 if(verbose>0)
78 info_list_search_space(list_search_space, current_search_space, disk->sector_size, 0, verbose);
79#ifdef HAVE_NCURSES
80 wmove(stdscr,22,0);
81 wattrset(stdscr, A_REVERSE);
82 waddstr(stdscr," Stop ");
83 wattroff(stdscr, A_REVERSE);
84#endif
85 disk->pread(disk, buffer_start, READ_SIZE, offset);
86 while(current_search_space!=list_search_space && nbr_subdir<10)
87 {
88 const uint64_t old_offset=offset;
89 if(buffer[0]=='.' && is_fat_directory(buffer))
90 {
91 const unsigned long int cluster=fat_get_cluster_from_entry((const struct msdos_dir_entry *)buffer);
92 log_info("sector %lu, cluster %lu\n",
93 (unsigned long)(offset/disk->sector_size), cluster);
94 sector_cluster[nbr_subdir].cluster=cluster;
95 sector_cluster[nbr_subdir].sector=offset/disk->sector_size;
96 log_flush();
97 nbr_subdir++;
98 }
99 get_next_sector(list_search_space, &current_search_space, &offset, 512);
100 buffer+=512;
101 if( old_offset+512!=offset ||
102 buffer+512>buffer_start+READ_SIZE)
103 {
104 buffer=buffer_start;
105#ifdef HAVE_NCURSES
106 if(offset > next_offset)
107 {
108 const time_t current_time=time(NULL);
109 if(current_time==previous_time)
110 diff_offset<<=1;
111 else
112 diff_offset>>=1;
113 if(diff_offset < disk->sector_size)
114 diff_offset=disk->sector_size;
115 next_offset=offset+diff_offset;
116 previous_time=current_time;
117 wmove(stdscr,9,0);
118 wclrtoeol(stdscr);
119 wprintw(stdscr,"Search subdirectory %10lu/%lu %u",(unsigned long)(offset/disk->sector_size),(unsigned long)(partition->part_size/disk->sector_size),nbr_subdir);

Callers 1

fat_unformatFunction · 0.85

Calls 7

MALLOCFunction · 0.85
info_list_search_spaceFunction · 0.85
is_fat_directoryFunction · 0.85
log_flushFunction · 0.85
get_next_sectorFunction · 0.85

Tested by

no test coverage detected