MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / Ioctl

Interface Ioctl

src/ioctl/mod.rs:147–190  ·  view source on GitHub ↗

A trait defining the properties of an `ioctl` command. Objects implementing this trait can be passed to [`ioctl`] to make an `ioctl` call. The contents of the object represent the inputs to the `ioctl` call. The inputs must be convertible to a pointer through the `as_ptr` method. In most cases, this involves either casting a number to a pointer, or creating a pointer to the actual data. The latte

Source from the content-addressed store, hash-verified

145/// - If `IS_MUTATING` is false, that no userspace data will be modified by
146/// the `ioctl` call.
147pub unsafe trait Ioctl {
148 /// The type of the output data.
149 ///
150 /// Given a pointer, one should be able to construct an instance of this
151 /// type.
152 type Output;
153
154 /// Does the `ioctl` mutate any data in the userspace?
155 ///
156 /// If the `ioctl` call does not mutate any data in the userspace, then
157 /// making this `false` enables optimizations that can make the call
158 /// faster. When in doubt, set this to `true`.
159 ///
160 /// # Safety
161 ///
162 /// This should only be set to `false` if the `ioctl` call does not mutate
163 /// any data in the userspace. Undefined behavior may occur if this is set
164 /// to `false` when it should be `true`.
165 const IS_MUTATING: bool;
166
167 /// Get the opcode used by this `ioctl` command.
168 ///
169 /// There are different types of opcode depending on the operation. See
170 /// documentation for [`opcode`] for more information.
171 fn opcode(&self) -> Opcode;
172
173 /// Get a pointer to the data to be passed to the `ioctl` command.
174 ///
175 /// See trait-level documentation for more information.
176 fn as_ptr(&mut self) -> *mut c::c_void;
177
178 /// Cast the output data to the correct type.
179 ///
180 /// # Safety
181 ///
182 /// The `extract_output` value must be the resulting value after a
183 /// successful `ioctl` call, and `out` is the direct return value of an
184 /// `ioctl` call that did not fail. In this case `extract_output` is the
185 /// pointer that was passed to the `ioctl` call.
186 unsafe fn output_from_ptr(
187 out: IoctlOutput,
188 extract_output: *mut c::c_void,
189 ) -> Result<Self::Output>;
190}
191
192/// Const functions for computing opcode values.
193///

Callers

nothing calls this directly

Implementers 4

pty.rssrc/pty.rs
patterns.rssrc/ioctl/patterns.rs
ioctl.rssrc/process/ioctl.rs
ioctl.rssrc/fs/ioctl.rs

Calls

no outgoing calls

Tested by

no test coverage detected