summaryrefslogtreecommitdiffstats
path: root/share/man/man9/resource_query_string.9
blob: 7d753b8d6e84ebd8e6a6a2e25534d1f57579a870 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
.\" -*- nroff -*-
.\"
.\" Copyright (c) 2001 M. Warner Losh
.\"
.\" All rights reserved.
.\"
.\" This program is free software.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd March 1, 2001
.Dt RESOURCE_QUERY_STRING 9
.Os
.Sh NAME
.Nm resource_query_string , resource_query_name , resource_query_unit
.Nd query the
.Dq hints
database for matches
.Sh SYNOPSIS
.Fd #include <sys/bus.h>
.Ft int
.Fn resource_query_string "int num" "const char *field" "const char *what"
.Ft char *
.Fn resource_query_name "int num"
.Ft int
.Fn resource_query_unit "int num"
.Sh DESCRIPTION
.Fn resource_query_string
enumerates all devices in the
.Dq hints
database whose
.Fa field
value matches the
.Fa what
parameter.
A cookie is returned for use as the
.Fa num
parameter in calls to
.Fn resource_query_name
and
.Fn resource_query_unit .
This cookie should be passed as the
.Fa num
parameter on subsequent calls.
A return value of \-1 means no further matches exist.
.Pp
.Fn resource_query_name
returns the name of the device matched by
.Fn resource_query_string .
.Pp
.Fn resource_query_unit
returns the unit of the device matched by
.Fn resource_query_string .
.Pp
The functions take the following arguments:
.Bl -tag -width "field"
.It Fa num
is the
.Dq index
of the item to lookup.
Set to \-1 for the first call, and the return value of the previous
.Fn resource_query_string
on subsequent calls.
The
.Dq index
is an opaque cookie.
.It Fa field
is the name of the field in the
.Dq hints
database to query.
.It Fa what
is the value of
.Fa field
in the
.Dq hints
database for which to search.
.El
.Sh RETURN VALUES
.Fn resource_query_string
returns \-1 on failure, otherwise a cookie to pass to
.Fn resource_query_name
or
.Fn resource_query_unit .
.Pp
.Fn resource_query_name
returns the device name matching the cookie.
.Pp
.Fn resource_query_unit
returns the device unit number matching the cookie.
.Sh EXAMPLES
The following example will return all the
.Dq hints
that say they are
.Dq Li "at gerbil0" .
.Pp
An example hint would be:
.Bd -literal -offset indent
hint.habitat.0.at="gerbil0"
hint.ewheel.0.at="gerbil0"
hint.fred.0.at="nexus"
.Ed
.Pp
The following code
.Bd -literal -offset indent
int i = -1;
while ((i = resource_query_string(i, "at", "gerbil0")) != -1) {
	printf("Found %s%d at gerbil0\en", resource_query_name(i),
	    resource_query_unit(i));
}
.Ed
.Pp
would produce two lines:
.Bd -literal -offset indent
Found habitat0 at gerbil0
Found ewheel0 at gerbil0
.Ed
.Sh SEE ALSO
.Xr device 9 ,
.Xr driver 9 ,
.Xr resource_int_value 9
.Sh AUTHORS
This manual page was written by
.An Warner Losh Aq imp@FreeBSD.org .
OpenPOWER on IntegriCloud