freebsd-skq/share/man/man9/resource_query_string.9

144 lines
3.8 KiB
Groff

.\" -*- 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 .