mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-06 05:28:31 +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
|
akku += delta
|
||||||
while (akku > interval) {
|
while (akku > interval) {
|
||||||
consumeMessages()
|
consumeMessages()
|
||||||
println("[${this.javaClass.simpleName}] boop!")
|
// println("[${this.javaClass.simpleName}] boop!")
|
||||||
akku -= interval
|
akku -= interval
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ object TevdSyncWatchdog : VMWatchdog() {
|
|||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
messageQueue.forEach { (outfile, dom) ->
|
messageQueue.forEach { (outfile, dom) ->
|
||||||
VDUtil.dumpToRealMachine(dom, outfile)
|
VDUtil.dumpToRealMachine(dom, outfile)
|
||||||
println("[${this.javaClass.simpleName}] dump ${outfile.path}")
|
// println("[${this.javaClass.simpleName}] dump ${outfile.path}")
|
||||||
}
|
}
|
||||||
messageQueue.clear()
|
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) {
|
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)
|
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.
|
* Disk drive must create desired side effects in accordance with the input message.
|
||||||
*/
|
*/
|
||||||
override fun writeoutImpl(inputData: ByteArray) {
|
override fun writeoutImpl(inputData: ByteArray) {
|
||||||
println("[TevDiskDrive] inputString=${inputData.trimNull().toString(VM.CHARSET)}")
|
printdbg("inputString=${inputData.trimNull().toString(VM.CHARSET)}")
|
||||||
|
|
||||||
if (writeMode || appendMode) {
|
if (writeMode || appendMode) {
|
||||||
//println("[DiskDrive] writeout with inputdata length of ${inputData.size}")
|
//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")
|
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()) {
|
if (!bootFile.exists()) {
|
||||||
println("bootfile not exists!")
|
printdbg("bootfile not exists!")
|
||||||
statusCode.set(TestDiskDrive.STATE_CODE_NO_SUCH_FILE_EXISTS)
|
statusCode.set(TestDiskDrive.STATE_CODE_NO_SUCH_FILE_EXISTS)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
val retMsg = bootFile.getHeadBytes(BLOCK_SIZE)
|
val retMsg = bootFile.getHeadBytes(BLOCK_SIZE)
|
||||||
|
|
||||||
println("retMsg = ${retMsg.toString(VM.CHARSET)}")
|
printdbg("retMsg = ${retMsg.toString(VM.CHARSET)}")
|
||||||
|
|
||||||
recipient?.writeout(retMsg)
|
recipient?.writeout(retMsg)
|
||||||
statusCode.set(TestDiskDrive.STATE_CODE_STANDBY)
|
statusCode.set(TestDiskDrive.STATE_CODE_STANDBY)
|
||||||
}
|
}
|
||||||
catch (e: IOException) {
|
catch (e: IOException) {
|
||||||
println("exception:")
|
printdbg("exception:")
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|
||||||
statusCode.set(TestDiskDrive.STATE_CODE_SYSTEM_IO_ERROR)
|
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) }
|
get() = entryID.let { if (it == null) false else VDUtil.isDirectoryFollowSymlink(DOM, it) }
|
||||||
|
|
||||||
|
|
||||||
private var fileContent: EntryFile? = null
|
|
||||||
|
|
||||||
fun appendBytes(bytes: ByteArray) {
|
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) {
|
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 (isDirectory) throw RuntimeException("Not a file")
|
||||||
if (!exists()) throw IOException("File not found")
|
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))
|
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 (isDirectory) throw RuntimeException("Not a file")
|
||||||
if (!exists()) throw IOException("File not found")
|
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())
|
it.sliceArray(0 until minOf(length.toLong(), it.size).toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,12 +82,11 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun delete() {
|
fun delete() {
|
||||||
fileContent = null
|
|
||||||
VDUtil.deleteFile(DOM, vdPath)
|
VDUtil.deleteFile(DOM, vdPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun length(): Long {
|
fun length(): Long {
|
||||||
return if (isFile) fileContent?.getSizePure() ?: 0L
|
return if (isFile) VDUtil.getAsNormalFileOrNull(DOM, vdPath)?.getSizePure() ?: 0L
|
||||||
else -1L
|
else -1L
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +119,9 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createNewFile(): Boolean {
|
fun createNewFile(): Boolean {
|
||||||
fileContent = EntryFile(ByteArray64())
|
val fileContent = EntryFile(ByteArray64())
|
||||||
val time_t = System.currentTimeMillis() / 1000
|
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 {
|
return try {
|
||||||
VDUtil.addFile(DOM, vdPath.getParent(), newFile)
|
VDUtil.addFile(DOM, vdPath.getParent(), newFile)
|
||||||
true
|
true
|
||||||
|
|||||||
Reference in New Issue
Block a user