summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-06 21:41:38 +0200
committerEdoardo La Greca2025-08-06 21:42:15 +0200
commit59e3a9e23cb2e81cb1a5ffd044b57538b3071e6c (patch)
tree2b5fb54b45b789eb6bede4a511d1e6969567024a /src/main
parent49750d70be34302b30808a34dc0df0a39ada8912 (diff)
add FIDInfo
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/Connection.kt4
-rw-r--r--src/main/kotlin/FIDInfo.kt42
2 files changed, 44 insertions, 2 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt
index 6444ade..b916d1b 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
/**
- * Each FID associated with each file.
+ * Info about FIDs.
*/
- val fids: Map<UInt, String> = emptyMap()
+ val fids: FIDInfo = FIDInfo()
// 9P constants.
val DEFAULT_VERSION = "9P2000"
diff --git a/src/main/kotlin/FIDInfo.kt b/src/main/kotlin/FIDInfo.kt
new file mode 100644
index 0000000..dbbc945
--- /dev/null
+++ b/src/main/kotlin/FIDInfo.kt
@@ -0,0 +1,42 @@
+/**
+ * This class holds all info about File IDs (FIDs).
+ */
+class FIDInfo() {
+ private val inUse: MutableSet<FID> = mutableSetOf()
+
+ /**
+ * A single FID.
+ *
+ * @param fid The actual FID value.
+ * @param path The path of the FID, represented as successive path name elements.
+ * @param qid The QID associated with the FID.
+ */
+ data class FID(val fid: UInt, val path: List<String>, val qid: QID)
+
+ /**
+ * Add a FID with the associated file path and QID.
+ */
+ fun addFID(fid: FID) {
+ this.inUse.add(fid)
+ }
+
+ /**
+ * Find the path associated to a FID.
+ *
+ * @param fid The FID to find the path of.
+ * @return The path if [fid] could be found, or null otherwise.
+ */
+ fun findPathByFID(fid: UInt): List<String>? {
+ return this.inUse.find { x -> x.fid == fid }?.path
+ }
+
+ /**
+ * Find the FID associated to a path.
+ *
+ * @param path The path to find the FID of.
+ * @return The FID if [path] has an associated FID, or null otherwise.
+ */
+ fun findFIDByPath(path: List<String>): UInt? {
+ return this.inUse.find { x -> x.path == path }?.fid
+ }
+} \ No newline at end of file