| 2219 | } |
| 2220 | |
| 2221 | int FAT_init_rootdir(disk_t *disk_car, partition_t *partition, const int verbose, char **current_cmd) |
| 2222 | { |
| 2223 | unsigned long int fat_length,sector; |
| 2224 | uint64_t start_rootdir,start_data; |
| 2225 | unsigned int error=0; |
| 2226 | struct fat_boot_sector *fat_header; |
| 2227 | unsigned char *buffer; |
| 2228 | if(partition->upart_type!=UP_FAT12 && partition->upart_type!=UP_FAT16) |
| 2229 | return 1; |
| 2230 | if(check_FAT(disk_car,partition,verbose)!=0) |
| 2231 | { |
| 2232 | display_message("Boot sector not valid, can't check FAT.\n"); |
| 2233 | return 1; |
| 2234 | } |
| 2235 | buffer=(unsigned char *)MALLOC(disk_car->sector_size); |
| 2236 | fat_header=(struct fat_boot_sector *)buffer; |
| 2237 | if((unsigned)disk_car->pread(disk_car, buffer, disk_car->sector_size, partition->part_offset) != disk_car->sector_size) |
| 2238 | { |
| 2239 | display_message("FAT_init_rootdir: Can't read boot sector\n"); |
| 2240 | free(buffer); |
| 2241 | return 1; |
| 2242 | } |
| 2243 | fat_length=le16(fat_header->fat_length)>0?le16(fat_header->fat_length):le32(fat_header->fat32_length); |
| 2244 | start_rootdir=le16(fat_header->reserved)+ fat_header->fats*fat_length; |
| 2245 | start_data=start_rootdir+(get_dir_entries(fat_header)*32+disk_car->sector_size-1)/disk_car->sector_size; |
| 2246 | for(sector=start_rootdir;error==0 && sector<start_data;sector++) |
| 2247 | { |
| 2248 | if((unsigned)disk_car->pread(disk_car, buffer, disk_car->sector_size, |
| 2249 | partition->part_offset + (uint64_t)sector * disk_car->sector_size) != disk_car->sector_size) |
| 2250 | { |
| 2251 | log_error("FAT_init_rootdir: read error at sector %lu\n", sector); |
| 2252 | } |
| 2253 | else |
| 2254 | { |
| 2255 | unsigned int i; |
| 2256 | for(i=0;error==0 && (i<disk_car->sector_size/0x20);i++) |
| 2257 | { |
| 2258 | if(check_FAT_dir_entry(&buffer[i*0x20],i)==2) |
| 2259 | { |
| 2260 | error=1; |
| 2261 | } |
| 2262 | } |
| 2263 | } |
| 2264 | } |
| 2265 | if(error==0) |
| 2266 | { |
| 2267 | if(*current_cmd!=NULL) |
| 2268 | log_info("TestDisk doesn't seem needed to reset the root directory.\n"); |
| 2269 | else |
| 2270 | display_message("TestDisk doesn't seem needed to reset the root directory.\n"); |
| 2271 | free(buffer); |
| 2272 | return 0; |
| 2273 | } |
| 2274 | #ifdef HAVE_NCURSES |
| 2275 | if(ask_confirmation("Initialize FAT root directory, confirm ? (Y/N)")!=0) |
| 2276 | { |
| 2277 | int err=0; |
| 2278 | log_info("Initialize FAT root directory\n"); |
no test coverage detected