How can I read at the position relative to end of the file via IoUring? I have a file that contains the metadata in the end of the file because of single pass writing. Now, I want to read the file via IoUring for efficiency, therefore I have to read the metadata in the first step.
Read it via blocking IO is simple, we can use lseek with SEEK_END to seek to the position(file.seek(SeekFrom::End(-meta_siza)) in rust) and then read from it. However, after some search, I found IoUring does not have an operation named seek. So maybe we can use the pos = file.read_at(file_size - meta_size) to achieve it. But how can we get the file size? Using stat syscall may cause blocking...
This example was for me the occasion to discover
io-uring.One solution is to call
statx()withAT_FDCWDas file-descriptor in order to state that the path is relative to the current directory. The path provided to this call is supposed to be null-terminated, hence the conversion intoCString.Another solution is to call
statx()with an already open file-descriptor, an empty null-terminated string as filename and theAT_EMPTY_PATHflag.Note that this example is not representative of a normal usage because it does not take any advantage of the asynchronous nature of the API; we submit and wait for every single operation in a synchronous manner.