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

Function exfat_dir

src/exfat_dir.c:295–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293
294#define NBR_CLUSTER_MAX 30
295static int exfat_dir(disk_t *disk, const partition_t *partition, dir_data_t *dir_data, const unsigned long int first_cluster, file_info_t *dir_list)
296{
297 const struct exfat_dir_struct *ls=(const struct exfat_dir_struct*)dir_data->private_dir_data;
298 const struct exfat_super_block*exfat_header=ls->boot_sector;
299 const unsigned int cluster_shift=exfat_header->block_per_clus_bits + exfat_header->blocksize_bits;
300 unsigned int cluster;
301 unsigned char *buffer_dir=(unsigned char *)MALLOC(NBR_CLUSTER_MAX << cluster_shift);
302 unsigned int nbr_cluster;
303 const unsigned int total_clusters=le32(exfat_header->total_clusters);
304 exfat_method_t exfat_meth=exFAT_FOLLOW_CLUSTER;
305 int stop=0;
306 const uint64_t start_exfat1=(uint64_t)le32(exfat_header->fat_blocknr) << exfat_header->blocksize_bits;
307 if(first_cluster<2)
308 cluster=le32(exfat_header->rootdir_clusnr);
309 else
310 cluster=first_cluster;
311 memset(buffer_dir, 0, NBR_CLUSTER_MAX<<cluster_shift);
312 nbr_cluster=0;
313 while(!is_EOC(cluster) && cluster>=2 && nbr_cluster<NBR_CLUSTER_MAX && stop==0)
314 {
315 if(exfat_read_cluster(disk, partition, exfat_header, buffer_dir + ((uint64_t) nbr_cluster << cluster_shift), cluster) != (1<<cluster_shift))
316 {
317 log_error("exFAT: Can't read directory cluster.\n");
318 stop=1;
319 }
320 if(stop==0)
321 {
322 if(exfat_meth==exFAT_FOLLOW_CLUSTER)
323 {
324 const unsigned int next_cluster=exfat_get_next_cluster(disk, partition, start_exfat1, cluster);
325 if((next_cluster>=2 && next_cluster<=total_clusters) ||
326 is_EOC(next_cluster))
327 cluster=next_cluster;
328 else if(next_cluster==0)
329 {
330#if 0
331 /* FIXME: experimental */
332 if(cluster==first_cluster && (dir_data->param & FLAG_LIST_DELETED)==FLAG_LIST_DELETED)
333 exfat_meth=exFAT_NEXT_FREE_CLUSTER; /* Recovery of a deleted directory */
334 else
335 cluster=0; /* Stop directory listing */
336#else
337 cluster=0; /* Stop directory listing */
338#endif
339 }
340 else
341 exfat_meth=exFAT_NEXT_CLUSTER; /* exFAT is corrupted, don't trust it */
342 }
343 if(exfat_meth==exFAT_NEXT_CLUSTER)
344 cluster++;
345 else if(exfat_meth==exFAT_NEXT_FREE_CLUSTER)
346 { /* Deleted directories are composed of "free" clusters */
347#if 0
348 while(++cluster<total_clusters &&
349 exfat_get_next_cluster(disk, partition, start_exfat1, cluster)!=0);
350#endif
351 }
352 nbr_cluster++;

Callers

nothing calls this directly

Calls 5

MALLOCFunction · 0.85
exfat_read_clusterFunction · 0.85
exfat_get_next_clusterFunction · 0.85
dir_exfat_auxFunction · 0.85
is_EOCFunction · 0.70

Tested by

no test coverage detected