diff --git a/Source/Core/Common/SDCardUtil.cpp b/Source/Core/Common/SDCardUtil.cpp index d57a43fb9d..5719c1552f 100644 --- a/Source/Core/Common/SDCardUtil.cpp +++ b/Source/Core/Common/SDCardUtil.cpp @@ -177,12 +177,12 @@ static void fat_init(u8* fat) POKEW(fat + 8, 0x0fffffff); /* End of cluster chain for root dir */ } -static unsigned int write_sector(FILE* file, u8* sector) +static bool write_sector(FILE* file, const u8* sector) { - return fwrite(sector, 1, BYTES_PER_SECTOR, file) != BYTES_PER_SECTOR; + return fwrite(sector, 1, BYTES_PER_SECTOR, file) == BYTES_PER_SECTOR; } -static unsigned int write_empty(FILE* file, u64 count) +static bool write_empty(FILE* file, u64 count) { static u8 empty[64 * 1024]; @@ -194,11 +194,11 @@ static unsigned int write_empty(FILE* file, u64 count) len = count; if (fwrite(empty, 1, (size_t)len, file) != (size_t)len) - return 1; + return false; count -= len; } - return 0; + return true; } bool SDCardCreate(u64 disk_size /*in MB*/, const std::string& filename) @@ -245,45 +245,45 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const std::string& filename) * zero sectors */ - if (write_sector(f, s_boot_sector)) + if (!write_sector(f, s_boot_sector)) goto FailWrite; - if (write_sector(f, s_fsinfo_sector)) + if (!write_sector(f, s_fsinfo_sector)) goto FailWrite; if (BACKUP_BOOT_SECTOR > 0) { - if (write_empty(f, BACKUP_BOOT_SECTOR - 2)) + if (!write_empty(f, BACKUP_BOOT_SECTOR - 2)) goto FailWrite; - if (write_sector(f, s_boot_sector)) + if (!write_sector(f, s_boot_sector)) goto FailWrite; - if (write_sector(f, s_fsinfo_sector)) + if (!write_sector(f, s_fsinfo_sector)) goto FailWrite; - if (write_empty(f, RESERVED_SECTORS - 2 - BACKUP_BOOT_SECTOR)) + if (!write_empty(f, RESERVED_SECTORS - 2 - BACKUP_BOOT_SECTOR)) goto FailWrite; } else { - if (write_empty(f, RESERVED_SECTORS - 2)) + if (!write_empty(f, RESERVED_SECTORS - 2)) goto FailWrite; } - if (write_sector(f, s_fat_head)) + if (!write_sector(f, s_fat_head)) goto FailWrite; - if (write_empty(f, sectors_per_fat - 1)) + if (!write_empty(f, sectors_per_fat - 1)) goto FailWrite; - if (write_sector(f, s_fat_head)) + if (!write_sector(f, s_fat_head)) goto FailWrite; - if (write_empty(f, sectors_per_fat - 1)) + if (!write_empty(f, sectors_per_fat - 1)) goto FailWrite; - if (write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2 * sectors_per_fat)) + if (!write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2 * sectors_per_fat)) goto FailWrite; return true;