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

Function rebuild_FAT_BS

src/fat_adv.c:1897–2219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1895#endif
1896
1897int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind, const unsigned int expert, char**current_cmd)
1898{
1899 unsigned long int max_offset;
1900 unsigned int fat_length=0;
1901 unsigned int sectors_per_cluster=0;
1902 unsigned int reserved=0;
1903 unsigned int dir_entries=0;
1904 unsigned int fats=2;
1905 int p_fat12,p_fat16,p_fat32;
1906 upart_type_t upart_type;
1907 /*
1908 * Using partition size, check if partition can be FAT12, FAT16 or FAT32
1909 * */
1910 if(partition->part_size>(uint64_t)(2*1024+1)*1024*1024)
1911 {
1912 p_fat32=1;
1913 p_fat16=0;
1914 p_fat12=0;
1915 }
1916 else
1917 /* 1<<12 clusters * 8 secteurs/clusters= 32768 secteurs
1918 fat_length=((1<<12+1)*1.5/DEFAULT_SECTOR_SIZE)+1=13; */
1919 if(partition->part_size>=(uint64_t)(1+2*13+32768+63)*512)
1920 {
1921 p_fat32=1;
1922 p_fat16=1;
1923 p_fat12=0;
1924 }
1925 else
1926 {
1927 p_fat32=0;
1928 p_fat16=1;
1929 p_fat12=1;
1930 }
1931#ifdef TESTING
1932 p_fat32=1; p_fat16=1; p_fat12=1;
1933#endif
1934 if(verbose)
1935 {
1936 log_info("\n");
1937 log_partition(disk_car,partition);
1938 log_info("rebuild_FAT_BS p_fat12 %d, p_fat16 %d, p_fat32 %d\n", p_fat12,p_fat16,p_fat32);
1939 }
1940 {
1941 /* Set fat_length_max */
1942 unsigned long int fat_length_max;
1943 unsigned int sectors_per_cluster_min=disk_car->sector_size;
1944 if(p_fat32)
1945 { /* Cluster 512 bytes */
1946 fat_length_max=partition->part_size/sectors_per_cluster_min*4;
1947 }
1948 else if(p_fat16)
1949 {
1950 while(partition->part_size/sectors_per_cluster_min > (1<<16))
1951 sectors_per_cluster_min*=2;
1952 fat_length_max=partition->part_size/sectors_per_cluster_min*2;
1953 }
1954 else

Callers 2

fat32_boot_sectorFunction · 0.85
fat1x_boot_sectorFunction · 0.85

Calls 15

log_partitionFunction · 0.85
aff_partFunction · 0.85
fat_find_infoFunction · 0.85
find_sectors_per_clusterFunction · 0.85
display_messageFunction · 0.85
no_of_cluster2part_typeFunction · 0.85
find_dir_entriesFunction · 0.85
analyse_dir_entriesFunction · 0.85
analyse_dir_entries2Function · 0.85
ask_numberFunction · 0.85
fat32_free_infoFunction · 0.85

Tested by

no test coverage detected