forked from len0rd/rockbox
Some MMCs don't like reading their very last sector with the read_multiple_blocks command, so always read it with read_single_block. Slight optimisation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5942 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
672092c6dc
commit
4d6e482e56
1 changed files with 21 additions and 16 deletions
|
|
@ -626,7 +626,7 @@ int ata_read_sectors(IF_MV2(int drive,)
|
||||||
void* inbuf)
|
void* inbuf)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int i;
|
int last_sector;
|
||||||
unsigned long addr;
|
unsigned long addr;
|
||||||
unsigned char response;
|
unsigned char response;
|
||||||
void *inbuf_prev = NULL;
|
void *inbuf_prev = NULL;
|
||||||
|
|
@ -645,22 +645,17 @@ int ata_read_sectors(IF_MV2(int drive,)
|
||||||
if (start + incount > card->numsectors)
|
if (start + incount > card->numsectors)
|
||||||
panicf("Reading past end of card\n");
|
panicf("Reading past end of card\n");
|
||||||
|
|
||||||
|
/* some cards don't like reading the very last sector with
|
||||||
|
* CMD_READ_MULTIPLE_BLOCK, so make sure this sector is always
|
||||||
|
* read with CMD_READ_SINGLE_BLOCK. */
|
||||||
|
last_sector = (start + incount == card->numsectors) ? 1 : 0;
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
if (incount == 1)
|
if (incount > 1)
|
||||||
{
|
|
||||||
ret = send_cmd(CMD_READ_SINGLE_BLOCK, addr, &response);
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
ret = receive_sector(inbuf, inbuf_prev, card->read_timeout);
|
|
||||||
inbuf_prev = inbuf;
|
|
||||||
last_disk_activity = current_tick;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
ret = send_cmd(CMD_READ_MULTIPLE_BLOCK, addr, &response);
|
ret = send_cmd(CMD_READ_MULTIPLE_BLOCK, addr, &response);
|
||||||
for (i = 0; (i < incount) && (ret == 0); i++)
|
for (; (incount > last_sector) && (ret == 0); incount--)
|
||||||
{
|
{
|
||||||
ret = receive_sector(inbuf, inbuf_prev, card->read_timeout);
|
ret = receive_sector(inbuf, inbuf_prev, card->read_timeout);
|
||||||
inbuf_prev = inbuf;
|
inbuf_prev = inbuf;
|
||||||
|
|
@ -670,6 +665,17 @@ int ata_read_sectors(IF_MV2(int drive,)
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = send_cmd(CMD_STOP_TRANSMISSION, 0, &response);
|
ret = send_cmd(CMD_STOP_TRANSMISSION, 0, &response);
|
||||||
}
|
}
|
||||||
|
if (incount && (ret == 0))
|
||||||
|
{
|
||||||
|
ret = send_cmd(CMD_READ_SINGLE_BLOCK, addr, &response);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
ret = receive_sector(inbuf, inbuf_prev, card->read_timeout);
|
||||||
|
inbuf_prev = inbuf;
|
||||||
|
last_disk_activity = current_tick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
bitswap(inbuf_prev, SECTOR_SIZE);
|
bitswap(inbuf_prev, SECTOR_SIZE);
|
||||||
}
|
}
|
||||||
|
|
@ -690,7 +696,6 @@ int ata_write_sectors(IF_MV2(int drive,)
|
||||||
const void* buf)
|
const void* buf)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int i;
|
|
||||||
unsigned long addr;
|
unsigned long addr;
|
||||||
unsigned char response;
|
unsigned char response;
|
||||||
tCardInfo *card;
|
tCardInfo *card;
|
||||||
|
|
@ -724,7 +729,7 @@ int ata_write_sectors(IF_MV2(int drive,)
|
||||||
{
|
{
|
||||||
swapcopy_sector(buf); /* prepare first sector */
|
swapcopy_sector(buf); /* prepare first sector */
|
||||||
ret = send_cmd(CMD_WRITE_MULTIPLE_BLOCK, addr, &response);
|
ret = send_cmd(CMD_WRITE_MULTIPLE_BLOCK, addr, &response);
|
||||||
for (i = 1; (i < count) && (ret == 0); i++)
|
for (; (count > 1) && (ret == 0); count--)
|
||||||
{
|
{
|
||||||
buf += SECTOR_SIZE;
|
buf += SECTOR_SIZE;
|
||||||
ret = send_sector(buf, card->write_timeout);
|
ret = send_sector(buf, card->write_timeout);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue