mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/fatfs: use page-wise read() and write()
The FAT file system operates on sectors (pages), so use the new mtd_write_page() and mtd_read_page() functions. This also avoids the wrap-around after reading/writing past 4 GiB.
This commit is contained in:
parent
7d291b5707
commit
c436c39ea8
@ -95,15 +95,15 @@ DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
uint32_t nread = count * fatfs_mtd_devs[pdrv]->page_size;
|
||||
int res = mtd_read(fatfs_mtd_devs[pdrv], buff,
|
||||
sector * fatfs_mtd_devs[pdrv]->page_size,
|
||||
nread);
|
||||
uint32_t sector_size = fatfs_mtd_devs[pdrv]->page_size
|
||||
* fatfs_mtd_devs[pdrv]->pages_per_sector;
|
||||
|
||||
int res = mtd_read_page(fatfs_mtd_devs[pdrv], buff,
|
||||
sector, 0, count * sector_size);
|
||||
|
||||
if (res != 0) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
assert((nread / fatfs_mtd_devs[pdrv]->page_size) == count);
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
@ -127,23 +127,21 @@ DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
|
||||
}
|
||||
|
||||
/* erase memory before writing to it */
|
||||
int res = mtd_erase(fatfs_mtd_devs[pdrv],
|
||||
sector * fatfs_mtd_devs[pdrv]->page_size,
|
||||
count * fatfs_mtd_devs[pdrv]->page_size);
|
||||
int res = mtd_erase_sector(fatfs_mtd_devs[pdrv], sector, count);
|
||||
|
||||
if (res != 0) {
|
||||
return RES_ERROR; /* erase failed! */
|
||||
}
|
||||
|
||||
uint32_t nwrite = count * fatfs_mtd_devs[pdrv]->page_size;
|
||||
res = mtd_write(fatfs_mtd_devs[pdrv], buff,
|
||||
sector * fatfs_mtd_devs[pdrv]->page_size,
|
||||
nwrite);
|
||||
uint32_t sector_size = fatfs_mtd_devs[pdrv]->page_size
|
||||
* fatfs_mtd_devs[pdrv]->pages_per_sector;
|
||||
|
||||
res = mtd_write_page(fatfs_mtd_devs[pdrv], buff,
|
||||
sector, 0, count * sector_size);
|
||||
|
||||
if (res != 0) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
assert((nwrite / fatfs_mtd_devs[pdrv]->page_size) == count);
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user