]>
Commit | Line | Data |
---|---|---|
ec7ea47d ZJS |
1 | <?xml version='1.0'?> |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" | |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
4 | <!-- SPDX-License-Identifier: LGPL-2.1+ --> | |
5 | ||
6 | <refentry id="sd_hwdb_get" xmlns:xi="http://www.w3.org/2001/XInclude"> | |
7 | <refentryinfo> | |
8 | <title>sd_hwdb_get</title> | |
9 | <productname>systemd</productname> | |
10 | </refentryinfo> | |
11 | ||
12 | <refmeta> | |
13 | <refentrytitle>sd_hwdb_get</refentrytitle> | |
14 | <manvolnum>3</manvolnum> | |
15 | </refmeta> | |
16 | ||
17 | <refnamediv> | |
18 | <refname>sd_hwdb_get</refname> | |
19 | <refname>sd_hwdb_seek</refname> | |
20 | <refname>sd_hwdb_enumerate</refname> | |
32c4d2ba | 21 | <refname>SD_HWDB_FOREACH_PROPERTY</refname> |
ec7ea47d ZJS |
22 | |
23 | <refpurpose>Seek to a location in hwdb or access entries</refpurpose> | |
24 | </refnamediv> | |
25 | ||
26 | <refsynopsisdiv> | |
27 | <funcsynopsis> | |
28 | <funcsynopsisinfo>#include <systemd/sd-hwdb.h></funcsynopsisinfo> | |
29 | ||
30 | <funcprototype> | |
31 | <funcdef>int <function>sd_hwdb_get</function></funcdef> | |
32 | <paramdef>sd_hwdb *<parameter>hwdb</parameter></paramdef> | |
33 | <paramdef>const char *<parameter>modalias</parameter></paramdef> | |
34 | <paramdef>const char *<parameter>key</parameter></paramdef> | |
35 | <paramdef>const char **<parameter>value</parameter></paramdef> | |
36 | </funcprototype> | |
37 | ||
38 | <funcprototype> | |
39 | <funcdef>int <function>sd_hwdb_seek</function></funcdef> | |
40 | <paramdef>sd_hwdb *<parameter>hwdb</parameter></paramdef> | |
41 | <paramdef>const char *<parameter>modalias</parameter></paramdef> | |
42 | </funcprototype> | |
43 | ||
44 | <funcprototype> | |
45 | <funcdef>int <function>sd_hwdb_enumerate</function></funcdef> | |
46 | <paramdef>sd_hwdb *<parameter>hwdb</parameter></paramdef> | |
47 | <paramdef>const char **<parameter>key</parameter></paramdef> | |
48 | <paramdef>const char **<parameter>value</parameter></paramdef> | |
49 | </funcprototype> | |
50 | ||
32c4d2ba ZJS |
51 | <funcprototype> |
52 | <funcdef><function>SD_HWDB_FOREACH_PROPERTY</function></funcdef> | |
53 | <paramdef>hwdb</paramdef> | |
54 | <paramdef>modalias</paramdef> | |
55 | <paramdef>key</paramdef> | |
56 | <paramdef>value</paramdef> | |
57 | </funcprototype> | |
ec7ea47d ZJS |
58 | </funcsynopsis> |
59 | </refsynopsisdiv> | |
60 | ||
61 | <refsect1> | |
62 | <title>Description</title> | |
63 | ||
64 | <para><function>sd_hwdb_get()</function> queries the <parameter>hwdb</parameter> object created earlier | |
65 | with <citerefentry><refentrytitle>sd_hwdb_new</refentrytitle><manvolnum>3</manvolnum></citerefentry> for | |
66 | entries matching the specified string <parameter>modalias</parameter>, and returns the value | |
67 | corresponding to the the key <parameter>key</parameter>. The value is returned as a | |
68 | <constant>NUL</constant>-terminated string in <parameter>value</parameter>. It must not be modified by | |
69 | the caller and is valid as long as a reference to <parameter>hwdb</parameter> is kept. When multiple | |
70 | patterns in the database match <parameter>modalias</parameter>, the one with the highest priority is | |
71 | used. See <citerefentry><refentrytitle>hwdb</refentrytitle><manvolnum>7</manvolnum></citerefentry> for | |
72 | details.</para> | |
73 | ||
74 | <para><function>sd_hwdb_seek()</function> selects entries matching the specified string | |
75 | <parameter>modalias</parameter>. Subsequent queries with <function>sd_hwdb_enumerate()</function> will | |
76 | access the key-value pairs for that string.</para> | |
77 | ||
78 | <para><function>sd_hwdb_enumerate()</function> returns (in turn) all the key-value pairs defined for the | |
79 | string used with <function>sd_hwdb_seek()</function>. Each pair is returned as | |
80 | <constant>NUL</constant>-terminated strings in <parameter>key</parameter> and | |
81 | <parameter>value</parameter>. The strings must not be modified by the caller and are valid as long as a | |
82 | reference to <parameter>hwdb</parameter> is kept. When multiple patterns in the database match | |
83 | <parameter>modalias</parameter>, the combination of all matching key-value pairs is used. See | |
84 | <citerefentry><refentrytitle>hwdb</refentrytitle><manvolnum>7</manvolnum></citerefentry> for | |
85 | details.</para> | |
32c4d2ba ZJS |
86 | |
87 | <para>The <function>SD_HWDB_FOREACH_PROPERTY</function> macro combines | |
88 | <function>sd_hwdb_seek()</function> and <function>sd_hwdb_enumerate()</function>. No error handling is | |
86b52a39 | 89 | performed and iteration simply stops on error. See the example below.</para> |
ec7ea47d ZJS |
90 | </refsect1> |
91 | ||
92 | <refsect1> | |
93 | <title>Return Value</title> | |
94 | ||
95 | <para>On success, <function>sd_hwdb_get()</function> and <function>sd_hwdb_seek()</function> return a | |
96 | non-negative integer. On failure, they return a negative errno-style error code.</para> | |
97 | ||
98 | <para><function>sd_hwdb_enumerate()</function> returns a positive integer if another key-value pair was found or zero if | |
99 | all entries have already been enumerated. On failure, it returns a negative errno-style error code. | |
100 | </para> | |
101 | ||
102 | <refsect2> | |
103 | <title>Errors</title> | |
104 | ||
105 | <para>Returned errors may indicate the following problems:</para> | |
106 | ||
107 | <variablelist> | |
108 | <varlistentry> | |
109 | <term><constant>-EINVAL</constant></term> | |
110 | ||
111 | <listitem><para>A parameter is <constant>NULL</constant>.</para></listitem> | |
112 | </varlistentry> | |
113 | ||
114 | <varlistentry> | |
115 | <term><constant>-ENOENT</constant></term> | |
116 | ||
117 | <listitem><para>An entry for the specified <parameter>modalias</parameter> was not found. | |
118 | </para></listitem> | |
119 | </varlistentry> | |
120 | ||
121 | <varlistentry> | |
122 | <term><constant>-EAGAIN</constant></term> | |
123 | ||
124 | <listitem><para><function>sd_hwdb_seek()</function> was not called before | |
125 | <function>sd_hwdb_enumerate()</function>.</para></listitem> | |
126 | </varlistentry> | |
127 | </variablelist> | |
128 | </refsect2> | |
129 | </refsect1> | |
130 | ||
131 | <xi:include href="libsystemd-pkgconfig.xml" /> | |
132 | ||
32c4d2ba ZJS |
133 | <refsect1> |
134 | <title>Examples</title> | |
135 | ||
136 | <example> | |
137 | <title>Look up hwdb entries for a USB device</title> | |
138 | ||
139 | <programlisting><xi:include href="hwdb-usb-device.c" parse="text" /></programlisting> | |
140 | ||
141 | <para>The effect is similar to calling <command>systemd-hwdb query usb:v046DpC534</command>. | |
142 | </para> | |
143 | </example> | |
144 | </refsect1> | |
145 | ||
ec7ea47d ZJS |
146 | <refsect1> |
147 | <title>See Also</title> | |
148 | ||
149 | <para> | |
150 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
151 | <citerefentry><refentrytitle>systemd-udev.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>, | |
152 | <citerefentry><refentrytitle>sd-hwdb</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
153 | <citerefentry><refentrytitle>systemd-hwdb</refentrytitle><manvolnum>8</manvolnum></citerefentry> | |
154 | </para> | |
155 | </refsect1> | |
156 | ||
157 | </refentry> |