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

Function find_dir_entries

src/fat_adv.c:700–753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

698#endif
699
700static int find_dir_entries(disk_t *disk_car,const partition_t *partition, const unsigned int offset,const int verbose)
701{
702 uint64_t hd_offset;
703 unsigned int i;
704 int dir_entry_found=0;
705 unsigned char *buffer=(unsigned char *)MALLOC(disk_car->sector_size);
706 for(i=0, hd_offset=partition->part_offset+(uint64_t)offset*disk_car->sector_size;
707 i<200 && i<offset;
708 i++, hd_offset-=disk_car->sector_size)
709 {
710 if((unsigned)disk_car->pread(disk_car, buffer, disk_car->sector_size, hd_offset) != disk_car->sector_size)
711 {
712 log_error("dir_entries: read error, dir_entries>=%u (%u sectors)\n",i*(disk_car->sector_size/32),i);
713 }
714 else
715 {
716 unsigned int j;
717 /* A directory entry is 32 bytes long *
718 * Entries has allocated by whole sector */
719 for(j=disk_car->sector_size/32-1;j>0;j--)
720 {
721 if(verbose>1)
722 {
723 log_verbose("find_dir_entries sector=%u entry=%u dir_entry_found=%d\n",
724 offset-i, j, dir_entry_found);
725 }
726 if(dir_entry_found==0)
727 { /* Should be between the last directory entries and the first cluster */
728 switch(check_FAT_dir_entry(&buffer[j*32],j))
729 {
730 case 0: /* Empty entry */
731 break;
732 case 1: /* Non empty entry */
733 dir_entry_found=1;
734 break;
735 case 2: /* Failed */
736 free(buffer);
737 return 0;
738 }
739 }
740 else
741 {
742 if(check_FAT_dir_entry(&buffer[j*32],j)!=1)
743 { /* Must be in the FAT table */
744 free(buffer);
745 return (i-1)*(disk_car->sector_size/32);
746 }
747 }
748 }
749 }
750 }
751 free(buffer);
752 return 0;
753}
754
755static int analyse_dir_entries(disk_t *disk_car,const partition_t *partition, const unsigned int offset,const int verbose)
756{

Callers 1

rebuild_FAT_BSFunction · 0.85

Calls 2

MALLOCFunction · 0.85
check_FAT_dir_entryFunction · 0.85

Tested by

no test coverage detected