summaryrefslogtreecommitdiffstats
path: root/src/exfat.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2011-01-07 20:52:33 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2011-01-07 20:52:33 +0100
commit2c4b6dcbb956f43b07ecb0d1f6ab661c934693bc (patch)
treef07d624b136400bb6b0336af74ee548089655ed4 /src/exfat.c
parent26f724eacd72e64f48db2aa6dda6718b6c446a6b (diff)
Fix exFAT recovery using backup boot sector
Diffstat (limited to 'src/exfat.c')
-rw-r--r--src/exfat.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/exfat.c b/src/exfat.c
index 02a11c2..f0611c9 100644
--- a/src/exfat.c
+++ b/src/exfat.c
@@ -33,20 +33,21 @@
#include "types.h"
#include "common.h"
#include "exfat.h"
-static int test_EXFAT(const struct exfat_super_block *exfat_header, partition_t *partition);
-#define EXFAT_SIZE 512
static int set_EXFAT_info(partition_t *partition)
{
partition->fsname[0]='\0';
- strncpy(partition->info,"EXFAT",sizeof(partition->info));
+ if(partition->sb_offset==0)
+ strncpy(partition->info,"exFAT",sizeof(partition->info));
+ else
+ strncpy(partition->info,"exFAT found using backup sector!",sizeof(partition->info));
return 0;
}
int check_EXFAT(disk_t *disk_car, partition_t *partition)
{
- unsigned char *buffer=(unsigned char*)MALLOC(EXFAT_SIZE);
- if(disk_car->pread(disk_car, buffer, EXFAT_SIZE, partition->part_offset) != EXFAT_SIZE)
+ unsigned char *buffer=(unsigned char*)MALLOC(EXFAT_BS_SIZE);
+ if(disk_car->pread(disk_car, buffer, EXFAT_BS_SIZE, partition->part_offset) != EXFAT_BS_SIZE)
{
free(buffer);
return 1;
@@ -61,7 +62,7 @@ int check_EXFAT(disk_t *disk_car, partition_t *partition)
return 0;
}
-static int test_EXFAT(const struct exfat_super_block *exfat_header, partition_t *partition)
+int test_EXFAT(const struct exfat_super_block *exfat_header, partition_t *partition)
{
if(le16(exfat_header->signature)!=0xAA55)
return 1;
@@ -75,9 +76,17 @@ int recover_EXFAT(const disk_t *disk, const struct exfat_super_block *exfat_head
{
if(test_EXFAT(exfat_header, partition)!=0)
return 1;
- set_EXFAT_info(partition);
+ partition->sborg_offset=0;
+ partition->sb_size=12 << exfat_header->blocksize_bits;
partition->part_type_i386=P_EXFAT;
partition->part_type_gpt=GPT_ENT_TYPE_MS_BASIC_DATA;
partition->part_size=(uint64_t)le64(exfat_header->nr_sectors) * disk->sector_size;
+ if(le64(exfat_header->start_sector) +
+ (12 << exfat_header->blocksize_bits) == partition->part_offset)
+ {
+ partition->sb_offset=12 << exfat_header->blocksize_bits;
+ partition->part_offset-=partition->sb_offset;
+ }
+ set_EXFAT_info(partition);
return 0;
}