summaryrefslogtreecommitdiff
path: root/firmware/common/file.c
diff options
context:
space:
mode:
authorMichael Sparmann <theseven@rockbox.org>2011-02-27 22:47:33 +0000
committerMichael Sparmann <theseven@rockbox.org>2011-02-27 22:47:33 +0000
commit59c5e791a13765e75dacc2b97e93450c374b3b14 (patch)
tree81ca04dff7403e103280b63cb87e1fdea8dc5447 /firmware/common/file.c
parent1b5e31ed43d2c09ada6a1313b2a1de0b262e74c6 (diff)
downloadrockbox-59c5e791a13765e75dacc2b97e93450c374b3b14.tar.gz
rockbox-59c5e791a13765e75dacc2b97e93450c374b3b14.zip
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
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r--firmware/common/file.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index bc4a90a485..272cf8a80b 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -496,9 +496,10 @@ static int flush_cache(int fd)
496static int readwrite(int fd, void* buf, long count, bool write) 496static int readwrite(int fd, void* buf, long count, bool write)
497{ 497{
498 long sectors; 498 long sectors;
499 long i;
499 long nread=0; 500 long nread=0;
500 struct filedesc* file; 501 struct filedesc* file;
501 int rc; 502 int rc, rc2;
502 503
503 if (fd < 0 || fd > MAX_OPEN_FILES-1) { 504 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
504 errno = EINVAL; 505 errno = EINVAL;
@@ -561,9 +562,25 @@ static int readwrite(int fd, void* buf, long count, bool write)
561 562
562 /* read/write whole sectors right into/from the supplied buffer */ 563 /* read/write whole sectors right into/from the supplied buffer */
563 sectors = count / SECTOR_SIZE; 564 sectors = count / SECTOR_SIZE;
565 rc = 0;
564 if ( sectors ) { 566 if ( sectors ) {
565 rc = fat_readwrite(&(file->fatfile), sectors, 567#ifdef STORAGE_NEEDS_ALIGN
566 (unsigned char*)buf+nread, write ); 568 if (((uint32_t)buf + nread) & (CACHEALIGN_SIZE - 1))
569 for (i = 0; i < sectors; i++)
570 {
571 if (write) memcpy(file->cache, buf+nread+i*SECTOR_SIZE, SECTOR_SIZE);
572 rc2 = fat_readwrite(&(file->fatfile), 1, file->cache, write );
573 if (rc2 < 0)
574 {
575 rc = rc2;
576 break;
577 }
578 else rc += rc2;
579 if (!write) memcpy(buf+nread+i*SECTOR_SIZE, file->cache, SECTOR_SIZE);
580 }
581 else
582#endif
583 rc = fat_readwrite(&(file->fatfile), sectors, (unsigned char*)buf+nread, write );
567 if ( rc < 0 ) { 584 if ( rc < 0 ) {
568 DEBUGF("Failed read/writing %ld sectors\n",sectors); 585 DEBUGF("Failed read/writing %ld sectors\n",sectors);
569 errno = EIO; 586 errno = EIO;