Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use platform-specific read_at to read the files. #8

Merged
merged 4 commits into from
Dec 16, 2022
Merged

Conversation

Berrysoft
Copy link
Collaborator

  • 写了个单独的 mod 处理 read_at。如果有一天这个方法进入 std,可以直接删掉这个文件。
  • 加入了自己处理 offset 的逻辑。
  • 删掉了 frfs::File::try_clone。这是因为 try_clone 要求两个 File 的操作互相影响,我们反正也不需要这个功能,就删了。

All frfs::File uses the same source underneath. The sources are created
with try_clone. Therefore when one file is readed, all other files'
cursor will be changed. This is not a desirable behavior.

While there are no cross-platform way to avoid this besides reopening
the source, we can use read_at/seek_read methods in the FileExt. It is a
platform-specific extension, but avaliable on Windows, Unix, and WASI.

The implementation on Unix of read_at is pread/pread64, and the one on
Windows is NtReadFile. They are all reliable methods and will not read
or write the file cursor.

Using read_at, we need to manage the own offset in the frfs::File.

This implementation is not suitable for try_clone. Therefore we removed
this method.
@Berrysoft
Copy link
Collaborator Author

Track: rust 1.66 stable release

@Berrysoft Berrysoft merged commit 48a3775 into main Dec 16, 2022
@Tim-Paik Tim-Paik deleted the dev/readat branch December 17, 2022 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant