mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-26 13:52:21 +00:00
emummc: fix file-based accesses that cross file boundaries
This commit is contained in:
parent
0a11cbc2d6
commit
972681c57e
1 changed files with 29 additions and 0 deletions
|
@ -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];
|
fp = &f_emu.fp_gpp[sector / f_emu.part_size];
|
||||||
sector = 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
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue