mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-17 23:12:17 +00:00
emummc: fix file-based accesses that cross file boundaries
This commit is contained in:
parent
0a11cbc2d6
commit
972681c57e
@ -292,6 +292,35 @@ static uint64_t emummc_read_write_inner(void *buf, unsigned int sector, unsigned
|
||||
{
|
||||
fp = &f_emu.fp_gpp[sector / f_emu.part_size];
|
||||
sector = sector % f_emu.part_size;
|
||||
|
||||
// Special handling for reads/writes which cross file-boundaries.
|
||||
if (__builtin_expect(sector + num_sectors > f_emu.part_size, 0))
|
||||
{
|
||||
unsigned int remaining = num_sectors;
|
||||
while (remaining > 0) {
|
||||
const unsigned int cur_sectors = MIN(remaining, f_emu.part_size - sector);
|
||||
|
||||
if (f_lseek(fp, sector << 9) != FR_OK)
|
||||
return 0; // Out of bounds.
|
||||
|
||||
if (is_write)
|
||||
{
|
||||
if (f_write_fast(fp, buf, cur_sectors << 9) != FR_OK)
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (f_read_fast(fp, buf, cur_sectors << 9) != FR_OK)
|
||||
return 0;
|
||||
}
|
||||
|
||||
remaining -= cur_sectors;
|
||||
sector = 0;
|
||||
++fp;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user