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

Support File::seek for Hermit #138074

Merged
merged 2 commits into from
Mar 11, 2025
Merged

Support File::seek for Hermit #138074

merged 2 commits into from
Mar 11, 2025

Conversation

thaliaarchi
Copy link
Contributor

lseek was added in hermit-abi in commit 87dd201 (add missing interface for lseek, 2024-07-15), which was just released in version 0.5.0.

cc @mkroening, @stlankes

Fixes hermit-os/hermit-rs#652

@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

r? @ChrisDenton

rustbot has assigned @ChrisDenton.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-hermit Operating System: Hermit S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

These commits modify the library/Cargo.lock file. Unintentional changes to library/Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Mar 5, 2025
@thaliaarchi
Copy link
Contributor Author

thaliaarchi commented Mar 5, 2025

I have not setup Hermit for runtime testing, so although this compiles with x check library/std --target=x86_64-unknown-hermit, I do not know whether it is fully correct. I copied fn seek from Unix with minor type adjustments.

To the Hermit maintainers: Please check that these invariants are also good for Hermit.

pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
let (whence, pos) = match pos {
// Casting to `i64` is fine, too large values will end up as
// negative which will cause an error in `lseek64`.
SeekFrom::Start(off) => (libc::SEEK_SET, off as i64),
SeekFrom::End(off) => (libc::SEEK_END, off),
SeekFrom::Current(off) => (libc::SEEK_CUR, off),
};
let n = cvt(unsafe { lseek64(self.as_raw_fd(), pos as off64_t, whence) })?;
Ok(n as u64)
}

Copy link
Contributor

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thanks a lot!

I have also tested this with Hermit and the kernel receives all system calls as expected. 👍

@thaliaarchi
Copy link
Contributor Author

@mkroening Is the negative cast fine too?

@thaliaarchi
Copy link
Contributor Author

It looks like all Hermit targets are 64-bit, so the i64 to isize cast should be fine.

@mkroening
Copy link
Contributor

@mkroening Is the negative cast fine too?

Do you mean casting SeekFrom::Start(off) to i64? That's fine, yes. I have tested this with Hermit's ramfs, and we do explicitly check for negative values.

In any case, since this appears to be fine to do on all Unixes, it should also be fine to do on Hermit, since we aim for POSIX compatibility for most file descriptor related things.

@bors
Copy link
Contributor

bors commented Mar 9, 2025

