diff --git a/lib/TerranVirtualDisk-src.jar b/lib/TerranVirtualDisk-src.jar index 26a7087..9b335a4 100644 Binary files a/lib/TerranVirtualDisk-src.jar and b/lib/TerranVirtualDisk-src.jar differ diff --git a/lib/TerranVirtualDisk.jar b/lib/TerranVirtualDisk.jar index 81c26a7..7f047ca 100644 Binary files a/lib/TerranVirtualDisk.jar and b/lib/TerranVirtualDisk.jar differ diff --git a/tsvm_core/src/net/torvald/tsvm/VMWatchdog.kt b/tsvm_core/src/net/torvald/tsvm/VMWatchdog.kt index dccad6f..ce6bd1d 100644 --- a/tsvm_core/src/net/torvald/tsvm/VMWatchdog.kt +++ b/tsvm_core/src/net/torvald/tsvm/VMWatchdog.kt @@ -18,7 +18,7 @@ abstract class VMWatchdog { akku += delta while (akku > interval) { consumeMessages() - println("[${this.javaClass.simpleName}] boop!") +// println("[${this.javaClass.simpleName}] boop!") akku -= interval } } @@ -38,7 +38,7 @@ object TevdSyncWatchdog : VMWatchdog() { synchronized(this) { messageQueue.forEach { (outfile, dom) -> VDUtil.dumpToRealMachine(dom, outfile) - println("[${this.javaClass.simpleName}] dump ${outfile.path}") +// println("[${this.javaClass.simpleName}] dump ${outfile.path}") } messageQueue.clear() } diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt index c223da6..a73c2d1 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt @@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicBoolean class TevdDiskDrive(private val vm: VM, private val driveNum: Int, private val theTevdPath: String, val diskUUIDstr: String) : BlockTransferInterface(false, true) { - private val DBGPRN = true + private val DBGPRN = false val diskID: UUID = UUID.fromString(diskUUIDstr) @@ -95,7 +95,7 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, private val t * Disk drive must create desired side effects in accordance with the input message. */ override fun writeoutImpl(inputData: ByteArray) { - println("[TevDiskDrive] inputString=${inputData.trimNull().toString(VM.CHARSET)}") + printdbg("inputString=${inputData.trimNull().toString(VM.CHARSET)}") if (writeMode || appendMode) { //println("[DiskDrive] writeout with inputdata length of ${inputData.size}") @@ -305,23 +305,23 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, private val t val bootFile = TevdFileDescriptor(DOM, "!BOOTSEC") - println("bootFile = $bootFile, ID: ${bootFile.entryID}, exists = ${bootFile.exists()}") + printdbg("bootFile = $bootFile, ID: ${bootFile.entryID}, exists = ${bootFile.exists()}") if (!bootFile.exists()) { - println("bootfile not exists!") + printdbg("bootfile not exists!") statusCode.set(TestDiskDrive.STATE_CODE_NO_SUCH_FILE_EXISTS) return } try { val retMsg = bootFile.getHeadBytes(BLOCK_SIZE) - println("retMsg = ${retMsg.toString(VM.CHARSET)}") + printdbg("retMsg = ${retMsg.toString(VM.CHARSET)}") recipient?.writeout(retMsg) statusCode.set(TestDiskDrive.STATE_CODE_STANDBY) } catch (e: IOException) { - println("exception:") + printdbg("exception:") e.printStackTrace() statusCode.set(TestDiskDrive.STATE_CODE_SYSTEM_IO_ERROR) diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt index 6f0dcb1..33d0b6c 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt @@ -35,14 +35,17 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { get() = entryID.let { if (it == null) false else VDUtil.isDirectoryFollowSymlink(DOM, it) } - private var fileContent: EntryFile? = null - fun appendBytes(bytes: ByteArray) { - fileContent?.getContent()?.appendBytes(bytes) + val fileContent = VDUtil.getAsNormalFile(DOM, vdPath) // this is not an object properties: the reference to the file may have been changed + fileContent.getContent().appendBytes(bytes) } fun writeBytes(bytes: ByteArray) { - fileContent?.replaceContent(ByteArray64.fromByteArray(bytes)) + val fileContent = VDUtil.getAsNormalFile(DOM, vdPath) +// println("[TevdFileDesc] ${path} writing ${bytes.size} bytes...") +// println("Old: ${fileContent.getContent().toByteArray().toString(VM.CHARSET)}") + fileContent.replaceContent(ByteArray64.fromByteArray(bytes)) +// println("New: ${fileContent.getContent().toByteArray().toString(VM.CHARSET)}") } /** @@ -53,9 +56,9 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { if (isDirectory) throw RuntimeException("Not a file") if (!exists()) throw IOException("File not found") - if (fileContent == null) fileContent = VDUtil.getAsNormalFile(DOM, vdPath) + val fileContent = VDUtil.getAsNormalFile(DOM, vdPath) - return fileContent!!.getContent().let { + return fileContent.getContent().let { it.sliceArray64(0L until minOf(length, it.size)) } } @@ -67,9 +70,9 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { if (isDirectory) throw RuntimeException("Not a file") if (!exists()) throw IOException("File not found") - if (fileContent == null) fileContent = VDUtil.getAsNormalFile(DOM, vdPath) + val fileContent = VDUtil.getAsNormalFile(DOM, vdPath) - return fileContent!!.getContent().let { + return fileContent.getContent().let { it.sliceArray(0 until minOf(length.toLong(), it.size).toInt()) } } @@ -79,12 +82,11 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { } fun delete() { - fileContent = null VDUtil.deleteFile(DOM, vdPath) } fun length(): Long { - return if (isFile) fileContent?.getSizePure() ?: 0L + return if (isFile) VDUtil.getAsNormalFileOrNull(DOM, vdPath)?.getSizePure() ?: 0L else -1L } @@ -117,9 +119,9 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { } fun createNewFile(): Boolean { - fileContent = EntryFile(ByteArray64()) + val fileContent = EntryFile(ByteArray64()) val time_t = System.currentTimeMillis() / 1000 - val newFile = DiskEntry(-1, -1, nameBytes, time_t, time_t, fileContent!!) + val newFile = DiskEntry(-1, -1, nameBytes, time_t, time_t, fileContent) return try { VDUtil.addFile(DOM, vdPath.getParent(), newFile) true