minor change in RAM disk read/write handling

This commit is contained in:
cecio
2026-04-04 23:23:09 +02:00
parent b81e83e7e6
commit f86712a8ed

View File

@@ -73,14 +73,17 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset,
flag_autorun = true; flag_autorun = true;
} }
// Protect memory: only read from real disk blocks // Return data from ramdisk, or zeros for blocks beyond it.
if (lba < DISK_BLOCK_NUM - 1) { // The disk reports FAKE_DISK_BLOCK_NUM sectors but only
uint8_t const* addr = msc_disk[lba]; // DISK_BLOCK_NUM exist in RAM — the rest must read as empty.
memcpy(buffer, addr, bufsize); if (lba < DISK_BLOCK_NUM) {
memcpy(buffer, msc_disk[lba], bufsize);
} else {
memset(buffer, 0, bufsize);
} }
serial_printf("Read LBA: %u Size: %u\r\n", (unsigned)lba, (unsigned)bufsize); serial_printf("Read LBA: %u Size: %u\r\n", (unsigned)lba, (unsigned)bufsize);
if (lba < DISK_BLOCK_NUM - 1) { if (lba < DISK_BLOCK_NUM) {
hex_dump(msc_disk[lba], MAX_DUMP_BYTES); hex_dump(msc_disk[lba], MAX_DUMP_BYTES);
} }
@@ -105,14 +108,13 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset,
flag_written = true; flag_written = true;
} }
// Protect memory: only write to real disk blocks // Only write to real disk blocks; silently discard beyond ramdisk
if (lba < DISK_BLOCK_NUM - 1) { if (lba < DISK_BLOCK_NUM) {
uint8_t* addr = msc_disk[lba]; memcpy(msc_disk[lba], buffer, bufsize);
memcpy(addr, buffer, bufsize);
} }
serial_printf("Write LBA: %u Size: %u\r\n", (unsigned)lba, (unsigned)bufsize); serial_printf("Write LBA: %u Size: %u\r\n", (unsigned)lba, (unsigned)bufsize);
if (lba < DISK_BLOCK_NUM - 1) { if (lba < DISK_BLOCK_NUM) {
hex_dump(msc_disk[lba], MAX_DUMP_BYTES); hex_dump(msc_disk[lba], MAX_DUMP_BYTES);
} }