diff options
author | Edoardo La Greca | 2025-08-09 21:07:53 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-09 21:07:53 +0200 |
commit | 48922ff78c0b82be4b52c3221cb408ff01951190 (patch) | |
tree | b0e792c60df4bc2790ce2766bf201544b27ddb9d | |
parent | c69d08ab05a044eb6b6135739de77b0711ebbdd3 (diff) |
implement create
-rw-r--r-- | src/main/kotlin/Connection.kt | 24 | ||||
-rw-r--r-- | src/main/kotlin/ProtocolTranslator.kt | 13 |
2 files changed, 34 insertions, 3 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index 587f5ee..d5330d7 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -193,8 +193,28 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { return Pair(qid, iounit) } - override fun create(path: String) { - TODO("Not yet implemented") + override fun create(fid: UInt, name: String, perm: FilePermissions, mode: FileMode): Pair<QID, UInt> { + val omsg = OutMessage(NinePMessageType.TCREATE, this.tagGen.generate(), listOf("fid", "name", "perm", "mode"), + mapOf( + "fid" to Pair(BigInteger(fid.toString()), 4u), + "perm" to Pair(BigInteger(perm.toPermissionInt().toString()), 4u), + "mode" to Pair(BigInteger(mode.toModeByte().toString()), 1u) + ), + mapOf( + "name" to name + ), + emptyMap(), + this.maxSize + ) + omsg.write(this.tl) + val imsg = checkedInMessage(omsg.tag) + imsg.applySchema(listOf( + InMessage.Field("qid", InMessage.Field.Type.RAW, 13u), + InMessage.Field("iounit", InMessage.Field.Type.INTEGER, 4u) + )) + val qid = QID(imsg.fieldsRaw["qid"]!!.toList()) + val iounit = imsg.fieldsInt["iounit"]!!.toInt().toUInt() + return Pair(qid, iounit) } override fun read(fid: UInt, offset: ULong, count: UInt): Array<UByte> { diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt index c023dd6..8623737 100644 --- a/src/main/kotlin/ProtocolTranslator.kt +++ b/src/main/kotlin/ProtocolTranslator.kt @@ -90,8 +90,19 @@ interface ProtocolTranslator { /** * Prepare an FID for I/O on a new file. + * + * @param fid The FID of the directory that is going to contain the file. The specified directory requires write + * permission. + * @param name The file name. + * @param perm The permissions of the new file. + * @param mode The open mode after successful creation. + * @return A pair of: (1) the QID of the newly created file, and (2) a value called `iounit` that indicates, if + * non-zero, the maximum number of bytes that are guaranteed to be read from or written to the file without breaking + * the I/O transfer into multiple 9P messages. + * @throws except.InvalidMessageException if the received message is invalid. + * @throws except.RErrorException if the received message is an R-error message. */ - fun create(path: String) + fun create(fid: UInt, name: String, perm: FilePermissions, mode: FileMode): Pair<QID, UInt> /** * Transfer data from file. Due to the negotiated maximum size of 9P messages, called `msize`, one is supposed to |