diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2024-11-26 08:35:33 -0500 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2024-11-26 08:37:55 -0500 |
commit | dfbbfb12d44a4c99c77c0f75169fe6b0130c1e12 (patch) | |
tree | 59ec0005e3cefe07f49fa28cf92d22eec20d723d | |
parent | 127b583a4da5b48225cce7336139c1339a30ea9b (diff) | |
download | rockbox-dfbbfb12d4.tar.gz rockbox-dfbbfb12d4.zip |
storage: Misc corrections and cleanups
* Make the partial sector logic a little clearer (no functional change)
* Corrections for debugging messages
* Also use MAX_VIRT_SECTOR_SIZE in BOUNCE_BUFFER calculations
Change-Id: I89363824b092b2e3bddd5e0f75bf81200c9bc513
-rw-r--r-- | firmware/common/file.c | 2 | ||||
-rw-r--r-- | firmware/drivers/ata-common.c | 95 | ||||
-rw-r--r-- | firmware/drivers/fat.c | 12 |
3 files changed, 54 insertions, 55 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index fe65f0fdd5..ba885ca43a 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -120,7 +120,7 @@ static int flush_cache(struct filestr_desc *file) int rc; struct filestr_cache *cachep = file->stream.cachep; - DEBUGF("Flushing dirty sector cache (%lu)\n", cachep->sector); + DEBUGF("Flushing dirty sector cache (%llu)\n", (uint64_t)cachep->sector); if (fat_query_sectornum(&file->stream.fatstr) != cachep->sector) { diff --git a/firmware/drivers/ata-common.c b/firmware/drivers/ata-common.c index 3a1cea2dca..45efd23478 100644 --- a/firmware/drivers/ata-common.c +++ b/firmware/drivers/ata-common.c @@ -84,7 +84,7 @@ int ata_read_sectors(IF_MD(int drive,) offset = start & (phys_sector_mult - 1); - if (offset) /* first partial sector */ + if (offset) /* first partial physical sector */ { int partcount = MIN(incount, phys_sector_mult - offset); @@ -101,32 +101,30 @@ int ata_read_sectors(IF_MD(int drive,) inbuf += partcount * log_sector_size; incount -= partcount; } - if (incount) - { - offset = incount & (phys_sector_mult - 1); - incount -= offset; + offset = incount & (phys_sector_mult - 1); + incount -= offset; - if (incount) + if (incount) /* all complete physical sectors */ + { + rc = ata_transfer_sectors(start, incount, inbuf, false); + if (rc) { - rc = ata_transfer_sectors(start, incount, inbuf, false); - if (rc) - { - rc = rc * 10 - 2; - goto error; - } - start += incount; - inbuf += incount * log_sector_size; + rc = rc * 10 - 2; + goto error; } - if (offset) + start += incount; + inbuf += incount * log_sector_size; + } + + if (offset) /* Trailing partial logical sector */ + { + rc = cache_sector(start); + if (rc) { - rc = cache_sector(start); - if (rc) - { - rc = rc * 10 - 3; - goto error; - } - memcpy(inbuf, sector_cache.data, offset * log_sector_size); + rc = rc * 10 - 3; + goto error; } + memcpy(inbuf, sector_cache.data, offset * log_sector_size); } error: @@ -150,7 +148,7 @@ int ata_write_sectors(IF_MD(int drive,) offset = start & (phys_sector_mult - 1); - if (offset) /* first partial sector */ + if (offset) /* first partial physical sector */ { int partcount = MIN(count, phys_sector_mult - offset); @@ -172,37 +170,36 @@ int ata_write_sectors(IF_MD(int drive,) buf += partcount * log_sector_size; count -= partcount; } - if (count) + + offset = count & (phys_sector_mult - 1); + count -= offset; + + if (count) /* all complete physical sectors */ { - offset = count & (phys_sector_mult - 1); - count -= offset; + rc = ata_transfer_sectors(start, count, (void*)buf, true); + if (rc) + { + rc = rc * 10 - 3; + goto error; + } + start += count; + buf += count * log_sector_size; + } - if (count) + if (offset) /* Trailing partial logical sector */ + { + rc = cache_sector(start); + if (rc) { - rc = ata_transfer_sectors(start, count, (void*)buf, true); - if (rc) - { - rc = rc * 10 - 3; - goto error; - } - start += count; - buf += count * log_sector_size; + rc = rc * 10 - 4; + goto error; } - if (offset) + memcpy(sector_cache.data, buf, offset * log_sector_size); + rc = flush_current_sector(); + if (rc) { - rc = cache_sector(start); - if (rc) - { - rc = rc * 10 - 4; - goto error; - } - memcpy(sector_cache.data, buf, offset * log_sector_size); - rc = flush_current_sector(); - if (rc) - { - rc = rc * 10 - 5; - goto error; - } + rc = rc * 10 - 5; + goto error; } } diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 08c915d39b..14ec35bd27 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -278,7 +278,9 @@ static struct bpb } fat_bpbs[NUM_VOLUMES]; /* mounted partition info */ #ifdef STORAGE_NEEDS_BOUNCE_BUFFER -#if defined(MAX_VARIABLE_LOG_SECTOR) +#if defined(MAX_VIRT_SETOR_SIZE) +#define BOUNCE_SECTOR_SIZE MAX_VIRT_SECTOR_SIZE +#elif defined(MAX_VARIABLE_LOG_SECTOR) #define BOUNCE_SECTOR_SIZE MAX_VARIABLE_LOG_SECTOR #elif defined(MAX_PHYS_SECTOR_SIZE) #define BOUNCE_SECTOR_SIZE MAX_PHYS_SECTOR_SIZE @@ -1586,7 +1588,7 @@ static int write_longname(struct bpb *fat_bpb, struct fat_filestr *parentstr, union raw_dirent *srcent, uint8_t attr, unsigned int flags) { - DEBUGF("%s(file:%lx, first:%d, num:%d, name:%s)\n", __func__, + DEBUGF("%s(file:0x%lx, first:%d, num:%d, name:%s)\n", __func__, file->firstcluster, file->e.entry - file->e.entries + 1, file->e.entries, name); @@ -2490,8 +2492,8 @@ static long transfer(struct bpb *fat_bpb, sector_t start, long count, if (rc < 0) { - DEBUGF("Couldn't %s sector %lx (err %ld)\n", - write ? "write":"read", start, rc); + DEBUGF("Couldn't %s sector %llx (err %ld)\n", + write ? "write":"read", (uint64_t)start, rc); return rc; } @@ -2518,7 +2520,7 @@ long fat_readwrite(struct fat_filestr *filestr, unsigned long sectorcount, long clusternum = filestr->clusternum; unsigned long sectornum = filestr->sectornum; - DEBUGF("%s(file:%lx,count:0x%lx,buf:%lx,%s)\n", __func__, + DEBUGF("%s(file:0x%lx,count:0x%lx,buf:%lx,%s)\n", __func__, file->firstcluster, sectorcount, (long)buf, write ? "write":"read"); DEBUGF("%s: sec:%llx numsec:%ld eof:%d\n", __func__, |