Make FAT RebuildBS works when there is a single FAT table

This commit is contained in:
Christophe Grenier 2012-01-07 11:42:10 +01:00
parent d741d15777
commit 106fb14319
4 changed files with 22 additions and 13 deletions

View file

@ -1831,7 +1831,11 @@ static upart_type_t select_fat_info(const info_offset_t *info_offset, const unsi
{
wmove(stdscr,INTER_FAT_ASK_Y, INTER_FAT_ASK_X);
fat2_location=ask_number(fat2_location,0,max_sector_offset,"FAT2 location ");
if(fat2_location>*reserved)
if(fat2_location == *reserved)
{
*fats=1;
}
else if(fat2_location > *reserved)
{
*fat_length=fat2_location-*reserved;
wmove(stdscr,INTER_FAT_ASK_Y, INTER_FAT_ASK_X);
@ -2016,7 +2020,7 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
(fat_length==0)||(reserved==0))
{
uint64_t start_data=0;
if(find_sectors_per_cluster(disk_car, partition, verbose, dump_ind, interface,&sectors_per_cluster,&start_data)==0)
if(find_sectors_per_cluster(disk_car, partition, verbose, dump_ind, interface, &sectors_per_cluster, &start_data, upart_type)==0)
{
display_message("Can't find cluster size\n");
return 0;
@ -2064,9 +2068,12 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
fat_length=(start_data-reserved-((dir_entries-1)/16+1))/fats;
break;
case UP_FAT32:
reserved=32;
if((start_data&1)!=0)
reserved+=1;
if(reserved==0)
{
reserved=32;
if((start_data&1)!=0)
reserved+=1;
}
fat_length=(start_data-reserved)/fats;
break;
default: /* No compiler warning */

View file

@ -40,7 +40,7 @@
/* Using a couple of inodes of "." directory entries, get the cluster size and where the first cluster begins.
* */
int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset_org)
int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset_org, const upart_type_t upart_type)
{
unsigned int nbr_subdir=0;
sector_cluster_t sector_cluster[10];
@ -96,10 +96,10 @@ int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int
}
}
free(buffer);
return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk_car->sector_size);
return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk_car->sector_size, upart_type);
}
int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors)
int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors, const upart_type_t upart_type)
{
cluster_offset_t *cluster_offset;
unsigned int i,j;
@ -162,13 +162,14 @@ int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const u
unsigned int nbr_max=0;
for(i=0;i<nbr_sol;i++)
{
const upart_type_t upart_type_new=no_of_cluster2part_type((part_size_in_sectors-cluster_offset[i].offset)/cluster_offset[i].sectors_per_cluster);
if(verbose>0)
{
log_verbose("sectors_per_cluster=%u offset=%lu nbr=%u ",
cluster_offset[i].sectors_per_cluster,
cluster_offset[i].offset,
cluster_offset[i].nbr);
switch(no_of_cluster2part_type((part_size_in_sectors-cluster_offset[i].offset)/cluster_offset[i].sectors_per_cluster))
switch(upart_type_new)
{
case UP_FAT12:
log_info("FAT : 12\n");
@ -183,7 +184,8 @@ int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const u
break;
}
}
if(cluster_offset[i].nbr>nbr_max)
if((upart_type==UP_UNK || upart_type==upart_type_new) &&
cluster_offset[i].nbr>nbr_max)
{
nbr_max=cluster_offset[i].nbr;
*sectors_per_cluster=cluster_offset[i].sectors_per_cluster;

View file

@ -42,9 +42,9 @@ struct cluster_offset_struct
unsigned int first_sol;
};
int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset);
int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset, const upart_type_t upart_type);
upart_type_t no_of_cluster2part_type(const unsigned long int no_of_cluster);
int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors);
int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors, const upart_type_t upart_type);
#ifdef __cplusplus
} /* closing brace for extern "c" */

View file

@ -115,7 +115,7 @@ static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const
}
} /* end while(current_search_space!=list_search_space) */
free(buffer_start);
return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk->sector_size);
return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk->sector_size, UP_UNK);
}
static int fat_copy_file(disk_t *disk, const partition_t *partition, const unsigned int block_size, const uint64_t start_data, const char *recup_dir, const unsigned int dir_num, const file_data_t *file)