Files
phy/rustix/ioctl/trait.Ioctl.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

61 lines
20 KiB
HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A trait defining the properties of an `ioctl` command."><title>Ioctl in rustix::ioctl - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="rustix" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../rustix/index.html">rustix</a><span class="version">0.38.37</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Ioctl</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#safety" title="Safety">Safety</a></li></ul><h3><a href="#required-associated-consts">Required Associated Constants</a></h3><ul class="block"><li><a href="#associatedconstant.IS_MUTATING" title="IS_MUTATING">IS_MUTATING</a></li><li><a href="#associatedconstant.OPCODE" title="OPCODE">OPCODE</a></li></ul><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Output" title="Output">Output</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.as_ptr" title="as_ptr">as_ptr</a></li><li><a href="#tymethod.output_from_ptr" title="output_from_ptr">output_from_ptr</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In rustix::<wbr>ioctl</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">rustix</a>::<wbr><a href="index.html">ioctl</a></span><h1>Trait <span class="trait">Ioctl</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/rustix/ioctl/mod.rs.html#146-189">Source</a> </span></div><pre class="rust item-decl"><code>pub unsafe trait Ioctl {
type <a href="#associatedtype.Output" class="associatedtype">Output</a>;
const <a href="#associatedconstant.OPCODE" class="constant">OPCODE</a>: <a class="struct" href="struct.Opcode.html" title="struct rustix::ioctl::Opcode">Opcode</a>;
const <a href="#associatedconstant.IS_MUTATING" class="constant">IS_MUTATING</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a>;
// Required methods
fn <a href="#tymethod.as_ptr" class="fn">as_ptr</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.pointer.html">*mut </a><a class="enum" href="https://doc.rust-lang.org/1.84.0/core/ffi/enum.c_void.html" title="enum core::ffi::c_void">c_void</a>;
<span class="item-spacer"></span> unsafe fn <a href="#tymethod.output_from_ptr" class="fn">output_from_ptr</a>(
out: <a class="type" href="type.IoctlOutput.html" title="type rustix::ioctl::IoctlOutput">IoctlOutput</a>,
extract_output: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.pointer.html">*mut </a><a class="enum" href="https://doc.rust-lang.org/1.84.0/core/ffi/enum.c_void.html" title="enum core::ffi::c_void">c_void</a>,
) -&gt; <a class="type" href="../io/type.Result.html" title="type rustix::io::Result">Result</a>&lt;Self::<a class="associatedtype" href="trait.Ioctl.html#associatedtype.Output" title="type rustix::ioctl::Ioctl::Output">Output</a>&gt;;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait defining the properties of an <code>ioctl</code> command.</p>
<p>Objects implementing this trait can be passed to <a href="fn.ioctl.html" title="fn rustix::ioctl::ioctl"><code>ioctl</code></a> to make an
<code>ioctl</code> call. The contents of the object represent the inputs to the
<code>ioctl</code> call. The inputs must be convertible to a pointer through the
<code>as_ptr</code> method. In most cases, this involves either casting a number to a
pointer, or creating a pointer to the actual data. The latter case is
necessary for <code>ioctl</code> calls that modify userspace data.</p>
<h2 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h2>
<p>This trait is unsafe to implement because it is impossible to guarantee
that the <code>ioctl</code> call is safe. The <code>ioctl</code> call may be proprietary, or it
may be unsafe to call in certain circumstances.</p>
<p>By implementing this trait, you guarantee that:</p>
<ul>
<li>The <code>ioctl</code> call expects the input provided by <code>as_ptr</code> and produces the
output as indicated by <code>output</code>.</li>
<li>That <code>output_from_ptr</code> can safely take the pointer from <code>as_ptr</code> and cast
it to the correct type, <em>only</em> after the <code>ioctl</code> call.</li>
<li>That <code>OPCODE</code> uniquely identifies the <code>ioctl</code> call.</li>
<li>That, for whatever platforms you are targeting, the <code>ioctl</code> call is safe
to make.</li>
<li>If <code>IS_MUTATING</code> is false, that no userspace data will be modified by the
<code>ioctl</code> call.</li>
</ul>
</div></details><h2 id="required-associated-consts" class="section-header">Required Associated Constants<a href="#required-associated-consts" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedconstant.OPCODE" class="method"><a class="src rightside" href="../../src/rustix/ioctl/mod.rs.html#157">Source</a><h4 class="code-header">const <a href="#associatedconstant.OPCODE" class="constant">OPCODE</a>: <a class="struct" href="struct.Opcode.html" title="struct rustix::ioctl::Opcode">Opcode</a></h4></section></summary><div class="docblock"><p>The opcode used by this <code>ioctl</code> command.</p>
<p>There are different types of opcode depending on the operation. See
documentation for the <a href="struct.Opcode.html" title="struct rustix::ioctl::Opcode"><code>Opcode</code></a> struct for more information.</p>
</div></details><details class="toggle" open><summary><section id="associatedconstant.IS_MUTATING" class="method"><a class="src rightside" href="../../src/rustix/ioctl/mod.rs.html#170">Source</a><h4 class="code-header">const <a href="#associatedconstant.IS_MUTATING" class="constant">IS_MUTATING</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Does the <code>ioctl</code> mutate any data in the userspace?</p>
<p>If the <code>ioctl</code> call does not mutate any data in the userspace, then
making this <code>false</code> enables optimizations that can make the call
faster. When in doubt, set this to <code>true</code>.</p>
<h5 id="safety-1"><a class="doc-anchor" href="#safety-1">§</a>Safety</h5>
<p>This should only be set to <code>false</code> if the <code>ioctl</code> call does not mutate
any data in the userspace. Undefined behavior may occur if this is set
to <code>false</code> when it should be <code>true</code>.</p>
</div></details></div><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.Output" class="method"><a class="src rightside" href="../../src/rustix/ioctl/mod.rs.html#151">Source</a><h4 class="code-header">type <a href="#associatedtype.Output" class="associatedtype">Output</a></h4></section></summary><div class="docblock"><p>The type of the output data.</p>
<p>Given a pointer, one should be able to construct an instance of this
type.</p>
</div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.as_ptr" class="method"><a class="src rightside" href="../../src/rustix/ioctl/mod.rs.html#175">Source</a><h4 class="code-header">fn <a href="#tymethod.as_ptr" class="fn">as_ptr</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.pointer.html">*mut </a><a class="enum" href="https://doc.rust-lang.org/1.84.0/core/ffi/enum.c_void.html" title="enum core::ffi::c_void">c_void</a></h4></section></summary><div class="docblock"><p>Get a pointer to the data to be passed to the <code>ioctl</code> command.</p>
<p>See trait-level documentation for more information.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.output_from_ptr" class="method"><a class="src rightside" href="../../src/rustix/ioctl/mod.rs.html#185-188">Source</a><h4 class="code-header">unsafe fn <a href="#tymethod.output_from_ptr" class="fn">output_from_ptr</a>(
out: <a class="type" href="type.IoctlOutput.html" title="type rustix::ioctl::IoctlOutput">IoctlOutput</a>,
extract_output: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.pointer.html">*mut </a><a class="enum" href="https://doc.rust-lang.org/1.84.0/core/ffi/enum.c_void.html" title="enum core::ffi::c_void">c_void</a>,
) -&gt; <a class="type" href="../io/type.Result.html" title="type rustix::io::Result">Result</a>&lt;Self::<a class="associatedtype" href="trait.Ioctl.html#associatedtype.Output" title="type rustix::ioctl::Ioctl::Output">Output</a>&gt;</h4></section></summary><div class="docblock"><p>Cast the output data to the correct type.</p>
<h5 id="safety-2"><a class="doc-anchor" href="#safety-2">§</a>Safety</h5>
<p>The <code>extract_output</code> value must be the resulting value after a
successful <code>ioctl</code> call, and <code>out</code> is the direct return value of an
<code>ioctl</code> call that did not fail. In this case <code>extract_output</code> is the
pointer that was passed to the <code>ioctl</code> call.</p>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.0/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><details class="toggle implementors-toggle"><summary><section id="impl-Ioctl-for-Updater%3C'a,+Opcode,+T%3E" class="impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#185-198">Source</a><a href="#impl-Ioctl-for-Updater%3C'a,+Opcode,+T%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a, Opcode: <a class="trait" href="trait.CompileTimeOpcode.html" title="trait rustix::ioctl::CompileTimeOpcode">CompileTimeOpcode</a>, T&gt; <a class="trait" href="trait.Ioctl.html" title="trait rustix::ioctl::Ioctl">Ioctl</a> for <a class="struct" href="struct.Updater.html" title="struct rustix::ioctl::Updater">Updater</a>&lt;'a, Opcode, T&gt;</h3></section></summary><div class="impl-items"><section id="associatedconstant.IS_MUTATING-1" class="associatedconstant trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#188">Source</a><a href="#associatedconstant.IS_MUTATING-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.IS_MUTATING" class="constant">IS_MUTATING</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a> = true</h4></section><section id="associatedconstant.OPCODE-1" class="associatedconstant trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#189">Source</a><a href="#associatedconstant.OPCODE-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.OPCODE" class="constant">OPCODE</a>: <a class="struct" href="struct.Opcode.html" title="struct rustix::ioctl::Opcode">Opcode</a> = Opcode::OPCODE</h4></section><section id="associatedtype.Output-1" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#186">Source</a><a href="#associatedtype.Output-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Output" class="associatedtype">Output</a> = <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.unit.html">()</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Ioctl-for-NoArg%3COpcode%3E" class="impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#38-51">Source</a><a href="#impl-Ioctl-for-NoArg%3COpcode%3E" class="anchor">§</a><h3 class="code-header">impl&lt;Opcode: <a class="trait" href="trait.CompileTimeOpcode.html" title="trait rustix::ioctl::CompileTimeOpcode">CompileTimeOpcode</a>&gt; <a class="trait" href="trait.Ioctl.html" title="trait rustix::ioctl::Ioctl">Ioctl</a> for <a class="struct" href="struct.NoArg.html" title="struct rustix::ioctl::NoArg">NoArg</a>&lt;Opcode&gt;</h3></section></summary><div class="impl-items"><section id="associatedconstant.IS_MUTATING-2" class="associatedconstant trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#41">Source</a><a href="#associatedconstant.IS_MUTATING-2" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.IS_MUTATING" class="constant">IS_MUTATING</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a> = false</h4></section><section id="associatedconstant.OPCODE-2" class="associatedconstant trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#42">Source</a><a href="#associatedconstant.OPCODE-2" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.OPCODE" class="constant">OPCODE</a>: <a class="struct" href="struct.Opcode.html" title="struct rustix::ioctl::Opcode">Opcode</a> = Opcode::OPCODE</h4></section><section id="associatedtype.Output-2" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#39">Source</a><a href="#associatedtype.Output-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Output" class="associatedtype">Output</a> = <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.unit.html">()</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Ioctl-for-Setter%3COpcode,+Input%3E" class="impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#141-154">Source</a><a href="#impl-Ioctl-for-Setter%3COpcode,+Input%3E" class="anchor">§</a><h3 class="code-header">impl&lt;Opcode: <a class="trait" href="trait.CompileTimeOpcode.html" title="trait rustix::ioctl::CompileTimeOpcode">CompileTimeOpcode</a>, Input&gt; <a class="trait" href="trait.Ioctl.html" title="trait rustix::ioctl::Ioctl">Ioctl</a> for <a class="struct" href="struct.Setter.html" title="struct rustix::ioctl::Setter">Setter</a>&lt;Opcode, Input&gt;</h3></section></summary><div class="impl-items"><section id="associatedconstant.IS_MUTATING-3" class="associatedconstant trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#144">Source</a><a href="#associatedconstant.IS_MUTATING-3" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.IS_MUTATING" class="constant">IS_MUTATING</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a> = false</h4></section><section id="associatedconstant.OPCODE-3" class="associatedconstant trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#145">Source</a><a href="#associatedconstant.OPCODE-3" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.OPCODE" class="constant">OPCODE</a>: <a class="struct" href="struct.Opcode.html" title="struct rustix::ioctl::Opcode">Opcode</a> = Opcode::OPCODE</h4></section><section id="associatedtype.Output-3" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#142">Source</a><a href="#associatedtype.Output-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Output" class="associatedtype">Output</a> = <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.unit.html">()</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Ioctl-for-Getter%3COpcode,+Output%3E" class="impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#88-101">Source</a><a href="#impl-Ioctl-for-Getter%3COpcode,+Output%3E" class="anchor">§</a><h3 class="code-header">impl&lt;Opcode: <a class="trait" href="trait.CompileTimeOpcode.html" title="trait rustix::ioctl::CompileTimeOpcode">CompileTimeOpcode</a>, Output&gt; <a class="trait" href="trait.Ioctl.html" title="trait rustix::ioctl::Ioctl">Ioctl</a> for <a class="struct" href="struct.Getter.html" title="struct rustix::ioctl::Getter">Getter</a>&lt;Opcode, Output&gt;</h3></section></summary><div class="impl-items"><section id="associatedconstant.IS_MUTATING-4" class="associatedconstant trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#91">Source</a><a href="#associatedconstant.IS_MUTATING-4" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.IS_MUTATING" class="constant">IS_MUTATING</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a> = true</h4></section><section id="associatedconstant.OPCODE-4" class="associatedconstant trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#92">Source</a><a href="#associatedconstant.OPCODE-4" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.OPCODE" class="constant">OPCODE</a>: <a class="struct" href="struct.Opcode.html" title="struct rustix::ioctl::Opcode">Opcode</a> = Opcode::OPCODE</h4></section><section id="associatedtype.Output-4" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rustix/ioctl/patterns.rs.html#89">Source</a><a href="#associatedtype.Output-4" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Output" class="associatedtype">Output</a> = Output</h4></section></div></details></div><script src="../../trait.impl/rustix/ioctl/trait.Ioctl.js" async></script></section></div></main></body></html>