summaryrefslogtreecommitdiff
path: root/static/freebsd/man9/devfs_set_cdevpriv.9 3.html
blob: 46f226bb941c302e9ed5b29864238376359d3b7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<table class="head">
  <tr>
    <td class="head-ltitle">DEVFS_CDEVPRIV(9)</td>
    <td class="head-vol">Kernel Developer's Manual</td>
    <td class="head-rtitle">DEVFS_CDEVPRIV(9)</td>
  </tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">devfs_set_cdevpriv</code>,
    <code class="Nm">devfs_get_cdevpriv</code>,
    <code class="Nm">devfs_clear_cdevpriv</code>,
    <code class="Nm">devfs_foreach_cdevpriv</code> &#x2014;
    <span class="Nd">manage per-open filedescriptor data for devices</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
    &lt;<a class="In">sys/param.h</a>&gt;</code>
  <br/>
  <code class="In">#include &lt;<a class="In">sys/conf.h</a>&gt;</code></p>
<div class="Bd Pp Li">
<pre>typedef	void d_priv_dtor_t(void *data);</pre>
</div>
<br/>
<var class="Ft">int</var>
<br/>
<code class="Fn">devfs_get_cdevpriv</code>(<var class="Fa" style="white-space: nowrap;">void
  **datap</var>);
<p class="Pp"><var class="Ft">int</var>
  <br/>
  <code class="Fn">devfs_set_cdevpriv</code>(<var class="Fa" style="white-space: nowrap;">void
    *priv</var>, <var class="Fa" style="white-space: nowrap;">d_priv_dtor_t
    *dtr</var>);</p>
<p class="Pp"><var class="Ft">void</var>
  <br/>
  <code class="Fn">devfs_clear_cdevpriv</code>(<var class="Fa" style="white-space: nowrap;">void</var>);</p>
<p class="Pp"><var class="Ft">int</var>
  <br/>
  <code class="Fn">devfs_foreach_cdevpriv</code>(<var class="Fa">struct cdev
    *dev</var>, <var class="Fa">int (*cb)(void *data, void *arg)</var>,
    <var class="Fa">void *arg</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The
    <a class="permalink" href="#devfs_xxx_cdevpriv"><code class="Fn" id="devfs_xxx_cdevpriv">devfs_xxx_cdevpriv</code></a>()
    family of functions allows the <var class="Fa">cdev</var> driver methods to
    associate some driver-specific data with each user process
    <a class="Xr">open(2)</a> of the device special file. Currently, functioning
    of these functions is restricted to the context of the
    <var class="Fa">cdevsw</var> switch method calls performed as
    <a class="Xr">devfs(4)</a> operations in response to system calls that use
    filedescriptors.</p>
<p class="Pp" id="devfs_set_cdevpriv">The
    <a class="permalink" href="#devfs_set_cdevpriv"><code class="Fn">devfs_set_cdevpriv</code></a>()
    function associates a data pointed by <var class="Va">priv</var> with
    current calling context (filedescriptor). The data may be retrieved later,
    possibly from another call performed on this filedescriptor, by the
    <code class="Fn">devfs_get_cdevpriv</code>() function. The
    <code class="Fn">devfs_clear_cdevpriv</code>() disassociates previously
    attached data from context. Immediately after
    <code class="Fn">devfs_clear_cdevpriv</code>() finished operating, the
    <var class="Va">dtr</var> callback is called, with private data supplied
    <var class="Va">data</var> argument. The
    <code class="Fn">devfs_clear_cdevpriv</code>() function will be also be
    called if the open callback function returns an error code.</p>
<p class="Pp" id="devfs_clear_cdevpriv">On the last filedescriptor close, system
    automatically arranges
    <a class="permalink" href="#devfs_clear_cdevpriv"><code class="Fn">devfs_clear_cdevpriv</code></a>()
    call.</p>
<p class="Pp">If successful, the functions return 0.</p>
<p class="Pp" id="devfs_set_cdevpriv~2">The function
    <a class="permalink" href="#devfs_set_cdevpriv~2"><code class="Fn">devfs_set_cdevpriv</code></a>()
    returns the following values on error:</p>
<dl class="Bl-tag">
  <dt>[<code class="Er">ENOENT</code>]</dt>
  <dd>The current call is not associated with some filedescriptor.</dd>
  <dt>[<code class="Er">EBUSY</code>]</dt>
  <dd>The private driver data is already associated with current
    filedescriptor.</dd>
</dl>
<p class="Pp" id="devfs_get_cdevpriv">The function
    <a class="permalink" href="#devfs_get_cdevpriv"><code class="Fn">devfs_get_cdevpriv</code></a>()
    returns the following values on error:</p>
<dl class="Bl-tag">
  <dt>[<code class="Er">EBADF</code>]</dt>
  <dd>The current call is not associated with some filedescriptor.</dd>
  <dt>[<code class="Er">ENOENT</code>]</dt>
  <dd>The private driver data was not associated with current filedescriptor, or
      <code class="Fn">devfs_clear_cdevpriv</code>() was called.</dd>
</dl>
<p class="Pp" id="devfs_foreach_cdevpriv">The function
    <a class="permalink" href="#devfs_foreach_cdevpriv"><code class="Fn">devfs_foreach_cdevpriv</code></a>()
    sequentially calls the function <var class="Fa">cb</var> for each
    <code class="Nm">cdevpriv</code> structure, currently associated with the
    <var class="Fa">cdev</var> device. The iterated
    <code class="Nm">cdevpriv</code> data pointer and the user-supplied context
    <var class="Fa">arg</var> are passed to the function
    <var class="Fa">cb</var>. If <var class="Fa">cb</var> returns non-zero
    value, the iteration stops on that element. The
    <code class="Fn">devfs_foreach_cdevpriv</code>() returns the return value
    from the last call to <var class="Fa">cb</var>, or zero if no
    <code class="Nm">cdevpriv</code> data is currently associated with the
    device.</p>
<p class="Pp">Current implementation of the iterator makes it impossible to use
    any blockable locking inside the callback <var class="Fa">cb</var>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
  ALSO</a></h1>
<p class="Pp"><a class="Xr">close(2)</a>, <a class="Xr">open(2)</a>,
    <a class="Xr">devfs(4)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">The <code class="Fn">devfs_cdevpriv</code>() family of functions
    first appeared in <span class="Ux">FreeBSD 7.1</span>.</p>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">March 23, 2024</td>
    <td class="foot-os">FreeBSD 15.0</td>
  </tr>
</table>