From f7113c94abce7deec8bece794a3748cbee8a9a08 Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Thu, 7 Aug 2025 18:40:35 +0200 Subject: implement attach --- src/main/kotlin/Connection.kt | 24 +++++++++++++++++++++++- src/main/kotlin/ProtocolTranslator.kt | 8 +++++++- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index 13b928d..a7de8cc 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -114,8 +114,30 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { TODO("Not yet implemented") } - override fun attach() { + override fun attach(fid: UInt, afid: UInt, uname: String, aname: String): String? { + val omsg = OutMessage(NinePMessageType.TATTACH, this.tagGen.generate(), listOf("fid", "afid", "uname", "aname"), + mapOf( + "fid" to BigInteger(fid.toString()), + "afid" to BigInteger(afid.toString()) + ), + mapOf( + "uname" to uname, + "aname" to aname + ), + emptyMap(), + this.maxSize + ) + omsg.write(this.tl) + val checkErr = checkedInMessage(omsg.tag) + if (checkErr.first != null) { + return checkErr.first + } + val imsg = checkErr.second!! + imsg.applyField(InMessage.Field("qid", InMessage.Field.Type.RAW, 13u)) + val qid = QID(imsg.fieldsRaw["qid"]!!.toList()) + this.pathInfo.addPath(PathInfo.Path(aname.split("/"), fid, qid)) + return null } override fun walk(fid: UInt, newfid: UInt, wname: List): String? { diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt index 0cdfa53..4dad240 100644 --- a/src/main/kotlin/ProtocolTranslator.kt +++ b/src/main/kotlin/ProtocolTranslator.kt @@ -43,8 +43,14 @@ interface ProtocolTranslator { /** * Establish a connection. + * + * @param fid FID that represents the root directory of the desired file tree. + * @param afid A FID previously established by an auth message. + * @param uname A user identifier. + * @param aname The desired file tree to access. + * @return a possible error. */ - fun attach() + fun attach(fid: UInt, afid: UInt, uname: String, aname: String): String? /** * Descend a directory hierarchy. -- cgit v1.2.3