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

Function photorec_bf_pad

src/phbf.c:322–446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320}
321
322static bf_status_t 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)
323{
324 const unsigned int blocksize=params->blocksize;
325 { /* Add remaining data blocs */
326 unsigned int nbr;
327 uint64_t offset_error_tmp;
328 file_recovery->offset_error=file_offset;
329 do
330 {
331 uint64_t file_size_backup;
332 nbr=0;
333 offset_error_tmp=file_recovery->offset_error;
334 if(my_fseek(file_recovery->handle, file_recovery->file_size, SEEK_SET) < 0)
335 return BF_ENOENT;
336#if 1
337 if(file_recovery->data_check!=NULL)
338 {
339 int stop=0;
340 memset(buffer, 0, blocksize);
341 while(*current_search_space != list_search_space &&
342 stop==0 &&
343 file_recovery->file_size < file_recovery->offset_error+1000*blocksize)
344 {
345 if(
346 ((*current_search_space)->start!=*offset && phase!=1) ||
347 (*current_search_space)->file_stat==NULL ||
348 (*current_search_space)->file_stat->file_hint==NULL)
349 {
350 params->disk->pread(params->disk, block_buffer, blocksize, *offset);
351 if(file_recovery->data_check(buffer, 2*blocksize, file_recovery)!=DC_CONTINUE)
352 {
353 stop=1;
354 }
355 if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
356 {
357 log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
358 fclose(file_recovery->handle);
359 file_recovery->handle=NULL;
360 return BF_ENOSPC;
361 }
362 file_block_append(file_recovery, list_search_space, current_search_space, offset, blocksize, 1);
363 file_recovery->file_size+=blocksize;
364 nbr++;
365 memcpy(buffer, block_buffer, blocksize);
366 }
367 else
368 get_next_sector(list_search_space, current_search_space, offset, blocksize);
369 }
370 }
371 else
372#endif
373 {
374 while(*current_search_space != list_search_space &&
375 file_recovery->file_size < file_recovery->offset_error+100*blocksize)
376 {
377 if((*current_search_space)->start!=*offset ||
378 (*current_search_space)->file_stat==NULL ||
379 (*current_search_space)->file_stat->file_hint==NULL)

Callers 2

photorec_bf_frag_fastFunction · 0.85
photorec_bf_fragFunction · 0.85

Calls 5

my_fseekFunction · 0.85
file_block_appendFunction · 0.85
get_next_sectorFunction · 0.85
file_block_logFunction · 0.85
file_finish_bfFunction · 0.85

Tested by

no test coverage detected