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

Replace Ioctl::OPCODE with an Ioctl::opcode() method #1040

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ioctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ use bsd as platform;
#[inline]
pub unsafe fn ioctl<F: AsFd, I: Ioctl>(fd: F, mut ioctl: I) -> Result<I::Output> {
let fd = fd.as_fd();
let request = I::OPCODE.raw();
let request = ioctl.opcode().raw();
let arg = ioctl.as_ptr();

// SAFETY: The variant of `Ioctl` asserts that this is a valid IOCTL call
Expand Down Expand Up @@ -154,7 +154,8 @@ pub unsafe trait Ioctl {
///
/// There are different types of opcode depending on the operation. See
/// documentation for the [`Opcode`] struct for more information.
const OPCODE: Opcode;
//const OPCODE: Opcode;
fn opcode(&self) -> Opcode;

/// Does the `ioctl` mutate any data in the userspace?
///
Expand Down
16 changes: 12 additions & 4 deletions src/ioctl/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ unsafe impl<Opcode: CompileTimeOpcode> Ioctl for NoArg<Opcode> {
type Output = ();

const IS_MUTATING: bool = false;
const OPCODE: self::Opcode = Opcode::OPCODE;
fn opcode(&self) -> self::Opcode {
Opcode::OPCODE
}

fn as_ptr(&mut self) -> *mut c::c_void {
core::ptr::null_mut()
Expand Down Expand Up @@ -89,7 +91,9 @@ unsafe impl<Opcode: CompileTimeOpcode, Output> Ioctl for Getter<Opcode, Output>
type Output = Output;

const IS_MUTATING: bool = true;
const OPCODE: self::Opcode = Opcode::OPCODE;
fn opcode(&self) -> self::Opcode {
Opcode::OPCODE
}

fn as_ptr(&mut self) -> *mut c::c_void {
self.output.as_mut_ptr().cast()
Expand Down Expand Up @@ -142,7 +146,9 @@ unsafe impl<Opcode: CompileTimeOpcode, Input> Ioctl for Setter<Opcode, Input> {
type Output = ();

const IS_MUTATING: bool = false;
const OPCODE: self::Opcode = Opcode::OPCODE;
fn opcode(&self) -> self::Opcode {
Opcode::OPCODE
}

fn as_ptr(&mut self) -> *mut c::c_void {
addr_of_mut!(self.input).cast::<c::c_void>()
Expand Down Expand Up @@ -186,7 +192,9 @@ unsafe impl<'a, Opcode: CompileTimeOpcode, T> Ioctl for Updater<'a, Opcode, T> {
type Output = ();

const IS_MUTATING: bool = true;
const OPCODE: self::Opcode = Opcode::OPCODE;
fn opcode(&self) -> self::Opcode {
Opcode::OPCODE
}

fn as_ptr(&mut self) -> *mut c::c_void {
(self.value as *mut T).cast()
Expand Down
Loading