1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Solomon Peachy 2024-11-26 08:35:33 -05:00
parent 127b583a4d
commit dfbbfb12d4
3 changed files with 55 additions and 56 deletions

View file

@ -120,7 +120,7 @@ static int flush_cache(struct filestr_desc *file)
int rc; int rc;
struct filestr_cache *cachep = file->stream.cachep; 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) if (fat_query_sectornum(&file->stream.fatstr) != cachep->sector)
{ {

View file

@ -84,7 +84,7 @@ int ata_read_sectors(IF_MD(int drive,)
offset = start & (phys_sector_mult - 1); 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); 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; inbuf += partcount * log_sector_size;
incount -= partcount; 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); rc = rc * 10 - 2;
if (rc) goto error;
{
rc = rc * 10 - 2;
goto error;
}
start += incount;
inbuf += incount * log_sector_size;
} }
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); rc = rc * 10 - 3;
if (rc) goto error;
{
rc = rc * 10 - 3;
goto error;
}
memcpy(inbuf, sector_cache.data, offset * log_sector_size);
} }
memcpy(inbuf, sector_cache.data, offset * log_sector_size);
} }
error: error:
@ -150,7 +148,7 @@ int ata_write_sectors(IF_MD(int drive,)
offset = start & (phys_sector_mult - 1); 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); 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; buf += partcount * log_sector_size;
count -= partcount; count -= partcount;
} }
if (count)
{
offset = count & (phys_sector_mult - 1);
count -= offset;
if (count) offset = count & (phys_sector_mult - 1);
count -= offset;
if (count) /* all complete physical sectors */
{
rc = ata_transfer_sectors(start, count, (void*)buf, true);
if (rc)
{ {
rc = ata_transfer_sectors(start, count, (void*)buf, true); rc = rc * 10 - 3;
if (rc) goto error;
{
rc = rc * 10 - 3;
goto error;
}
start += count;
buf += count * log_sector_size;
} }
if (offset) start += count;
buf += count * log_sector_size;
}
if (offset) /* Trailing partial logical sector */
{
rc = cache_sector(start);
if (rc)
{ {
rc = cache_sector(start); rc = rc * 10 - 4;
if (rc) goto error;
{ }
rc = rc * 10 - 4; memcpy(sector_cache.data, buf, offset * log_sector_size);
goto error; rc = flush_current_sector();
} if (rc)
memcpy(sector_cache.data, buf, offset * log_sector_size); {
rc = flush_current_sector(); rc = rc * 10 - 5;
if (rc) goto error;
{
rc = rc * 10 - 5;
goto error;
}
} }
} }

View file

@ -278,7 +278,9 @@ static struct bpb
} fat_bpbs[NUM_VOLUMES]; /* mounted partition info */ } fat_bpbs[NUM_VOLUMES]; /* mounted partition info */
#ifdef STORAGE_NEEDS_BOUNCE_BUFFER #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 #define BOUNCE_SECTOR_SIZE MAX_VARIABLE_LOG_SECTOR
#elif defined(MAX_PHYS_SECTOR_SIZE) #elif defined(MAX_PHYS_SECTOR_SIZE)
#define BOUNCE_SECTOR_SIZE 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, union raw_dirent *srcent, uint8_t attr,
unsigned int flags) 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->firstcluster, file->e.entry - file->e.entries + 1,
file->e.entries, name); file->e.entries, name);
@ -2490,8 +2492,8 @@ static long transfer(struct bpb *fat_bpb, sector_t start, long count,
if (rc < 0) if (rc < 0)
{ {
DEBUGF("Couldn't %s sector %lx (err %ld)\n", DEBUGF("Couldn't %s sector %llx (err %ld)\n",
write ? "write":"read", start, rc); write ? "write":"read", (uint64_t)start, rc);
return rc; return rc;
} }
@ -2518,7 +2520,7 @@ long fat_readwrite(struct fat_filestr *filestr, unsigned long sectorcount,
long clusternum = filestr->clusternum; long clusternum = filestr->clusternum;
unsigned long sectornum = filestr->sectornum; 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, file->firstcluster, sectorcount, (long)buf,
write ? "write":"read"); write ? "write":"read");
DEBUGF("%s: sec:%llx numsec:%ld eof:%d\n", __func__, DEBUGF("%s: sec:%llx numsec:%ld eof:%d\n", __func__,