smol-rs / async-fs

Async filesystem primitives
Apache License 2.0
130 stars 8 forks source link

Support OS-specific FileExt traits. #7

Open songzhi opened 4 years ago

songzhi commented 4 years ago

Unix FileExt and Windows FileExt. They are useful when using .read_at(buf, offset) instead of .seek(pos); .read(buf). Because it calls pread(2) instead of lseek(2) + read(2) which is more efficient.

mainrs commented 2 years ago

I'd be willing to work on this (at least for linux), I need it for a project. Would it be possible to get some guidance on how to properly implement this?

I do have a question about this feature though: would this allow one to make multiple read_at,write_at calls in parallel? Or is this, on the kernel level, still a sync operation? Even if the offsets do not collide with each other?

songzhi commented 2 years ago

@mainrs See this docs for pread(2)/pwrite(2):

The pread() and pwrite() system calls are especially useful in multithreaded applications. They allow multiple threads to perform I/O on the same file descriptor without being affected by changes to the file offset by other threads.