From 8483439a7960e60d0c9b813b308106beb04b14af Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 20 Dec 2022 21:41:44 +0900 Subject: [PATCH] showing disk usage on DIR command --- assets/disk0/tvdos/bin/command.js | 26 +++++++++++++++++++ .../torvald/tsvm/peripheral/TestDiskDrive.kt | 4 +++ .../torvald/tsvm/peripheral/TevdDiskDrive.kt | 4 +++ 3 files changed, 34 insertions(+) diff --git a/assets/disk0/tvdos/bin/command.js b/assets/disk0/tvdos/bin/command.js index 4393eac..c0aff8a 100644 --- a/assets/disk0/tvdos/bin/command.js +++ b/assets/disk0/tvdos/bin/command.js @@ -373,10 +373,36 @@ shell.coreutils = { let currentDir = files.open(`${CURRENT_DRIVE}:\\${currentPath}`) let fileList = currentDir.list() + let fileCnt = 0 + let dirCnt = 0 + println(`Current directory: ${currentDir.fullPath}`) fileList.forEach(it => { println(`${it.name.padEnd(termWidth / 2, ' ')}${it.size}`) + if (it.isDirectory) + dirCnt += 1 + else + fileCnt += 1 }) + + + // print file/dir count + println(`\n${fileCnt} Files, ${dirCnt} Directories`) + + // print disk usage, if available + if (currentDir.driverID == "SERIAL") { + let port = _TVDOS.DRV.FS.SERIAL._toPorts(currentDir.driveLetter) + _TVDOS.DRV.FS.SERIAL._flush(port[0]);_TVDOS.DRV.FS.SERIAL._close(port[0]) + com.sendMessage(port[0], "USAGE") + let response = com.getStatusCode(port[0]) + if (0 == response) { + let rawStr = com.fetchResponse(port[0]).split('/') // USED1234/TOTAL23412341 + let usedBytes = (rawStr[0].substring(4))|0 + let totalBytes = (rawStr[1].substring(5))|0 + let freeBytes = totalBytes - usedBytes + println(`Disk used ${usedBytes} bytes, ${freeBytes} bytes free of ${totalBytes} bytes`) + } + } }, del: function(args) { if (args[1] === undefined) { diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt index 0185203..55b09f2 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TestDiskDrive.kt @@ -417,6 +417,10 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath: writeBufferUsage = 0 statusCode.set(STATE_CODE_STANDBY) } + else if (inputString.startsWith("USAGE")) { + recipient?.writeout(composePositiveAns("USED123456/TOTAL654321")) + statusCode.set(STATE_CODE_STANDBY) + } else statusCode.set(STATE_CODE_ILLEGAL_COMMAND) } diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt index a73c2d1..e0f8799 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/TevdDiskDrive.kt @@ -420,6 +420,10 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, private val t writeBufferUsage = 0 statusCode.set(TestDiskDrive.STATE_CODE_STANDBY) } + else if (inputString.startsWith("USAGE")) { + recipient?.writeout(TestDiskDrive.composePositiveAns("USED${DOM.usedBytes}/TOTAL${DOM.capacity}")) + statusCode.set(TestDiskDrive.STATE_CODE_STANDBY) + } else statusCode.set(TestDiskDrive.STATE_CODE_ILLEGAL_COMMAND) }