summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-10 16:49:28 +0200
committerEdoardo La Greca2025-08-10 16:49:28 +0200
commit46dd60cf23faaa9892ed802e3e7cbc630d648ae4 (patch)
tree4abe4ae3bbb5200fffa96c7f5fac379394f67588
parent5aff4f23638ee0968f9cc1bb5e9c397fe6b5cc0e (diff)
implement stat
-rw-r--r--src/main/kotlin/Connection.kt59
-rw-r--r--src/main/kotlin/ProtocolTranslator.kt6
2 files changed, 62 insertions, 3 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt
index 5db6b51..8908364 100644
--- a/src/main/kotlin/Connection.kt
+++ b/src/main/kotlin/Connection.kt
@@ -284,8 +284,63 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator {
val imsg = checkedInMessage(omsg.tag)
}
- override fun stat(path: String) {
- TODO("Not yet implemented")
+ override fun stat(fid: UInt): Stat {
+ val omsg = OutMessage(NinePMessageType.TSTAT, this.tagGen.generate(), listOf("fid"),
+ mapOf(
+ "fid" to Pair(BigInteger(fid.toString()), 4u)
+ ),
+ emptyMap(),
+ emptyMap(),
+ this.maxSize
+ )
+ omsg.write(this.tl)
+ val imsg = checkedInMessage(omsg.tag)
+ imsg.applyField(InMessage.Field("nstat", InMessage.Field.Type.INTEGER, 2u))
+ val nstat = imsg.fieldsInt["nstat"]!!.toInt().toUInt()
+ imsg.applyField(InMessage.Field("stat", InMessage.Field.Type.RAW, nstat))
+ val rawStat = imsg.fieldsRaw["stat"]!!.toList()
+
+ var offset = 0
+ val qid = QID(rawStat.slice(0..<13))
+ offset += 13
+ val mode = FilePermissions(rawStat.slice(offset+0..<offset+4))
+ offset += 4
+
+ val intFielSizes = listOf(4, 4, 8)
+ val intFields: MutableList<BigInteger> = mutableListOf()
+ for (size in intFielSizes) {
+ intFields.add(InMessage.convInteger(rawStat, offset, size))
+ offset += size
+ }
+ val atime = intFields[0].toInt().toUInt()
+ val mtime = intFields[1].toInt().toUInt()
+ val length = intFields[2].toLong().toULong()
+
+ val strAmount = 4
+ val strFields: MutableList<String> = mutableListOf()
+ for (i in 0..strAmount) {
+ val str = InMessage.convString(rawStat, offset)
+ strFields.add(str)
+ offset += str.length
+ }
+ val name = strFields[0]
+ val uid = strFields[1]
+ val gid = strFields[2]
+ val muid = strFields[3]
+
+ val stat = Stat(
+ fid,
+ qid,
+ mode,
+ atime,
+ mtime,
+ length,
+ name,
+ uid,
+ gid,
+ muid
+ )
+ return stat
}
override fun wstat(path: String) {
diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt
index 5148120..1ec4379 100644
--- a/src/main/kotlin/ProtocolTranslator.kt
+++ b/src/main/kotlin/ProtocolTranslator.kt
@@ -147,8 +147,12 @@ interface ProtocolTranslator {
/**
* Inquire file attributes.
+ *
+ * @param fid The FID of the file to inquire.
+ * @return All the file attributes of the file associated with [fid].
+ *
*/
- fun stat(path: String)
+ fun stat(fid: UInt): Stat
/**
* Change file attributes.