Skip to content

FreeBSD: Added xfile structure and file descriptor types#5002

Open
antoncxx wants to merge 1 commit intorust-lang:mainfrom
antoncxx:freebsd-file
Open

FreeBSD: Added xfile structure and file descriptor types#5002
antoncxx wants to merge 1 commit intorust-lang:mainfrom
antoncxx:freebsd-file

Conversation

@antoncxx
Copy link
Contributor

@antoncxx antoncxx commented Mar 4, 2026

Description

Added binding for xfile structure from sys/file.h and descriptor types.

Sources

FreeBSD 15

FreeBSD 14

FreeBSD 13

FreeBSD 12

FreeBSD 11

FreeBSD 10

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

@rustbot label +stable-nominated

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Mar 4, 2026
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.

pub const DTYPE_JAILDESC: c_int = 16;

s! {
pub struct xfile {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this whole struct just be #[cfg(not(any(freebsd10, freebsd11)))]? I don't think we really need the EOL support so that simplifies config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely. I will update the PR tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +20 to +31
#[cfg(any(freebsd13, freebsd14, freebsd15))]
pub const DTYPE_EVENTFD: c_int = 13;
#[cfg(any(freebsd10, freebsd11, freebsd12))]
pub const DTYPE_LINUXEFD: c_int = 13;
#[cfg(any(freebsd14, freebsd15))]
pub const DTYPE_TIMERFD: c_int = 14;
#[cfg(any(freebsd11, freebsd12, freebsd13))]
pub const DTYPE_LINUXTFD: c_int = 14;
#[cfg(freebsd15)]
pub const DTYPE_INOTIFY: c_int = 15;
#[cfg(freebsd15)]
pub const DTYPE_JAILDESC: c_int = 16;
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, I'd prefer to just drop anything that only exists on EOL versions (<13).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@asomers asomers left a comment

Choose a reason for hiding this comment

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

What's the purpose of this PR? As far as I know, struct xfile is only exposed to the user via the KERN_FILE sysctl. That's fairly obscure. I would be ok if those definitions lived outside of the libc crate. It's up to Trevor if he thinks it's worthwhile to include.
And like Trevor said, you should drop everything related to FreeBSD 10 through12.

View changes since this review

@antoncxx
Copy link
Contributor Author

antoncxx commented Mar 5, 2026

What's the purpose of this PR? As far as I know, struct xfile is only exposed to the user via the KERN_FILE sysctl. That's fairly obscure. I would be ok if those definitions lived outside of the libc crate. It's up to Trevor if he thinks it's worthwhile to include. And like Trevor said, you should drop everything related to FreeBSD 10 through12.

View changes since this review

The motivation is what you described. I'm involved into development of a Rust library that performs KERN_FILE sysctl query, currently written in C, and I want to rewrite it in pure Rust. I could define the bindings locally, but since libc is already a dependency, I figured contributing them here might be useful to others as well.

Comment on lines +25 to +26
#[cfg(freebsd15)]
pub const DTYPE_INOTIFY: c_int = 15;
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though DTYPE_INOTIFY didn't exist on FreeBSD 13 and 14, libc doesn't need to worry about that. It's safe to define it here for all versions. It's preferable, even, because that way Rust programs can use it without any special compiler settings for libc. Otherwise it would be off-limits, since libc always uses the FreeBSD 13 ABI. The only symbols that you need to be careful with are symbols that changed between FreeBSD versions, not symbols that got added, like struct kevent.

Suggested change
#[cfg(freebsd15)]
pub const DTYPE_INOTIFY: c_int = 15;
pub const DTYPE_INOTIFY: c_int = 15;

Comment on lines +21 to +24
#[cfg(freebsd13)]
pub const DTYPE_LINUXTFD: c_int = 14;
#[cfg(any(freebsd14, freebsd15))]
pub const DTYPE_TIMERFD: c_int = 14;
Copy link
Contributor

Choose a reason for hiding this comment

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

This symbol's name changed in FreeBSD 14, even though it already existed. So you might consider adding the old name as an alias. However, since there is literally zero Rust code already using the old name, it's probably better not to add a symbol that will always be deprecated.

Suggested change
#[cfg(freebsd13)]
pub const DTYPE_LINUXTFD: c_int = 14;
#[cfg(any(freebsd14, freebsd15))]
pub const DTYPE_TIMERFD: c_int = 14;
pub const DTYPE_TIMERFD: c_int = 14;
#[deprecated(since = "1.0.0", note = "Use DTYPE_TIMERFD instead")]
pub const DTYPE_LINUXTFD: c_int = DTYPE_TIMERFD;

Comment on lines +27 to +28
#[cfg(freebsd15)]
pub const DTYPE_JAILDESC: c_int = 16;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just like DTYPE_INOTIFY, you can define this for all FreeBSD versions.

Suggested change
#[cfg(freebsd15)]
pub const DTYPE_JAILDESC: c_int = 16;
pub const DTYPE_JAILDESC: c_int = 16;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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