freemyipod r120 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r119‎ | r120 | r121 >
Date:14:30, 13 August 2010
Author:theseven
Status:new
Tags:
Comment:
Fix unaligned file accesses
Modified paths:
  • /embios/trunk/file.c (modified) (history)
  • /embios/trunk/syscall.h (modified) (history)

Diff [purge]

Index: embios/trunk/syscall.h
@@ -31,7 +31,7 @@
3232 uint32_t get_platform_id() ICODE_ATTR;
3333
3434
35 -#include "syscallapi.h" // must be below get_platform_id
 35+#include "syscallapi.h" // must be between get_platform_id and get_syscall_table
3636
3737
3838 struct embios_syscall_table* get_syscall_table() ICODE_ATTR;
Index: embios/trunk/file.c
@@ -458,9 +458,10 @@
459459 static int readwrite(int fd, void* buf, long count, bool write)
460460 {
461461 long sectors;
 462+ long i;
462463 long nread=0;
463464 struct filedesc* file;
464 - int rc;
 465+ int rc, rc2;
465466
466467 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
467468 errno = EINVAL;
@@ -523,13 +524,21 @@
524525
525526 /* read/write whole sectors right into/from the supplied buffer */
526527 sectors = count / SECTOR_SIZE;
 528+ rc = 0;
527529 if ( sectors ) {
528530 if (((uint32_t)buf + nread) & (CACHEALIGN_SIZE - 1))
529 - {
530 - if (write) memcpy(file->cache, buf+nread, SECTOR_SIZE);
531 - rc = fat_readwrite(&(file->fatfile), sectors, file->cache, write );
532 - if (!write) memcpy(buf+nread, file->cache, SECTOR_SIZE);
533 - }
 531+ for (i = 0; i < sectors; i++)
 532+ {
 533+ if (write) memcpy(file->cache, buf+nread+i*SECTOR_SIZE, SECTOR_SIZE);
 534+ rc2 = fat_readwrite(&(file->fatfile), 1, file->cache, write );
 535+ if (rc2 < 0)
 536+ {
 537+ rc = rc2;
 538+ break;
 539+ }
 540+ else rc += rc2;
 541+ if (!write) memcpy(buf+nread+i*SECTOR_SIZE, file->cache, SECTOR_SIZE);
 542+ }
534543 else rc = fat_readwrite(&(file->fatfile), sectors, (unsigned char*)buf+nread, write );
535544 if ( rc < 0 ) {
536545 DEBUGF("Failed read/writing %ld sectors",sectors);