☔ The latest upstream changes (presumably #138279) made this pull request unmergeable. Please resolve the merge conflicts.

@ChrisDenton
Copy link
Member

If a target maintainer is fine with it then I am too 🙂

@bors r+

@bors
Copy link
Contributor

bors commented Mar 10, 2025

📌 Commit 1abaacd has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 10, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 10, 2025
…nton

Support `File::seek` for Hermit

`lseek` was added in `hermit-abi` in commit [87dd201](hermit-os/hermit-rs@87dd201) (add missing interface for lseek, 2024-07-15), which was just released in version 0.5.0.

cc `@mkroening,` `@stlankes`

Fixes hermit-os/hermit-rs#652
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2025
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#136395 (Update to rand 0.9.0)
 - rust-lang#137279 (Make some invalid codegen attr errors structured/translatable)
 - rust-lang#137585 (Update documentation to consistently use 'm' in atomic synchronization example)
 - rust-lang#137926 (Add a test for `-znostart-stop-gc` usage with LLD)
 - rust-lang#138074 (Support `File::seek` for Hermit)
 - rust-lang#138238 (Fix dyn -> param suggestion in struct ICEs)
 - rust-lang#138270 (chore: Fix some comments)
 - rust-lang#138280 (fix ICE in pretty-printing `global_asm!`)
 - rust-lang#138286 (triagebot.toml: Don't label `test/rustdoc-json` as A-rustdoc-search (…)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#136395 (Update to rand 0.9.0)
 - rust-lang#137279 (Make some invalid codegen attr errors structured/translatable)
 - rust-lang#137585 (Update documentation to consistently use 'm' in atomic synchronization example)
 - rust-lang#137926 (Add a test for `-znostart-stop-gc` usage with LLD)
 - rust-lang#138074 (Support `File::seek` for Hermit)
 - rust-lang#138238 (Fix dyn -> param suggestion in struct ICEs)
 - rust-lang#138270 (chore: Fix some comments)
 - rust-lang#138286 (triagebot.toml: Don't label `test/rustdoc-json` as A-rustdoc-search (…)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#136395 (Update to rand 0.9.0)
 - rust-lang#137279 (Make some invalid codegen attr errors structured/translatable)
 - rust-lang#137585 (Update documentation to consistently use 'm' in atomic synchronization example)
 - rust-lang#137926 (Add a test for `-znostart-stop-gc` usage with LLD)
 - rust-lang#138074 (Support `File::seek` for Hermit)
 - rust-lang#138238 (Fix dyn -> param suggestion in struct ICEs)
 - rust-lang#138270 (chore: Fix some comments)
 - rust-lang#138286 (triagebot.toml: Don't label `test/rustdoc-json` as A-rustdoc-search (…)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 10, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#136395 (Update to rand 0.9.0)
 - rust-lang#137279 (Make some invalid codegen attr errors structured/translatable)
 - rust-lang#137585 (Update documentation to consistently use 'm' in atomic synchronization example)
 - rust-lang#137926 (Add a test for `-znostart-stop-gc` usage with LLD)
 - rust-lang#138074 (Support `File::seek` for Hermit)
 - rust-lang#138238 (Fix dyn -> param suggestion in struct ICEs)
 - rust-lang#138270 (chore: Fix some comments)
 - rust-lang#138286 (triagebot.toml: Don't label `test/rustdoc-json` as A-rustdoc-search (…)

r? `@ghost`
`@rustbot` modify labels: rollup
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Mar 10, 2025
…nton

Support `File::seek` for Hermit

`lseek` was added in `hermit-abi` in commit [87dd201](hermit-os/hermit-rs@87dd201) (add missing interface for lseek, 2024-07-15), which was just released in version 0.5.0.

cc ```@mkroening,``` ```@stlankes```

Fixes hermit-os/hermit-rs#652
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 11, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#136395 (Update to rand 0.9.0)
 - rust-lang#137279 (Make some invalid codegen attr errors structured/translatable)
 - rust-lang#137585 (Update documentation to consistently use 'm' in atomic synchronization example)
 - rust-lang#137926 (Add a test for `-znostart-stop-gc` usage with LLD)
 - rust-lang#138074 (Support `File::seek` for Hermit)
 - rust-lang#138238 (Fix dyn -> param suggestion in struct ICEs)
 - rust-lang#138270 (chore: Fix some comments)
 - rust-lang#138286 (triagebot.toml: Don't label `test/rustdoc-json` as A-rustdoc-search (…)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2f1908d into rust-lang:master Mar 11, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 11, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 11, 2025
Rollup merge of rust-lang#138074 - thaliaarchi:hermit-seek, r=ChrisDenton

Support `File::seek` for Hermit

`lseek` was added in `hermit-abi` in commit [87dd201](hermit-os/hermit-rs@87dd201) (add missing interface for lseek, 2024-07-15), which was just released in version 0.5.0.

cc ``@mkroening,`` ``@stlankes``

Fixes hermit-os/hermit-rs#652
@thaliaarchi thaliaarchi deleted the hermit-seek branch March 11, 2025 03:59
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Mar 14, 2025
…nton

Support `File::seek` for Hermit

`lseek` was added in `hermit-abi` in commit [87dd201](hermit-os/hermit-rs@87dd201) (add missing interface for lseek, 2024-07-15), which was just released in version 0.5.0.

cc ``@mkroening,`` ``@stlankes``

Fixes hermit-os/hermit-rs#652
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-hermit Operating System: Hermit S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support std::fs::File::seek
5 participants