summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/disk.c14
-rw-r--r--firmware/common/file.c29
2 files changed, 30 insertions, 13 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index 950658286c..f5f9f194b2 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -157,7 +157,21 @@ int disk_mount(int drive)
mounted++;
vol_drive[volume] = drive; /* remember the drive for this volume */
volume = get_free_volume(); /* prepare next entry */
+ continue;
}
+
+# 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)))
+ {
+ 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
diff --git a/firmware/common/file.c b/firmware/common/file.c
index e24b44ce1f..d1ba10569a 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -36,7 +36,7 @@
*/
struct filedesc {
- unsigned char cache[SECTOR_SIZE];
+ unsigned char cache[MAX_SECTOR_SIZE];
int cacheoffset; /* invariant: 0 <= cacheoffset <= SECTOR_SIZE */
long fileoffset;
long size;
@@ -415,9 +415,10 @@ int ftruncate(int fd, off_t size)
{
int rc, sector;
struct filedesc* file = &openfiles[fd];
+ int secsize = fat_get_secsize(&(file->fatfile));
- sector = size / SECTOR_SIZE;
- if (size % SECTOR_SIZE)
+ sector = size / secsize;
+ if (size % secsize)
sector++;
rc = fat_seek(&(file->fatfile), sector);
@@ -444,7 +445,7 @@ static int flush_cache(int fd)
{
int rc;
struct filedesc* file = &openfiles[fd];
- long sector = file->fileoffset / SECTOR_SIZE;
+ long sector = file->fileoffset / fat_get_secsize(&(file->fatfile));
DEBUGF("Flushing dirty sector cache\n");
@@ -473,6 +474,7 @@ 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 ) {
@@ -490,7 +492,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, SECTOR_SIZE - offs);
+ int headbytes = MIN(count, secsize - offs);
if (write) {
memcpy( file->cache + offs, buf, headbytes );
@@ -500,7 +502,7 @@ static int readwrite(int fd, void* buf, long count, bool write)
memcpy( buf, file->cache + offs, headbytes );
}
- if (offs + headbytes == SECTOR_SIZE) {
+ if (offs + headbytes == secsize) {
if (file->dirty) {
int rc = flush_cache(fd);
if ( rc < 0 ) {
@@ -523,7 +525,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 / SECTOR_SIZE;
+ sectors = count / secsize;
if ( sectors ) {
int rc = fat_readwrite(&(file->fatfile), sectors,
(unsigned char*)buf+nread, write );
@@ -541,8 +543,8 @@ static int readwrite(int fd, void* buf, long count, bool write)
}
else {
if ( rc > 0 ) {
- nread += rc * SECTOR_SIZE;
- count -= sectors * SECTOR_SIZE;
+ nread += rc * secsize;
+ count -= sectors * secsize;
/* if eof, skip tail bytes */
if ( rc < sectors )
@@ -575,7 +577,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) /
- SECTOR_SIZE);
+ secsize);
if ( rc < 0 ) {
DEBUGF("fat_seek() failed\n");
errno = EIO;
@@ -641,6 +643,7 @@ 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);
@@ -672,9 +675,9 @@ off_t lseek(int fd, off_t offset, int whence)
}
/* new sector? */
- newsector = pos / SECTOR_SIZE;
- oldsector = file->fileoffset / SECTOR_SIZE;
- sectoroffset = pos % SECTOR_SIZE;
+ newsector = pos / secsize;
+ oldsector = file->fileoffset / secsize;
+ sectoroffset = pos % secsize;
if ( (newsector != oldsector) ||
((file->cacheoffset==-1) && sectoroffset) ) {