diff --git a/src/fs/ioctl.rs b/src/fs/ioctl.rs index c7e705f44..0794c48be 100644 --- a/src/fs/ioctl.rs +++ b/src/fs/ioctl.rs @@ -79,7 +79,10 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> { type Output = (); const IS_MUTATING: bool = false; - const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::FICLONE as ioctl::RawOpcode); + + fn opcode(&self) -> ioctl::Opcode { + ioctl::Opcode::old(c::FICLONE as ioctl::RawOpcode) + } fn as_ptr(&mut self) -> *mut c::c_void { self.0.as_raw_fd() as *mut c::c_void diff --git a/src/ioctl/mod.rs b/src/ioctl/mod.rs index dec108f69..8ef9dfb16 100644 --- a/src/ioctl/mod.rs +++ b/src/ioctl/mod.rs @@ -85,7 +85,7 @@ use bsd as platform; #[inline] pub unsafe fn ioctl(fd: F, mut ioctl: I) -> Result { 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 @@ -138,7 +138,7 @@ unsafe fn _ioctl_readonly( /// output as indicated by `output`. /// - That `output_from_ptr` can safely take the pointer from `as_ptr` and cast /// it to the correct type, *only* after the `ioctl` call. -/// - That `OPCODE` uniquely identifies the `ioctl` call. +/// - That the return value of `opcode` uniquely identifies the `ioctl` call. /// - That, for whatever platforms you are targeting, the `ioctl` call is safe /// to make. /// - If `IS_MUTATING` is false, that no userspace data will be modified by the @@ -150,12 +150,6 @@ pub unsafe trait Ioctl { /// type. type Output; - /// The opcode used by this `ioctl` command. - /// - /// There are different types of opcode depending on the operation. See - /// documentation for the [`Opcode`] struct for more information. - const OPCODE: Opcode; - /// Does the `ioctl` mutate any data in the userspace? /// /// If the `ioctl` call does not mutate any data in the userspace, then @@ -169,6 +163,12 @@ pub unsafe trait Ioctl { /// to `false` when it should be `true`. const IS_MUTATING: bool; + /// Get the opcode used by this `ioctl` command. + /// + /// There are different types of opcode depending on the operation. See + /// documentation for the [`Opcode`] struct for more information. + fn opcode(&self) -> Opcode; + /// Get a pointer to the data to be passed to the `ioctl` command. /// /// See trait-level documentation for more information. diff --git a/src/ioctl/patterns.rs b/src/ioctl/patterns.rs index ea0c714fc..e7477464e 100644 --- a/src/ioctl/patterns.rs +++ b/src/ioctl/patterns.rs @@ -39,7 +39,10 @@ unsafe impl Ioctl for NoArg { 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() @@ -89,7 +92,10 @@ unsafe impl Ioctl for Getter 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() @@ -142,7 +148,10 @@ unsafe impl Ioctl for Setter { 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::() @@ -186,7 +195,10 @@ 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() @@ -244,7 +256,10 @@ unsafe impl Ioctl for IntegerSetter { 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 { self.value diff --git a/src/process/ioctl.rs b/src/process/ioctl.rs index 1b617035f..8f93f3448 100644 --- a/src/process/ioctl.rs +++ b/src/process/ioctl.rs @@ -37,7 +37,10 @@ unsafe impl ioctl::Ioctl for Tiocsctty { type Output = (); const IS_MUTATING: bool = false; - const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::TIOCSCTTY as ioctl::RawOpcode); + + fn opcode(&self) -> ioctl::Opcode { + ioctl::Opcode::old(c::TIOCSCTTY as ioctl::RawOpcode) + } fn as_ptr(&mut self) -> *mut c::c_void { (&0_u32) as *const u32 as *mut c::c_void diff --git a/src/pty.rs b/src/pty.rs index 2f887da4d..b7d1fdd6a 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -206,7 +206,10 @@ unsafe impl ioctl::Ioctl for Tiocgptpeer { type Output = OwnedFd; const IS_MUTATING: bool = false; - const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::TIOCGPTPEER as ioctl::RawOpcode); + + fn opcode(&self) -> ioctl::Opcode { + ioctl::Opcode::old(c::TIOCGPTPEER as ioctl::RawOpcode) + } fn as_ptr(&mut self) -> *mut c::c_void { self.0.bits() as *mut c::c_void