summaryrefslogtreecommitdiff
path: root/src/main/kotlin/Connection.kt
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-09 18:44:09 +0200
committerEdoardo La Greca2025-08-09 18:44:09 +0200
commit8e5b09c28644fba6078728aacf515d1af8c218ba (patch)
tree4dbd51bcd3b777b391dca3315ff11175663bf62e /src/main/kotlin/Connection.kt
parentbedbcf252d63bcbfc3a4de24a5573667d86ca17d (diff)
implement open and add FileMode
Diffstat (limited to 'src/main/kotlin/Connection.kt')
-rw-r--r--src/main/kotlin/Connection.kt23
1 files changed, 21 insertions, 2 deletions
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<QID, UInt> {
+ 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) {