diff options
| author | Jens Arnold <amiconn@rockbox.org> | 2006-12-04 21:37:22 +0000 |
|---|---|---|
| committer | Jens Arnold <amiconn@rockbox.org> | 2006-12-04 21:37:22 +0000 |
| commit | ef3e129b6530b1694c0fcfa8ee2fbdf3ea95b083 (patch) | |
| tree | 073e5fe264f0edcfc907254320b4f90e74042672 /firmware/common | |
| parent | 74369b4a7b1b91371dc90905dc26e54b919d81a4 (diff) | |
| download | rockbox-ef3e129b6530b1694c0fcfa8ee2fbdf3ea95b083.zip rockbox-ef3e129b6530b1694c0fcfa8ee2fbdf3ea95b083.tar.gz rockbox-ef3e129b6530b1694c0fcfa8ee2fbdf3ea95b083.tar.bz2 rockbox-ef3e129b6530b1694c0fcfa8ee2fbdf3ea95b083.tar.xz | |
Much simpler implementation of large virtual sector support, not needing larger sector buffers and not touching file.c at all. secmult is simply used to normalize all sector counts to 512-byte physical sectors. * Moved MAX_SECTOR_SIZE definition to config-*.h, and enabled it for iPod Video only. MAX_SECTOR_SIZE now only enables checking for alternate disk layouts due to sector size (as iPod Video G5.5 is presented as having 2048-byte _physical_ sectors to the PC). Large virtual sector support in fat.c is always enabled.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11659 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common')
| -rw-r--r-- | firmware/common/disk.c | 29 | ||||
| -rw-r--r-- | firmware/common/file.c | 29 |
2 files changed, 29 insertions, 29 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c index f5f9f19..c58ae3e 100644 --- a/firmware/common/disk.c +++ b/firmware/common/disk.c @@ -152,26 +152,29 @@ int disk_mount(int drive) real problem. */ for (i=0; volume != -1 && i<4; i++) { - if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start)) +#ifdef MAX_SECTOR_SIZE + int j; + + for (j = 1; j <= (MAX_SECTOR_SIZE/SECTOR_SIZE); j <<= 1) { - mounted++; - vol_drive[volume] = drive; /* remember the drive for this volume */ - volume = get_free_volume(); /* prepare next entry */ - continue; + if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start * j)) + { + pinfo[i].start *= j; + pinfo[i].size *= j; + mounted++; + vol_drive[volume] = drive; /* remember the drive for this volume */ + volume = get_free_volume(); /* prepare next entry */ + break; + } } - -# if MAX_SECTOR_SIZE != PHYSICAL_SECTOR_SIZE - /* Try again with sector size 2048 */ - if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start - * (MAX_SECTOR_SIZE/PHYSICAL_SECTOR_SIZE))) +#else + if (!fat_mount(IF_MV2(volume,) IF_MV2(drive,) pinfo[i].start)) { - pinfo[i].start *= MAX_SECTOR_SIZE/PHYSICAL_SECTOR_SIZE; - pinfo[i].size *= MAX_SECTOR_SIZE/PHYSICAL_SECTOR_SIZE; mounted++; vol_drive[volume] = drive; /* remember the drive for this volume */ volume = get_free_volume(); /* prepare next entry */ } -# endif +#endif } #endif diff --git a/firmware/common/file.c b/firmware/common/file.c index d1ba105..e24b44c 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -36,7 +36,7 @@ */ struct filedesc { - unsigned char cache[MAX_SECTOR_SIZE]; + unsigned char cache[SECTOR_SIZE]; int cacheoffset; /* invariant: 0 <= cacheoffset <= SECTOR_SIZE */ long fileoffset; long size; @@ -415,10 +415,9 @@ int ftruncate(int fd, off_t size) { int rc, sector; struct filedesc* file = &openfiles[fd]; - int secsize = fat_get_secsize(&(file->fatfile)); - sector = size / secsize; - if (size % secsize) + sector = size / SECTOR_SIZE; + if (size % SECTOR_SIZE) sector++; rc = fat_seek(&(file->fatfile), sector); @@ -445,7 +444,7 @@ static int flush_cache(int fd) { int rc; struct filedesc* file = &openfiles[fd]; - long sector = file->fileoffset / fat_get_secsize(&(file->fatfile)); + long sector = file->fileoffset / SECTOR_SIZE; DEBUGF("Flushing dirty sector cache\n"); @@ -474,7 +473,6 @@ static int readwrite(int fd, void* buf, long count, bool write) long sectors; long nread=0; struct filedesc* file = &openfiles[fd]; - int secsize = fat_get_secsize(&(file->fatfile)); int rc; if ( !file->busy ) { @@ -492,7 +490,7 @@ static int readwrite(int fd, void* buf, long count, bool write) /* any head bytes? */ if ( file->cacheoffset != -1 ) { int offs = file->cacheoffset; - int headbytes = MIN(count, secsize - offs); + int headbytes = MIN(count, SECTOR_SIZE - offs); if (write) { memcpy( file->cache + offs, buf, headbytes ); @@ -502,7 +500,7 @@ static int readwrite(int fd, void* buf, long count, bool write) memcpy( buf, file->cache + offs, headbytes ); } - if (offs + headbytes == secsize) { + if (offs + headbytes == SECTOR_SIZE) { if (file->dirty) { int rc = flush_cache(fd); if ( rc < 0 ) { @@ -525,7 +523,7 @@ static int readwrite(int fd, void* buf, long count, bool write) * more data to follow in this call). Do NOT flush here. */ /* read/write whole sectors right into/from the supplied buffer */ - sectors = count / secsize; + sectors = count / SECTOR_SIZE; if ( sectors ) { int rc = fat_readwrite(&(file->fatfile), sectors, (unsigned char*)buf+nread, write ); @@ -543,8 +541,8 @@ static int readwrite(int fd, void* buf, long count, bool write) } else { if ( rc > 0 ) { - nread += rc * secsize; - count -= sectors * secsize; + nread += rc * SECTOR_SIZE; + count -= sectors * SECTOR_SIZE; /* if eof, skip tail bytes */ if ( rc < sectors ) @@ -577,7 +575,7 @@ static int readwrite(int fd, void* buf, long count, bool write) /* seek back one sector to put file position right */ rc = fat_seek(&(file->fatfile), (file->fileoffset + nread) / - secsize); + SECTOR_SIZE); if ( rc < 0 ) { DEBUGF("fat_seek() failed\n"); errno = EIO; @@ -643,7 +641,6 @@ off_t lseek(int fd, off_t offset, int whence) int sectoroffset; int rc; struct filedesc* file = &openfiles[fd]; - int secsize = fat_get_secsize(&(file->fatfile)); LDEBUGF("lseek(%d,%ld,%d)\n",fd,offset,whence); @@ -675,9 +672,9 @@ off_t lseek(int fd, off_t offset, int whence) } /* new sector? */ - newsector = pos / secsize; - oldsector = file->fileoffset / secsize; - sectoroffset = pos % secsize; + newsector = pos / SECTOR_SIZE; + oldsector = file->fileoffset / SECTOR_SIZE; + sectoroffset = pos % SECTOR_SIZE; if ( (newsector != oldsector) || ((file->cacheoffset==-1) && sectoroffset) ) { |