From 7b49a4c587eaaee3d071ad12aaeb54ac302d06fa Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Thu, 7 Aug 2025 17:27:53 +0200 Subject: add walk and change fids to pathInfo in Connection --- src/main/kotlin/Connection.kt | 51 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index b308402..13b928d 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -31,9 +31,9 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { private var maxSize: UInt = 0u /** - * Info about FIDs. + * Info about remote paths. */ - val fids: FIDInfo = FIDInfo() + val pathInfo: PathInfo = PathInfo() // 9P constants. val DEFAULT_VERSION = "9P2000" @@ -115,11 +115,52 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { } override fun attach() { - TODO("Not yet implemented") + } - override fun walk(path: String) { - TODO("Not yet implemented") + override fun walk(fid: UInt, newfid: UInt, wname: List): String? { + val nwname = wname.size + val omsg = OutMessage(NinePMessageType.TWALK, this.tagGen.generate(), listOf("fid", "newfid", "nwname"), + mapOf( + "fid" to BigInteger(fid.toString()), + "newfid" to BigInteger(newfid.toString()), + "nwname" to BigInteger(nwname.toString()) + ), + emptyMap(), + emptyMap(), + this.maxSize + ) + omsg.write(this.tl) + for (wn in wname) { // write wname elements + OutMessage.writeString(this.tl, wn) + } + val checkErr = checkedInMessage(omsg.tag) + if (checkErr.first != null) { + return checkErr.first + } + val imsg = checkErr.second!! + + imsg.applyField(InMessage.Field("nwqid", InMessage.Field.Type.INTEGER, 2u)) + val nwqid = imsg.fieldsInt["nwqid"]!!.toInt() + if (nwqid < nwname) { + return "cannot access ${wname.slice(0..nwqid).joinToString(separator = "/")}" + } + imsg.applyField(InMessage.Field("qids", InMessage.Field.Type.RAW, (nwqid * 13).toUInt())) + val rawQids = imsg.fieldsRaw["qids"]!! + val qids: MutableList = mutableListOf() + for (i in 0..