| 1 |
<?xml version="1.0"?> |
| 2 |
<!DOCTYPE refentries PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="sd_device_enumerator_add_match_parent" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 7 |
<refentryinfo> |
| 8 |
<title>sd_device_enumerator_add_match_parent</title> |
| 9 |
<productname>systemd</productname> |
| 10 |
</refentryinfo> |
| 11 |
|
| 12 |
<refmeta> |
| 13 |
<refentrytitle>sd_device_enumerator_add_match_parent</refentrytitle> |
| 14 |
<manvolnum>3</manvolnum> |
| 15 |
</refmeta> |
| 16 |
|
| 17 |
<refnamediv> |
| 18 |
<refname>sd_device_enumerator_add_match_parent</refname> |
| 19 |
<refname>sd_device_enumerator_add_match_property</refname> |
| 20 |
<refname>sd_device_enumerator_add_match_property_required</refname> |
| 21 |
<refname>sd_device_enumerator_add_match_subsystem</refname> |
| 22 |
<refname>sd_device_enumerator_add_match_sysattr</refname> |
| 23 |
<refname>sd_device_enumerator_add_match_sysname</refname> |
| 24 |
<refname>sd_device_enumerator_add_nomatch_sysname</refname> |
| 25 |
<refname>sd_device_enumerator_add_match_tag</refname> |
| 26 |
<refname>sd_device_enumerator_allow_uninitialized</refname> |
| 27 |
<refname>sd_device_enumerator_add_all_parents</refname> |
| 28 |
<refpurpose>Add a filter to the device enumerator</refpurpose> |
| 29 |
</refnamediv> |
| 30 |
|
| 31 |
<refsynopsisdiv> |
| 32 |
<funcsynopsis> |
| 33 |
<funcsynopsisinfo>#include <systemd/sd-device.h></funcsynopsisinfo> |
| 34 |
|
| 35 |
<funcprototype> |
| 36 |
<funcdef>int <function>sd_device_enumerator_add_match_parent</function></funcdef> |
| 37 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 38 |
<paramdef>sd_device *<parameter>parent</parameter></paramdef> |
| 39 |
</funcprototype> |
| 40 |
|
| 41 |
<funcprototype> |
| 42 |
<funcdef>int <function>sd_device_enumerator_add_match_property</function></funcdef> |
| 43 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 44 |
<paramdef>const char *<parameter>property</parameter></paramdef> |
| 45 |
<paramdef>const char *<parameter>value</parameter></paramdef> |
| 46 |
</funcprototype> |
| 47 |
|
| 48 |
<funcprototype> |
| 49 |
<funcdef>int <function>sd_device_enumerator_add_match_property_required</function></funcdef> |
| 50 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 51 |
<paramdef>const char *<parameter>property</parameter></paramdef> |
| 52 |
<paramdef>const char *<parameter>value</parameter></paramdef> |
| 53 |
</funcprototype> |
| 54 |
|
| 55 |
<funcprototype> |
| 56 |
<funcdef>int <function>sd_device_enumerator_add_match_subsystem</function></funcdef> |
| 57 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 58 |
<paramdef>const char *<parameter>subsystem</parameter></paramdef> |
| 59 |
<paramdef>int <parameter>match</parameter></paramdef> |
| 60 |
</funcprototype> |
| 61 |
|
| 62 |
<funcprototype> |
| 63 |
<funcdef>int <function>sd_device_enumerator_add_match_sysattr</function></funcdef> |
| 64 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 65 |
<paramdef>const char *<parameter>sysattr</parameter></paramdef> |
| 66 |
<paramdef>const char *<parameter>value</parameter></paramdef> |
| 67 |
<paramdef>int <parameter>match</parameter></paramdef> |
| 68 |
</funcprototype> |
| 69 |
|
| 70 |
<funcprototype> |
| 71 |
<funcdef>int <function>sd_device_enumerator_add_match_sysname</function></funcdef> |
| 72 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 73 |
<paramdef>const char *<parameter>sysname</parameter></paramdef> |
| 74 |
</funcprototype> |
| 75 |
|
| 76 |
<funcprototype> |
| 77 |
<funcdef>int <function>sd_device_enumerator_add_nomatch_sysname</function></funcdef> |
| 78 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 79 |
<paramdef>const char *<parameter>sysname</parameter></paramdef> |
| 80 |
</funcprototype> |
| 81 |
|
| 82 |
<funcprototype> |
| 83 |
<funcdef>int <function>sd_device_enumerator_add_match_tag</function></funcdef> |
| 84 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 85 |
<paramdef>const char *<parameter>tag</parameter></paramdef> |
| 86 |
</funcprototype> |
| 87 |
|
| 88 |
<funcprototype> |
| 89 |
<funcdef>int <function>sd_device_enumerator_allow_uninitialized</function></funcdef> |
| 90 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 91 |
</funcprototype> |
| 92 |
|
| 93 |
<funcprototype> |
| 94 |
<funcdef>int <function>sd_device_enumerator_add_all_parents</function></funcdef> |
| 95 |
<paramdef>sd_device_enumerator *<parameter>enumerator</parameter></paramdef> |
| 96 |
</funcprototype> |
| 97 |
|
| 98 |
</funcsynopsis> |
| 99 |
</refsynopsisdiv> |
| 100 |
|
| 101 |
<refsect1> |
| 102 |
<title>Description</title> |
| 103 |
<para>The <function>sd_device_enumerator_add_match_parent()</function> function adds a filter to |
| 104 |
the <parameter>enumerator</parameter> so that only devices under the tree of the specified |
| 105 |
<parameter>parent</parameter> device are enumerated. If this is called multiple times the |
| 106 |
previously set <parameter>parent</parameter> device is cleared and only the last call takes an |
| 107 |
effect.</para> |
| 108 |
|
| 109 |
<para>The <function>sd_device_enumerator_add_match_property()</function> function adds a filter to |
| 110 |
the <parameter>enumerator</parameter> so that only devices with the specified |
| 111 |
<parameter>property</parameter> equals to the <parameter>value</parameter> are enumerated. |
| 112 |
Both <parameter>property</parameter> and <parameter>value</parameter> can be a glob pattern. |
| 113 |
When this is called multiple times, devices that have at least one of the specified |
| 114 |
properties with matching values are enumerated. That is, filters are ORed.</para> |
| 115 |
|
| 116 |
<para>The <function>sd_device_enumerator_add_match_property_required()</function> function adds a |
| 117 |
filter to the <parameter>enumerator</parameter> so that only devices with the specified |
| 118 |
<parameter>property</parameter> equals to the <parameter>value</parameter> are enumerated. |
| 119 |
This function is similar to <function>sd_device_enumerator_add_match_property()</function>, but when |
| 120 |
this is called multiple times, devices that have <emphasis>all</emphasis> specified properties |
| 121 |
with matching values are enumerated. That is, filters are ANDed.</para> |
| 122 |
|
| 123 |
<para>The <function>sd_device_enumerator_add_match_subsystem()</function> function adds a filter |
| 124 |
to the <parameter>enumerator</parameter> so that all devices in the specified |
| 125 |
<parameter>subsystem</parameter>, when <parameter>match</parameter> is <constant>true</constant>. |
| 126 |
When <parameter>match</parameter> is <constant>false</constant>, then all devices except those in |
| 127 |
the specified <parameter>subsystem</parameter> are enumerated. When called multiple times, |
| 128 |
positive filters are ORed, and negative ones are ANDed.</para> |
| 129 |
|
| 130 |
<para>The <function>sd_device_enumerator_add_match_sysattr()</function> function adds a filter on |
| 131 |
the sysfs attribute <parameter>sysattr</parameter> matching <parameter>value</parameter>. |
| 132 |
<parameter>value</parameter> can be a glob pattern. If <parameter>value</parameter> is |
| 133 |
<constant>NULL</constant>, devices that either have (if <parameter>match</parameter> |
| 134 |
is <constant>true</constant>) or do not have (if <parameter>match</parameter> is |
| 135 |
<constant>false</constant>) the specified <parameter>sysattr</parameter> are included, regardless |
| 136 |
of its value. That is, <constant>NULL</constant> is mostly equivalent to <literal>*</literal>. |
| 137 |
When this function is called multiple times, only devices that match all specified |
| 138 |
<parameter>sysattr</parameter> filters are enumerated. That is, these filters are ANDed.</para> |
| 139 |
|
| 140 |
<para>The <function>sd_device_enumerator_add_match_sysname()</function> function adds a filter so |
| 141 |
that only devices whose sysname equals to <parameter>sysname</parameter> are enumerated. |
| 142 |
<parameter>sysname</parameter> can be a glob pattern. When called multiple times, filters are ORed.</para> |
| 143 |
|
| 144 |
<para>The <function>sd_device_enumerator_add_nomatch_sysname()</function> function adds a filter |
| 145 |
so that devices whose sysname equals to <parameter>sysname</parameter> are excluded from the |
| 146 |
enumeration. This is useful for excluding specific devices from the enumeration process. |
| 147 |
When called multiple times, features are ANDed.</para> |
| 148 |
|
| 149 |
<para>The <function>sd_device_enumerator_add_match_tag()</function> function adds a filter so that |
| 150 |
only devices tagged with <parameter>tag</parameter> are enumerated. When called multiple times, |
| 151 |
filters are ORed.</para> |
| 152 |
|
| 153 |
<para>The <function>sd_device_enumerator_allow_uninitialized()</function> function allows devices |
| 154 |
that have not yet been initialized by udev to be included in the enumeration.</para> |
| 155 |
|
| 156 |
<para>The <function>sd_device_enumerator_add_all_parents()</function> function enumerates all parent |
| 157 |
devices of the matching devices. This is useful for cases where you want to include all parent |
| 158 |
devices in the enumeration, such as when you are interested in the entire device tree leading up |
| 159 |
to a specific device.</para> |
| 160 |
</refsect1> |
| 161 |
|
| 162 |
<refsect1> |
| 163 |
<title>Return Value</title> |
| 164 |
|
| 165 |
<para>All functions return <constant>0</constant> or a positive integer on success, or a negative |
| 166 |
errno-style error code on failure.</para> |
| 167 |
|
| 168 |
<refsect2> |
| 169 |
<title>Errors</title> |
| 170 |
|
| 171 |
<para>Returned errors may indicate the following problems:</para> |
| 172 |
|
| 173 |
<variablelist> |
| 174 |
<varlistentry> |
| 175 |
<term><constant>-ENOMEM</constant></term> |
| 176 |
|
| 177 |
<listitem><para>Memory allocation failed.</para></listitem> |
| 178 |
</varlistentry> |
| 179 |
<varlistentry> |
| 180 |
<term><constant>-EINVAL</constant></term> |
| 181 |
|
| 182 |
<listitem><para>One of the arguments is invalid.</para></listitem> |
| 183 |
</varlistentry> |
| 184 |
</variablelist> |
| 185 |
</refsect2> |
| 186 |
</refsect1> |
| 187 |
|
| 188 |
<refsect1> |
| 189 |
<title>Examples</title> |
| 190 |
|
| 191 |
<example> |
| 192 |
<title>Detect Removable USB Devices (Using Match and Exclude)</title> |
| 193 |
<programlisting><xi:include href="sd_device_enumerator_add_match_parent-example.c" parse="text"/></programlisting> |
| 194 |
</example> |
| 195 |
</refsect1> |
| 196 |
|
| 197 |
<refsect1> |
| 198 |
<title>History</title> |
| 199 |
<para><function>sd_device_enumerator_add_match_parent()</function>, |
| 200 |
<function>sd_device_enumerator_add_match_property()</function>, |
| 201 |
<function>sd_device_enumerator_add_match_subsystem()</function>, |
| 202 |
<function>sd_device_enumerator_add_match_sysattr()</function>, |
| 203 |
<function>sd_device_enumerator_add_match_sysname()</function>, |
| 204 |
<function>sd_device_enumerator_add_match_tag()</function>, and |
| 205 |
<function>sd_device_enumerator_allow_uninitialized()</function> were added in version 240.</para> |
| 206 |
|
| 207 |
<para><function>sd_device_enumerator_add_nomatch_sysname()</function> was added in version 251.</para> |
| 208 |
|
| 209 |
<para><function>sd_device_enumerator_add_match_property_required()</function> was added in version 255.</para> |
| 210 |
|
| 211 |
<para><function>sd_device_enumerator_add_all_parents()</function> was added in version 258.</para> |
| 212 |
</refsect1> |
| 213 |
|
| 214 |
<refsect1> |
| 215 |
<title>See Also</title> |
| 216 |
|
| 217 |
<para><simplelist type="inline"> |
| 218 |
<member><citerefentry><refentrytitle>sd_device_ref</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 219 |
<member><citerefentry><refentrytitle>sd_device_enumerator_new</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 220 |
<member><citerefentry><refentrytitle>sd_device_enumerator_get_device_first</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 221 |
</simplelist></para> |
| 222 |
</refsect1> |
| 223 |
</refentry> |