Different return values for functionallity identical calls to openat2
and io_uring_prep_openat2
?
#760
-
I'm writing bindings for liburing to Kotlin Native via ffi, so my below examples will be in Kotlin. I'll heavily comment them but can conjure a C example if necessary. I'm using public suspend fun open(
filePath: String,
directoryFileDescriptor: Int = AT_FDCWD, /* A default parameter of AT_FDCWD. */
flags: Int = 0,
mode: Int = 0,
resolve: Int = 0,
): Int {
val sqe: io_uring_sqe = ring.getSqe() // Get a SQE structure from io_uring
val how = arena.alloc<open_how> { // Allocate some memory for the open_how struct and populate it with flags
// All of these flags will be 0 under test.
this.flags = flags.convert() // Int.convert() will coerce values to what the C API expects -- in this case unsigned values.
this.mode = mode.convert()
this.resolve = resolve.convert()
}
io_uring_prep_openat2(
sqe = sqe.ptr, // A pointer to the SQE
dfd = directoryFileDescriptor, // Under test this values if AT_FDCWD.
path = filePath, // A relative filepath within the CWD of the process.
how = how.ptr, // a pointer to the open_how struct.
)
io_uring_sqe_set_data64(sqe = sqe.ptr, data = /* Some custom data not important in here.*/)
io_uring_submit(ring.ptr)
return /* Async process the CQE and return a value */
} When I run this function I am getting a
This res value if an errno of In contrast, when I perform functionally the same operation via the synchronous val fd = syscall(
SYS_openat2,
AT_FDCWD,
"./src/linuxX64Test/resources/hello.txt",
alloc<open_how> {
this.resolve = 0u
this.flags = 0u
this.resolve = 0u
}.ptr,
sizeOf<open_how>(),
)
val array = allocArray<ByteVar>(100) // Allocate an array of 100 bytes.
read(fd.convert(), array, 100.convert())
println(array.toKStringFromUtf8()) /* Prints "hello world!" */ I am curious to hear why this might be occurring and would appreciate any guidance here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Please do, whatever it'll save us/me some time. |
Beta Was this translation helpful? Give feedback.
Please do, whatever it'll save us/me some time.