diff options
| author | Michael Sparmann <theseven@rockbox.org> | 2011-02-27 22:47:33 +0000 |
|---|---|---|
| committer | Michael Sparmann <theseven@rockbox.org> | 2011-02-27 22:47:33 +0000 |
| commit | 59c5e791a13765e75dacc2b97e93450c374b3b14 (patch) | |
| tree | 81ca04dff7403e103280b63cb87e1fdea8dc5447 | |
| parent | 1b5e31ed43d2c09ada6a1313b2a1de0b262e74c6 (diff) | |
| download | rockbox-59c5e791a13765e75dacc2b97e93450c374b3b14.zip rockbox-59c5e791a13765e75dacc2b97e93450c374b3b14.tar.gz rockbox-59c5e791a13765e75dacc2b97e93450c374b3b14.tar.bz2 rockbox-59c5e791a13765e75dacc2b97e93450c374b3b14.tar.xz | |
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
| -rw-r--r-- | firmware/common/file.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index bc4a90a..272cf8a 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -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; |