summaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/Connection.kt51
1 files 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>): 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<QID> = mutableListOf()
+ for (i in 0..<nwqid/13) {
+ val start = i * 13
+ val end = ((i+1) * 13) - 1
+ 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 null
}
override fun open(path: String) {