mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
fix: disk drive-explicitly writing 0 bytes would write 4096 bytes instead
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -115,12 +115,12 @@ MMIO
|
||||
n-read: size of the block from the other device, LSB (4096-full block size is zero)
|
||||
m-read: size of the block from the other device, MSB (4096-full block size is zero)
|
||||
a-read: if the other device hasNext (doYouHaveNext), false if device not present
|
||||
z-read: set if the size is actually 0 instead of 4096
|
||||
z-read: set if the size is actually 0 instead of 4096 (overrides n and m parameters)
|
||||
|
||||
n-write: size of the block I'm sending, LSB (4096-full block size is zero)
|
||||
m-write: size of the block I'm sending, MSB (4096-full block size is zero)
|
||||
a-write: if there's more to send (hasNext)
|
||||
z-write: set if the size is actually 0 instead of 4096
|
||||
z-write: set if the size is actually 0 instead of 4096 (overrides n and m parameters)
|
||||
|
||||
4092..4095 RW: Block transfer control for Port 1 through 4
|
||||
0b 00ms abcd
|
||||
|
||||
@@ -121,6 +121,8 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
|
||||
|
||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||
blockSendBuffer.size % BLOCK_SIZE
|
||||
else if (blockSendBuffer.size <= BLOCK_SIZE)
|
||||
blockSendBuffer.size
|
||||
else BLOCK_SIZE
|
||||
|
||||
// println("blockSendCount = ${blockSendCount}; sendSize = $sendSize; blockSendBuffer.size = ${blockSendBuffer.size}")
|
||||
@@ -147,21 +149,41 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
|
||||
//println("[DiskDrive] writeout with inputdata length of ${inputData.size}")
|
||||
//println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}")
|
||||
|
||||
// println("[TestDiskDrive] (write-payload of ${inputData.size} bytes; $writeBufferUsage out of $writeModeLength bytes has been written so far)")
|
||||
|
||||
|
||||
if (!fileOpen) throw InternalError("File is not open but the drive is in write mode")
|
||||
|
||||
System.arraycopy(inputData, 0, writeBuffer, writeBufferUsage, minOf(writeModeLength - writeBufferUsage, inputData.size, BLOCK_SIZE))
|
||||
writeBufferUsage += inputData.size
|
||||
if (writeModeLength == 0) {
|
||||
// println("[TestDiskDrive] write mode was initiated with zero-byte writing; closing immediately")
|
||||
|
||||
if (writeBufferUsage >= writeModeLength) {
|
||||
// commit to the disk
|
||||
if (appendMode)
|
||||
file.appendBytes(writeBuffer)
|
||||
else if (writeMode)
|
||||
file.writeBytes(writeBuffer)
|
||||
if (writeMode)
|
||||
file.writeBytes(ByteArray(0))
|
||||
|
||||
writeMode = false
|
||||
appendMode = false
|
||||
}
|
||||
else {
|
||||
System.arraycopy(
|
||||
inputData,
|
||||
0,
|
||||
writeBuffer,
|
||||
writeBufferUsage,
|
||||
minOf(writeModeLength - writeBufferUsage, inputData.size, BLOCK_SIZE)
|
||||
)
|
||||
writeBufferUsage += inputData.size
|
||||
|
||||
if (writeBufferUsage >= writeModeLength) {
|
||||
// commit to the disk
|
||||
if (appendMode)
|
||||
file.appendBytes(writeBuffer)
|
||||
else if (writeMode)
|
||||
file.writeBytes(writeBuffer)
|
||||
|
||||
writeMode = false
|
||||
appendMode = false
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fileOpenMode == 17) {
|
||||
if (!fileOpen) throw InternalError("Bootloader file is not open but the drive is in boot write mode")
|
||||
|
||||
@@ -117,6 +117,8 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, theTevdPath:
|
||||
|
||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||
blockSendBuffer.size % BLOCK_SIZE
|
||||
else if (blockSendBuffer.size <= BLOCK_SIZE)
|
||||
blockSendBuffer.size
|
||||
else BLOCK_SIZE
|
||||
|
||||
// println("blockSendCount = ${blockSendCount}; sendSize = $sendSize; blockSendBuffer.size = ${blockSendBuffer.size}")
|
||||
@@ -143,12 +145,17 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, theTevdPath:
|
||||
//println("[DiskDrive] writeout with inputdata length of ${inputData.size}")
|
||||
//println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}")
|
||||
|
||||
println("[TevDiskDrive] write-payload (${inputData.size} bytes)")
|
||||
// println("[TevDiskDrive] (write-payload of ${inputData.size} bytes; $writeBufferUsage out of $writeModeLength bytes has been written so far)")
|
||||
|
||||
|
||||
if (!fileOpen) throw InternalError("File is not open but the drive is in write mode")
|
||||
|
||||
if (writeBuffer.isEmpty()) {
|
||||
if (writeModeLength == 0) {
|
||||
// println("[TevDiskDrive] write mode was initiated with zero-byte writing; closing immediately")
|
||||
|
||||
if (writeMode)
|
||||
file.overwrite(ByteArray(0))
|
||||
|
||||
writeMode = false
|
||||
appendMode = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user