diff --git a/lib/TerranVirtualDisk-src.jar b/lib/TerranVirtualDisk-src.jar index 7626feb..26a7087 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 39a526d..81c26a7 100644 Binary files a/lib/TerranVirtualDisk.jar and b/lib/TerranVirtualDisk.jar differ diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt index ff2a4b9..b5d7c39 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt @@ -1,6 +1,8 @@ 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.toCanonicalString import net.torvald.tsvm.VM import java.io.* import java.util.* @@ -141,6 +143,8 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, private val t else { val inputString = inputData.trimNull().toString(VM.CHARSET) + println("[TevDiskDrive] inputString=$inputString") + if (inputString.startsWith("DEVRST\u0017")) { printdbg("Device Reset") //readModeLength = -1 @@ -322,16 +326,25 @@ 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()}") + if (!bootFile.exists()) { + println("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)}") + recipient?.writeout(retMsg) statusCode.set(TestDiskDrive.STATE_CODE_STANDBY) } catch (e: IOException) { + println("exception:") + e.printStackTrace() + statusCode.set(TestDiskDrive.STATE_CODE_SYSTEM_IO_ERROR) return } diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt index 33a1681..6f0dcb1 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdFileDescriptor.kt @@ -9,18 +9,23 @@ import java.io.IOException */ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { - val path = _pathstr.replace('/', '\\') + val path = _pathstr.replace('\\', '/') val vdPath = VDUtil.VDPath(path, VM.CHARSET) val entryID: EntryID? get() = VDUtil.getFile(DOM, vdPath)?.entryID - val canonicalPath: String - get() = path - val name: String - get() = path.substring(path.lastIndexOf('\\') + 1) - val nameBytes: ByteArray - get() = name.toByteArray(VM.CHARSET) + val canonicalPath = path.replace('/', '\\') + + /*init { + println("$path's vdPath:") + vdPath.hierarchy.forEach { + 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 @@ -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 */ fun getHeadBytes64(length: Long): ByteArray64 { - if (fileContent == null) throw IOException("No such file or not a file") - return fileContent!!.getContent().sliceArray64(0L until length) + if (isDirectory) throw RuntimeException("Not a file") + 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 * @return actual bytes read, the size may be less than `length` if the actual file size is smaller */ fun getHeadBytes(length: Int): ByteArray { - if (fileContent == null) throw IOException("No such file or not a file") - return fileContent!!.getContent().sliceArray(0 until length) + if (isDirectory) throw RuntimeException("Not a file") + 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 { @@ -78,7 +95,7 @@ class TevdFileDescriptor(val DOM: VirtualDisk, _pathstr: String) { if (it == null) return null return VDUtil.getDirectoryEntries(DOM, it).map { - TevdFileDescriptor(DOM, path + '\\' + it.getFilenameString(VM.CHARSET)) + TevdFileDescriptor(DOM, path + '/' + it.getFilenameString(VM.CHARSET)) }.toTypedArray() } }