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,12 +101,10 @@ 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); offset = incount & (phys_sector_mult - 1);
incount -= offset; incount -= offset;
if (incount) if (incount) /* all complete physical sectors */
{ {
rc = ata_transfer_sectors(start, incount, inbuf, false); rc = ata_transfer_sectors(start, incount, inbuf, false);
if (rc) if (rc)
@ -117,7 +115,8 @@ int ata_read_sectors(IF_MD(int drive,)
start += incount; start += incount;
inbuf += incount * log_sector_size; inbuf += incount * log_sector_size;
} }
if (offset)
if (offset) /* Trailing partial logical sector */
{ {
rc = cache_sector(start); rc = cache_sector(start);
if (rc) if (rc)
@ -127,7 +126,6 @@ int ata_read_sectors(IF_MD(int drive,)
} }
memcpy(inbuf, sector_cache.data, offset * log_sector_size); memcpy(inbuf, sector_cache.data, offset * log_sector_size);
} }
}
error: error:
mutex_unlock(&ata_mutex); mutex_unlock(&ata_mutex);
@ -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,12 +170,11 @@ 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); offset = count & (phys_sector_mult - 1);
count -= offset; count -= offset;
if (count) if (count) /* all complete physical sectors */
{ {
rc = ata_transfer_sectors(start, count, (void*)buf, true); rc = ata_transfer_sectors(start, count, (void*)buf, true);
if (rc) if (rc)
@ -188,7 +185,8 @@ int ata_write_sectors(IF_MD(int drive,)
start += count; start += count;
buf += count * log_sector_size; buf += count * log_sector_size;
} }
if (offset)
if (offset) /* Trailing partial logical sector */
{ {
rc = cache_sector(start); rc = cache_sector(start);
if (rc) if (rc)
@ -204,7 +202,6 @@ int ata_write_sectors(IF_MD(int drive,)
goto error; goto error;
} }
} }
}
error: error:
mutex_unlock(&ata_mutex); mutex_unlock(&ata_mutex);

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__,