diff options
author | Edoardo La Greca | 2025-08-09 19:30:21 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-09 19:30:21 +0200 |
commit | 31c4a211c483363bd254d41c3451e98116b05c4a (patch) | |
tree | d15d4b77d65fe6a250b113ee5b5be395ba8bf6c4 | |
parent | 5316ed0c6e4200195c6031651e285f61bb1424ab (diff) |
remove fid and qid management from Connection and return them in ProtocolTranslator methods
-rw-r--r-- | src/main/kotlin/Connection.kt | 22 | ||||
-rw-r--r-- | src/main/kotlin/ProtocolTranslator.kt | 10 |
2 files changed, 11 insertions, 21 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index 1aeb4b1..9b5af33 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -2,10 +2,8 @@ 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 @@ -36,11 +34,6 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { */ private var maxSize: UInt = 0u - /** - * Info about remote paths. - */ - val pathInfo: PathInfo = PathInfo() - // 9P constants. val DEFAULT_VERSION = "9P2000" val NOTAG = 0.toUShort().inv() @@ -123,7 +116,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { val imsg = checkedInMessage(omsg.tag) } - override fun attach(fid: UInt, afid: UInt, uname: String, aname: String) { + override fun attach(fid: UInt, afid: UInt, uname: String, aname: String): QID { val omsg = OutMessage(NinePMessageType.TATTACH, this.tagGen.generate(), listOf("fid", "afid", "uname", "aname"), mapOf( "fid" to BigInteger(fid.toString()), @@ -141,10 +134,10 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { 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 qid } - override fun walk(fid: UInt, newfid: UInt, wname: List<String>) { + override fun walk(fid: UInt, newfid: UInt, wname: List<String>): List<QID> { val nwname = wname.size val omsg = OutMessage(NinePMessageType.TWALK, this.tagGen.generate(), listOf("fid", "newfid", "nwname"), mapOf( @@ -165,7 +158,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { imsg.applyField(InMessage.Field("nwqid", InMessage.Field.Type.INTEGER, 2u)) val nwqid = imsg.fieldsInt["nwqid"]!!.toInt() if (nwqid < nwname) { - throw UnaccessibleFileException(wname.slice(0..nwqid).joinToString(separator = "/")) + throw UnaccessibleFileException(wname.slice(0..nwqid)) } imsg.applyField(InMessage.Field("qids", InMessage.Field.Type.RAW, (nwqid * 13).toUInt())) val rawQids = imsg.fieldsRaw["qids"]!! @@ -176,12 +169,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { val rawQid = rawQids.slice(start..end) qids += QID(rawQid) } - - for (i in 0..<nwname) { - this.pathInfo.addPath(PathInfo.Path(wname.slice(0..<i), null, qids[i])) - } - this.pathInfo.removeFID(fid) - this.pathInfo.addPath(PathInfo.Path(wname, newfid, qids.last())) + return qids.toList() } override fun open(fid: UInt, mode: FileMode): Pair<QID, UInt> { diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt index b3674f1..c023dd6 100644 --- a/src/main/kotlin/ProtocolTranslator.kt +++ b/src/main/kotlin/ProtocolTranslator.kt @@ -9,7 +9,7 @@ TODO: * Every method that can fail, that is, every request that can receive a response with `Rerror` type instead of the same * type as itself, returns a non-null `String` that contains the error message received in the response. * - * Tags, FIDs, QIDs, and the `msize` value are supposed to be managed internally by the implementing class. + * Tags and the `msize` value are supposed to be managed internally by the implementing class. * * When compared to 9P's formal message descriptions, like those which can be read in Plan 9's manual pages, some of the * methods might lack parameters. Those which can be inferred from the existing parameters are purposefully omitted. An @@ -55,10 +55,11 @@ interface ProtocolTranslator { * @param afid A FID previously established by an auth message. * @param uname A user identifier. * @param aname The desired file tree to access. + * @return The QID of the file tree's root. * @throws except.InvalidMessageException if the received message is invalid. * @throws except.RErrorException if the received message is an R-error message. */ - fun attach(fid: UInt, afid: UInt, uname: String, aname: String) + fun attach(fid: UInt, afid: UInt, uname: String, aname: String): QID /** * Descend a directory hierarchy. @@ -67,11 +68,12 @@ interface ProtocolTranslator { * @param newfid The proposed FID, which is going to be associated with the result of walking the hierarchy. It must * be not in use, unless it is the same as [fid]. * @param wname The successive path name elements which describe the file to walk to. + * @return The QID of each path element that has been walked through. * @throws except.InvalidMessageException if the received message is invalid. * @throws except.RErrorException if the received message is an R-error message. - * @throws except.UnaccessibleFileException if [wname] contains one or more files that do not exist. + * @throws except.UnaccessibleFileException if [wname] contains one or more path elements that do not exist. */ - fun walk(fid: UInt, newfid: UInt, wname: List<String>) + fun walk(fid: UInt, newfid: UInt, wname: List<String>): List<QID> /** * Prepare an FID for I/O on an existing file. |