summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-12-08 14:40:15 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2013-12-08 14:40:15 +0100
commitccc47d5bf2c28e40857912b7c65e3f97415ebe7a (patch)
tree1af42226034ee2f6fca5554f6759b826b3d9e232 /src
parent1398b863c2a47d2da492e8a66995e65cc3aded75 (diff)
fat32_get_free_count() and fat32_get_next_free() - code style
Diffstat (limited to 'src')
-rw-r--r--src/fat.c6
-rw-r--r--src/fat.h10
2 files changed, 14 insertions, 2 deletions
diff --git a/src/fat.c b/src/fat.c
index aea5407..c64cfb6 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -747,12 +747,14 @@ int comp_FAT(disk_t *disk, const partition_t *partition, const unsigned long int
unsigned long int fat32_get_free_count(const unsigned char *boot_fat32, const unsigned int sector_size)
{
- return (boot_fat32[sector_size+0x1E8+3]<<24)+(boot_fat32[sector_size+0x1E8+2]<<16)+(boot_fat32[sector_size+0x1E8+1]<<8)+boot_fat32[sector_size+0x1E8];
+ const struct fat_fsinfo *fsinfo=(const struct fat_fsinfo *)&boot_fat32[sector_size];
+ return le32(fsinfo->freecnt);
}
unsigned long int fat32_get_next_free(const unsigned char *boot_fat32, const unsigned int sector_size)
{
- return (boot_fat32[sector_size+0x1EC+3]<<24)+(boot_fat32[sector_size+0x1EC+2]<<16)+(boot_fat32[sector_size+0x1EC+1]<<8)+boot_fat32[sector_size+0x1EC];
+ const struct fat_fsinfo *fsinfo=(const struct fat_fsinfo *)&boot_fat32[sector_size];
+ return le32(fsinfo->nextfree);
}
int recover_FAT(disk_t *disk_car, const struct fat_boot_sector*fat_header, partition_t *partition, const int verbose, const int dump_ind, const int backup)
diff --git a/src/fat.h b/src/fat.h
index 935e991..f15d668 100644
--- a/src/fat.h
+++ b/src/fat.h
@@ -75,6 +75,16 @@ struct fat_boot_sector {
uint16_t marker;
} __attribute__ ((__packed__));
+struct fat_fsinfo {
+ uint32_t leadsig; /* 0x41615252 */
+ uint8_t reserved1[480];
+ uint32_t strucsig; /* 0x61417272 */
+ uint32_t freecnt; /* free clusters 0xfffffffff if unknown */
+ uint32_t nextfree; /* next free cluster */
+ uint8_t reserved3[12];
+ uint32_t magic3; /* 0xAA550000 */
+} __attribute__ ((__packed__));
+
struct msdos_dir_entry {
int8_t name[8],ext[3]; /* 00 name and extension */
uint8_t attr; /* 0B attribute bits */