mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
finally editable tevd
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user