From 8e5b09c28644fba6078728aacf515d1af8c218ba Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Sat, 9 Aug 2025 18:44:09 +0200 Subject: implement open and add FileMode --- src/main/kotlin/Connection.kt | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/main/kotlin/Connection.kt') diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index 6630567..1aeb4b1 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -2,8 +2,10 @@ import except.MsizeValueTooBigException import except.RErrorException import except.UnaccessibleFileException import except.UnknownVersionException +import java.io.File import java.io.IOException import java.math.BigInteger +import kotlin.io.path.Path /** * This class represents a 9P connection. It provides a practical implementation with networking to the 9P methods @@ -182,8 +184,25 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { this.pathInfo.addPath(PathInfo.Path(wname, newfid, qids.last())) } - override fun open(path: String) { - TODO("Not yet implemented") + override fun open(fid: UInt, mode: FileMode): Pair { + val omsg = OutMessage(NinePMessageType.TOPEN, this.tagGen.generate(), listOf("fid", "mode"), + mapOf( + "fid" to BigInteger(fid.toString()), + "mode" to BigInteger(mode.toModeByte().toString()) + ), + emptyMap(), + emptyMap(), + this.maxSize + ) + omsg.write(this.tl) + val imsg = checkedInMessage(omsg.tag) + imsg.applySchema(listOf( + InMessage.Field("qid", InMessage.Field.Type.RAW, 13u), + InMessage.Field("iounit", InMessage.Field.Type.INTEGER, 4u) + )) + val qid = QID(imsg.fieldsRaw["qid"]!!.toList()) + val iounit = imsg.fieldsInt["iounit"]!!.toInt().toUInt() + return Pair(qid, iounit) } override fun create(path: String) { -- cgit v1.2.3