diff --git a/src/fat.c b/src/fat.c index aea54079..c64cfb61 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 935e9916..f15d6684 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 */