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

Define more ioctl codes on riscv32gc-unknown-linux-gnu #4382

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sunfishcode
Copy link
Member

Description

Define ioctl codes including FICLONE and FS_IOC32_GETVERSION on riscv32gc-unknown-linux-gnu.

Sources

The values match the values in the linux-raw-sys crate, which is autogenerated from Linux sources:

https://github.com/sunfishcode/linux-raw-sys/blob/21a3b3b1fada619179810ca92404690d45890f29/src/riscv32/ioctl.rs#L248

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

Define ioctl codes including `FICLONE` and `FS_IOC32_GETVERSION` on
riscv32gc-unknown-linux-gnu.
@rustbot
Copy link
Collaborator

rustbot commented Apr 6, 2025

r? @tgross35

rustbot has assigned @tgross35.
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

Copy link
Contributor

@kraj kraj left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Any idea why these are gated in the first place? All of the constants are in https://github.com/torvalds/linux/blob/bec7dcbc242c6c087cede1a6fdfaeb5d6eaf25bf/include/uapi/linux/fs.h, I don't know why any platforms wouldn't have them unless they have no fs support.

In any case LGTM, blocked on CI issues.

@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Apr 8, 2025
@kraj
Copy link
Contributor

kraj commented Apr 8, 2025

Any idea why these are gated in the first place? All of the constants are in https://github.com/torvalds/linux/blob/bec7dcbc242c6c087cede1a6fdfaeb5d6eaf25bf/include/uapi/linux/fs.h, I don't know why any platforms wouldn't have them unless they have no fs support.

they all do exist but values are different sadly

In any case LGTM, blocked on CI issues.

@tgross35
Copy link
Contributor

tgross35 commented Apr 8, 2025

they all do exist but values are different sadly

Oh, from differences in sizes passed to _IOR and _IOW? We actually have these functions now, the cfg could probably just be deleted and replaced with calls

/// Build an ioctl number, analogous to the C macro of the same name.
const fn _IOC(dir: u32, ty: u32, nr: u32, size: usize) -> u32 {
// FIXME(ctest) the `garando_syntax` crate (used by ctest in the CI test suite)
// cannot currently parse these `debug_assert!`s
//
// debug_assert!(dir <= _IOC_DIRMASK);
// debug_assert!(ty <= _IOC_TYPEMASK);
// debug_assert!(nr <= _IOC_NRMASK);
// debug_assert!(size <= (_IOC_SIZEMASK as usize));
(dir << _IOC_DIRSHIFT)
| (ty << _IOC_TYPESHIFT)
| (nr << _IOC_NRSHIFT)
| ((size as u32) << _IOC_SIZESHIFT)
}
/// Build an ioctl number for an argumentless ioctl.
pub const fn _IO(ty: u32, nr: u32) -> u32 {
_IOC(_IOC_NONE, ty, nr, 0)
}
/// Build an ioctl number for an read-only ioctl.
pub const fn _IOR<T>(ty: u32, nr: u32) -> u32 {
_IOC(_IOC_READ, ty, nr, size_of::<T>())
}
/// Build an ioctl number for an write-only ioctl.
pub const fn _IOW<T>(ty: u32, nr: u32) -> u32 {
_IOC(_IOC_WRITE, ty, nr, size_of::<T>())
}
/// Build an ioctl number for a read-write ioctl.
pub const fn _IOWR<T>(ty: u32, nr: u32) -> u32 {
_IOC(_IOC_READ | _IOC_WRITE, ty, nr, size_of::<T>())
}
.

@tgross35
Copy link
Contributor

tgross35 commented Apr 8, 2025

Actually @sunfishcode would you mind just changing the relevant blocks to make use of those instead? I think we may as well use this as an excuse to get rid of some pre-const fn cruft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-linux O-unix S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants