iPod Classic CE-ATA Support (Part 3 of 4: Introduce STORAGE_NEEDS_ALIGN, which ensures that no unaligned storage accesses are performed through file.c)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29447 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
1b5e31ed43
commit
59c5e791a1
1 changed files with 20 additions and 3 deletions
|
@ -496,9 +496,10 @@ static int flush_cache(int fd)
|
|||
static int readwrite(int fd, void* buf, long count, bool write)
|
||||
{
|
||||
long sectors;
|
||||
long i;
|
||||
long nread=0;
|
||||
struct filedesc* file;
|
||||
int rc;
|
||||
int rc, rc2;
|
||||
|
||||
if (fd < 0 || fd > MAX_OPEN_FILES-1) {
|
||||
errno = EINVAL;
|
||||
|
@ -561,9 +562,25 @@ static int readwrite(int fd, void* buf, long count, bool write)
|
|||
|
||||
/* read/write whole sectors right into/from the supplied buffer */
|
||||
sectors = count / SECTOR_SIZE;
|
||||
rc = 0;
|
||||
if ( sectors ) {
|
||||
rc = fat_readwrite(&(file->fatfile), sectors,
|
||||
(unsigned char*)buf+nread, write );
|
||||
#ifdef STORAGE_NEEDS_ALIGN
|
||||
if (((uint32_t)buf + nread) & (CACHEALIGN_SIZE - 1))
|
||||
for (i = 0; i < sectors; i++)
|
||||
{
|
||||
if (write) memcpy(file->cache, buf+nread+i*SECTOR_SIZE, SECTOR_SIZE);
|
||||
rc2 = fat_readwrite(&(file->fatfile), 1, file->cache, write );
|
||||
if (rc2 < 0)
|
||||
{
|
||||
rc = rc2;
|
||||
break;
|
||||
}
|
||||
else rc += rc2;
|
||||
if (!write) memcpy(buf+nread+i*SECTOR_SIZE, file->cache, SECTOR_SIZE);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
rc = fat_readwrite(&(file->fatfile), sectors, (unsigned char*)buf+nread, write );
|
||||
if ( rc < 0 ) {
|
||||
DEBUGF("Failed read/writing %ld sectors\n",sectors);
|
||||
errno = EIO;
|
||||
|
|
Loading…
Reference in a new issue