diff --git a/cores/esp32/FirmwareMSC.cpp b/cores/esp32/FirmwareMSC.cpp index e4703f96e2754c4069904d7ed71ccfd007e915f2..e869cbef01cf908fe2595c5d0a331b4688fe223b 100644 --- a/cores/esp32/FirmwareMSC.cpp +++ b/cores/esp32/FirmwareMSC.cpp @@ -113,6 +113,7 @@ static size_t msc_update_get_required_disk_sectors(){ log_d("USING FAT12"); mcs_is_fat16 = false; } + log_d("FAT sector size: %u", DISK_SECTOR_SIZE); log_d("FAT data sectors: %u", data_sectors); log_d("FAT table sectors: %u", msc_table_sectors); log_d("FAT total sectors: %u (%uKB)", total_sectors, (total_sectors * DISK_SECTOR_SIZE) / 1024); diff --git a/cores/esp32/firmware_msc_fat.c b/cores/esp32/firmware_msc_fat.c index 6dd74ef3b0592e15f27f21d82c50c0e55720c00a..30a1a64ea21e1b2d8dad192350e2ea95c30879d1 100644 --- a/cores/esp32/firmware_msc_fat.c +++ b/cores/esp32/firmware_msc_fat.c @@ -39,7 +39,7 @@ static const char * FAT12_FILE_SYSTEM_TYPE = "FAT12"; static uint16_t fat12_sectors_per_alloc_table(uint32_t sector_num){ uint32_t required_bytes = (((sector_num * 3)+1)/2); - return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & DISK_SECTOR_SIZE)?1:0); + return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & (DISK_SECTOR_SIZE - 1))?1:0); } static uint8_t * fat12_add_table(uint8_t * dst, fat_boot_sector_t * boot){ @@ -68,7 +68,7 @@ static const char * FAT16_FILE_SYSTEM_TYPE = "FAT16"; static uint16_t fat16_sectors_per_alloc_table(uint32_t sector_num){ uint32_t required_bytes = sector_num * 2; - return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & DISK_SECTOR_SIZE)?1:0); + return (required_bytes / DISK_SECTOR_SIZE) + ((required_bytes & (DISK_SECTOR_SIZE - 1))?1:0); } static uint8_t * fat16_add_table(uint8_t * dst, fat_boot_sector_t * boot){ @@ -129,7 +129,7 @@ fat_boot_sector_t * fat_add_boot_sector(uint8_t * dst, uint16_t sector_num, uint boot->num_heads = 1; boot->hidden_sectors_count = 0; boot->total_sectors_32 = 0; - boot->physical_drive_number = 0x00; + boot->physical_drive_number = 0x80; boot->reserved0 = 0x00; boot->extended_boot_signature = 0x29; boot->serial_number = serial_number;