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

Function comp_FAT

src/fat.c:883–939  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

881}
882
883int comp_FAT(disk_t *disk, const partition_t *partition, const unsigned long int fat_size, const unsigned long int sect_res)
884{
885 /*
886 return 0 if FATs match
887 */
888 unsigned int reste;
889 uint64_t hd_offset;
890 uint64_t hd_offset2;
891 unsigned char *buffer;
892 unsigned char *buffer2;
893 buffer=(unsigned char *)MALLOC(16*disk->sector_size);
894 buffer2=(unsigned char *)MALLOC(16*disk->sector_size);
895 hd_offset=partition->part_offset+(uint64_t)sect_res*disk->sector_size;
896 hd_offset2=hd_offset+(uint64_t)fat_size*disk->sector_size;
897 reste=(fat_size>1000?1000:fat_size); /* Quick check ! */
898 reste*=disk->sector_size;
899 while(reste>0)
900 {
901 const unsigned int read_size=(reste > 16 * disk->sector_size ? 16 * disk->sector_size :reste);
902 reste-=read_size;
903 if((unsigned)disk->pread(disk, buffer, read_size, hd_offset) != read_size)
904 {
905#ifndef DISABLED_FOR_FRAMAC
906 log_error("comp_FAT: can't read FAT1\n");
907#endif
908 free(buffer2);
909 free(buffer);
910 return 1;
911 }
912 if((unsigned)disk->pread(disk, buffer2, read_size, hd_offset2) != read_size)
913 {
914#ifndef DISABLED_FOR_FRAMAC
915 log_error("comp_FAT: can't read FAT2\n");
916#endif
917 free(buffer2);
918 free(buffer);
919 return 1;
920 }
921 if(memcmp(buffer, buffer2, read_size)!=0)
922 {
923#ifndef DISABLED_FOR_FRAMAC
924 log_error("FAT differs, FAT sectors=%lu-%lu/%lu\n",
925 (unsigned long) ((hd_offset-partition->part_offset)/disk->sector_size-sect_res),
926 (unsigned long) ((hd_offset-partition->part_offset+read_size)/disk->sector_size-sect_res),
927 fat_size);
928#endif
929 free(buffer2);
930 free(buffer);
931 return 1;
932 }
933 hd_offset+=read_size;
934 hd_offset2+=read_size;
935 }
936 free(buffer2);
937 free(buffer);
938 return 0;
939}
940

Callers 2

fat_find_infoFunction · 0.85
test_FATFunction · 0.85

Calls 1

MALLOCFunction · 0.85

Tested by 1

test_FATFunction · 0.68