| 204 | } |
| 205 | |
| 206 | unsigned int fat_remove_used_space(disk_t *disk_car, const partition_t *partition, alloc_data_t *list_search_space) |
| 207 | { |
| 208 | unsigned long int fat_length; |
| 209 | unsigned long int start_fat1; |
| 210 | unsigned long int part_size; |
| 211 | unsigned int no_of_cluster; |
| 212 | unsigned int start_data; |
| 213 | unsigned char *buffer; |
| 214 | unsigned int res; |
| 215 | unsigned int sector_size; |
| 216 | const struct fat_boot_sector *fat_header; |
| 217 | buffer=(unsigned char *)MALLOC(3*disk_car->sector_size); |
| 218 | fat_header=(const struct fat_boot_sector *)buffer; |
| 219 | if((unsigned)disk_car->pread(disk_car, buffer, 3 * disk_car->sector_size, partition->part_offset) != 3 * disk_car->sector_size) |
| 220 | { |
| 221 | free(buffer); |
| 222 | return 0; |
| 223 | } |
| 224 | sector_size=fat_sector_size(fat_header); |
| 225 | if(sector_size==0) |
| 226 | { |
| 227 | free(buffer); |
| 228 | return 0; |
| 229 | } |
| 230 | fat_length=le16(fat_header->fat_length)>0?le16(fat_header->fat_length):le32(fat_header->fat32_length); |
| 231 | part_size=(fat_sectors(fat_header)>0?fat_sectors(fat_header):le32(fat_header->total_sect)); |
| 232 | start_fat1=le16(fat_header->reserved); |
| 233 | start_data=start_fat1+fat_header->fats*fat_length+(get_dir_entries(fat_header)*32+sector_size-1)/sector_size; |
| 234 | no_of_cluster=(part_size-start_data)/fat_header->sectors_per_cluster; |
| 235 | if(partition->upart_type==UP_FAT12) |
| 236 | fat12_remove_used_space(disk_car,partition, list_search_space, start_fat1, no_of_cluster, start_data, fat_header->sectors_per_cluster,sector_size); |
| 237 | else if(partition->upart_type==UP_FAT16) |
| 238 | fat16_remove_used_space(disk_car,partition, list_search_space, start_fat1, no_of_cluster, start_data, fat_header->sectors_per_cluster,sector_size); |
| 239 | else if(partition->upart_type==UP_FAT32) |
| 240 | fat32_remove_used_space(disk_car,partition, list_search_space, start_fat1, no_of_cluster, start_data, fat_header->sectors_per_cluster,sector_size); |
| 241 | res=fat_header->sectors_per_cluster * sector_size; |
| 242 | free(buffer); |
| 243 | return res; |
| 244 | } |
no test coverage detected