/// Implements the traditional “getter” pattern for `ioctl`s. /// /// Some `ioctl`s just read data into the userspace. As this is a popular /// pattern this structure implements it. pubstruct Getter<Opcode, Output> { /// The output data.
output: mem::MaybeUninit<Output>,
impl<Opcode: CompileTimeOpcode, Output> Getter<Opcode, Output> { /// Create a new getter-style `ioctl` object. /// /// # Safety /// /// - `Opcode` must provide a valid opcode. /// - For this opcode, `Output` must be the type that the kernel expects to /// write into. #[inline] pubunsafefn new() -> Self { Self {
output: mem::MaybeUninit::uninit(),
_opcode: PhantomData,
}
}
}
unsafeimpl<Opcode: CompileTimeOpcode, Output> Ioctl for Getter<Opcode, Output> { type Output = Output;
/// Implements the pattern for `ioctl`s where a pointer argument is given to /// the `ioctl`. /// /// The opcode must be read-only. pubstruct Setter<Opcode, Input> { /// The input data.
input: Input,
impl<Opcode: CompileTimeOpcode, Input> Setter<Opcode, Input> { /// Create a new pointer setter-style `ioctl` object. /// /// # Safety /// /// - `Opcode` must provide a valid opcode. /// - For this opcode, `Input` must be the type that the kernel expects to /// get. #[inline] pubunsafefn new(input: Input) -> Self { Self {
input,
_opcode: PhantomData,
}
}
}
unsafeimpl<Opcode: CompileTimeOpcode, Input> Ioctl for Setter<Opcode, Input> { type Output = ();
/// Implements an “updater” pattern for `ioctl`s. /// /// The ioctl takes a reference to a struct that it reads its input from, /// then writes output to the same struct. pubstruct Updater<'a, Opcode, Value> { /// Reference to input/output data.
value: &'a mut Value,
/// The opcode.
_opcode: PhantomData<Opcode>,
}
impl<'a, Opcode: CompileTimeOpcode, Value> Updater<'a, Opcode, Value> { /// Create a new pointer updater-style `ioctl` object. /// /// # Safety /// /// - `Opcode` must provide a valid opcode. /// - For this opcode, `Value` must be the type that the kernel expects to /// get. #[inline] pubunsafefn new(value: &'a mut Value) -> Self { Self {
value,
_opcode: PhantomData,
}
}
}
unsafeimpl<'a, Opcode: CompileTimeOpcode, T> Ioctl for Updater<'a, Opcode, T> { type Output = ();
/// Provides a read code at compile time. /// /// This corresponds to the C macro `_IOR(GROUP, NUM, Data)`. #[cfg(any(linux_kernel, bsd))] pubstruct ReadOpcode<const GROUP: u8, const NUM: u8, Data>(Data);
/// Provides a write code at compile time. /// /// This corresponds to the C macro `_IOW(GROUP, NUM, Data)`. #[cfg(any(linux_kernel, bsd))] pubstruct WriteOpcode<const GROUP: u8, const NUM: u8, Data>(Data);
/// Provides a read/write code at compile time. /// /// This corresponds to the C macro `_IOWR(GROUP, NUM, Data)`. #[cfg(any(linux_kernel, bsd))] pubstruct ReadWriteOpcode<const GROUP: u8, const NUM: u8, Data>(Data);
/// Provides a `None` code at compile time. /// /// This corresponds to the C macro `_IO(GROUP, NUM)` when `Data` is zero /// sized. #[cfg(any(linux_kernel, bsd))] pubstruct NoneOpcode<const GROUP: u8, const NUM: u8, Data>(Data);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.