can read TEVD but not modify

This commit is contained in:
minjaesong
2022-12-18 02:31:17 +09:00
parent e1e1a2f5db
commit 5fa195800c
4 changed files with 42 additions and 12 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,6 +1,8 @@
package net.torvald.tsvm.peripheral package net.torvald.tsvm.peripheral
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.EntryDirectory
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VDUtil import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VDUtil
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toCanonicalString
import net.torvald.tsvm.VM import net.torvald.tsvm.VM
import java.io.* import java.io.*
import java.util.* import java.util.*
@@ -141,6 +143,8 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, private val t
else { else {
val inputString = inputData.trimNull().toString(VM.CHARSET) val inputString = inputData.trimNull().toString(VM.CHARSET)
println("[TevDiskDrive] inputString=$inputString")
if (inputString.startsWith("DEVRST\u0017")) { if (inputString.startsWith("DEVRST\u0017")) {
printdbg("Device Reset") printdbg("Device Reset")
//readModeLength = -1 //readModeLength = -1
@@ -322,16 +326,25 @@ 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()}")
if (!bootFile.exists()) { if (!bootFile.exists()) {
println("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)}")
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:")
e.printStackTrace()
statusCode.set(TestDiskDrive.STATE_CODE_SYSTEM_IO_ERROR) statusCode.set(TestDiskDrive.STATE_CODE_SYSTEM_IO_ERROR)
return return
} }

View File

@@ -9,18 +9,23 @@ import java.io.IOException
*/ */
class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
val path = _pathstr.replace('/', '\\') val path = _pathstr.replace('\\', '/')
val vdPath = VDUtil.VDPath(path, VM.CHARSET) val vdPath = VDUtil.VDPath(path, VM.CHARSET)
val entryID: EntryID? val entryID: EntryID?
get() = VDUtil.getFile(DOM, vdPath)?.entryID get() = VDUtil.getFile(DOM, vdPath)?.entryID
val canonicalPath: String val canonicalPath = path.replace('/', '\\')
get() = path
val name: String /*init {
get() = path.substring(path.lastIndexOf('\\') + 1) println("$path's vdPath:")
val nameBytes: ByteArray vdPath.hierarchy.forEach {
get() = name.toByteArray(VM.CHARSET) println(" ${it.toCanonicalString(VM.CHARSET)} [${it.joinToString(" ") { it.toString(16).padStart(2, '0') } }]")
}
}*/
val nameBytes = if (vdPath.hierarchy.isEmpty()) ByteArray(DiskEntry.NAME_LENGTH) else vdPath.last()
val name = nameBytes.toCanonicalString(VM.CHARSET)
val isFile: Boolean val isFile: Boolean
@@ -45,16 +50,28 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
* @return actual bytes read, the size may be less than `length` if the actual file size is smaller * @return actual bytes read, the size may be less than `length` if the actual file size is smaller
*/ */
fun getHeadBytes64(length: Long): ByteArray64 { fun getHeadBytes64(length: Long): ByteArray64 {
if (fileContent == null) throw IOException("No such file or not a file") if (isDirectory) throw RuntimeException("Not a file")
return fileContent!!.getContent().sliceArray64(0L until length) if (!exists()) throw IOException("File not found")
if (fileContent == null) fileContent = VDUtil.getAsNormalFile(DOM, vdPath)
return fileContent!!.getContent().let {
it.sliceArray64(0L until minOf(length, it.size))
}
} }
/** /**
* @param length how many bytes to read * @param length how many bytes to read
* @return actual bytes read, the size may be less than `length` if the actual file size is smaller * @return actual bytes read, the size may be less than `length` if the actual file size is smaller
*/ */
fun getHeadBytes(length: Int): ByteArray { fun getHeadBytes(length: Int): ByteArray {
if (fileContent == null) throw IOException("No such file or not a file") if (isDirectory) throw RuntimeException("Not a file")
return fileContent!!.getContent().sliceArray(0 until length) if (!exists()) throw IOException("File not found")
if (fileContent == null) fileContent = VDUtil.getAsNormalFile(DOM, vdPath)
return fileContent!!.getContent().let {
it.sliceArray(0 until minOf(length.toLong(), it.size).toInt())
}
} }
fun exists(): Boolean { fun exists(): Boolean {
@@ -78,7 +95,7 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) {
if (it == null) return null if (it == null) return null
return VDUtil.getDirectoryEntries(DOM, it).map { return VDUtil.getDirectoryEntries(DOM, it).map {
TevdFileDescriptor(DOM, path + '\\' + it.getFilenameString(VM.CHARSET)) TevdFileDescriptor(DOM, path + '/' + it.getFilenameString(VM.CHARSET))
}.toTypedArray() }.toTypedArray()
} }
} }