mirror of
https://github.com/opentx/opentx.git
synced 2025-07-14 11:59:50 +03:00
[Horus] Massstorage bugfix (read cache beyond end of disk)
This commit is contained in:
parent
9d492b4faf
commit
fcdcccf8f5
3 changed files with 17 additions and 11 deletions
|
@ -55,7 +55,6 @@ bool DiskCacheBlock::read(BYTE* buff, DWORD sector, UINT count)
|
||||||
|
|
||||||
DRESULT DiskCacheBlock::fill(BYTE drv, BYTE * buff, DWORD sector, UINT count)
|
DRESULT DiskCacheBlock::fill(BYTE drv, BYTE * buff, DWORD sector, UINT count)
|
||||||
{
|
{
|
||||||
// TODO: check if trying to read beyond the end of disk
|
|
||||||
DRESULT res = __disk_read(drv, data, sector, DISK_CACHE_BLOCK_SECTORS);
|
DRESULT res = __disk_read(drv, data, sector, DISK_CACHE_BLOCK_SECTORS);
|
||||||
if (res != RES_OK) {
|
if (res != RES_OK) {
|
||||||
return res;
|
return res;
|
||||||
|
@ -102,6 +101,12 @@ DRESULT DiskCache::read(BYTE drv, BYTE* buff, DWORD sector, UINT count)
|
||||||
return __disk_read(drv, buff, sector, count);
|
return __disk_read(drv, buff, sector, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if block + cache block size is beyond the end of the disk, then read it directly without using cache
|
||||||
|
if (sector+DISK_CACHE_BLOCK_SECTORS > SDCardInfo.CardCapacity / SDCardInfo.CardBlockSize) {
|
||||||
|
TRACE_DISK_CACHE("\t\t cache would be beyond end of disk(%u)", this, (uint32_t)sector);
|
||||||
|
return __disk_read(drv, buff, sector, count);
|
||||||
|
}
|
||||||
|
|
||||||
for (int n=0; n<DISK_CACHE_BLOCKS_NUM; ++n) {
|
for (int n=0; n<DISK_CACHE_BLOCKS_NUM; ++n) {
|
||||||
if (blocks[n].read(buff, sector, count)) {
|
if (blocks[n].read(buff, sector, count)) {
|
||||||
++stats.noHits;
|
++stats.noHits;
|
||||||
|
@ -124,6 +129,7 @@ DRESULT DiskCache::read(BYTE drv, BYTE* buff, DWORD sector, UINT count)
|
||||||
if (++lastBlock >= DISK_CACHE_BLOCKS_NUM) {
|
if (++lastBlock >= DISK_CACHE_BLOCKS_NUM) {
|
||||||
lastBlock = 0;
|
lastBlock = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return blocks[lastBlock].fill(drv, buff, sector, count);
|
return blocks[lastBlock].fill(drv, buff, sector, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "FatFs/diskio.h"
|
#include "FatFs/diskio.h"
|
||||||
|
#include "sdio_sd.h"
|
||||||
|
|
||||||
#if defined(__cplusplus) && !defined(SIMU)
|
#if defined(__cplusplus) && !defined(SIMU)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -39,7 +40,6 @@ enum MassstorageLuns {
|
||||||
|
|
||||||
/* USB Mass storage Standard Inquiry Data */
|
/* USB Mass storage Standard Inquiry Data */
|
||||||
const unsigned char STORAGE_Inquirydata[] = { //36
|
const unsigned char STORAGE_Inquirydata[] = { //36
|
||||||
|
|
||||||
/* LUN 0 */
|
/* LUN 0 */
|
||||||
0x00,
|
0x00,
|
||||||
0x80,
|
0x80,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue