2003-06-30 16:10:40 +04:00
|
|
|
.\" $NetBSD: properties.9,v 1.9 2003/06/30 12:10:40 wiz Exp $
|
2001-10-04 22:56:06 +04:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2001 Eduardo Horvath
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed for the
|
2003-02-14 18:20:17 +03:00
|
|
|
.\" NetBSD Project. See http://www.NetBSD.org/ for
|
2001-10-04 22:56:06 +04:00
|
|
|
.\" information about NetBSD.
|
|
|
|
.\" 4. The name of the author may not be used to endorse or promote products
|
|
|
|
.\" derived from this software without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
.\"
|
|
|
|
.\"
|
|
|
|
.Dd October 3, 2001
|
|
|
|
.Dt PROPERTIES 9
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm propdb_create ,
|
|
|
|
.Nm propdb_destroy ,
|
|
|
|
.Nm prop_set ,
|
|
|
|
.Nm prop_get ,
|
|
|
|
.Nm prop_delete ,
|
|
|
|
.Nm prop_copy ,
|
|
|
|
.Nm prop_objs ,
|
|
|
|
.Nm prop_list
|
|
|
|
.Nd generic kernel properties
|
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In sys/properties.h
|
2001-10-04 22:56:06 +04:00
|
|
|
.Pp
|
2001-10-04 23:39:41 +04:00
|
|
|
.Va typedef void *propdb_t;
|
2001-10-04 22:56:06 +04:00
|
|
|
.Pp
|
2001-10-04 23:39:41 +04:00
|
|
|
.Va typedef int64_t opaque_t;
|
2001-10-04 22:56:06 +04:00
|
|
|
.Ft propdb_t
|
|
|
|
.Fn propdb_create "const char *name"
|
|
|
|
.Ft void
|
|
|
|
.Fn propdb_destroy "propdb_t db"
|
|
|
|
.Ft int
|
|
|
|
.Fn prop_set "propdb_t db" "opaque_t object" "const char *name" "void *val" \
|
|
|
|
"size_t len" "int type" "int wait"
|
|
|
|
.Ft size_t
|
|
|
|
.Fn prop_get "propdb_t db" "opaque_t object" "const char *name" "void *val" \
|
|
|
|
"size_t len" "int *type"
|
|
|
|
.Ft int
|
|
|
|
.Fn prop_delete "propdb_t db" "opaque_t object" "const char *name"
|
|
|
|
.Ft int
|
|
|
|
.Fn prop_copy "propdb_t db" "opaque_t source" "opaque_t dest" "int wait"
|
|
|
|
.Ft size_t
|
|
|
|
.Fn prop_objs "propdb_t db" "opaque_t *objects" "size_t len"
|
|
|
|
.Ft size_t
|
|
|
|
.Fn prop_list "propdb_t db" "opaque_t object" "char *names" "size_t len"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nx
|
|
|
|
property management routines allow kernel subsystems to associate
|
2001-10-04 23:39:41 +04:00
|
|
|
.Po name , value Pc
|
|
|
|
pairs with arbitrary keys in a generalized manner.
|
2001-10-04 22:56:06 +04:00
|
|
|
.Pp
|
2002-10-14 17:43:14 +04:00
|
|
|
A database is a container for a set of properties.
|
|
|
|
It is created with
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fn propdb_create
|
2001-10-04 23:39:41 +04:00
|
|
|
and discarded with
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fn propdb_destroy .
|
|
|
|
Kernel subsystems should create their own databases to prevent possible
|
|
|
|
namespace conflicts.
|
|
|
|
.Pp
|
2001-10-04 23:39:41 +04:00
|
|
|
A property is a tuple that consists of an opaque identifier
|
2001-10-04 22:56:06 +04:00
|
|
|
.Po often a pointer to a kernel data structure
|
2001-10-04 23:39:41 +04:00
|
|
|
.Pc ,
|
2002-10-14 17:43:14 +04:00
|
|
|
string, and an arbitrary amount of data.
|
|
|
|
This association is established by
|
2001-10-04 23:39:41 +04:00
|
|
|
.Fn prop_set ,
|
|
|
|
retrieved by
|
|
|
|
.Fn prop_get ,
|
2001-10-04 22:56:06 +04:00
|
|
|
and destroyed by
|
|
|
|
.Fn prop_delete .
|
|
|
|
.Pp
|
2001-10-04 23:39:41 +04:00
|
|
|
A system call interface makes use of the existing
|
2001-10-04 22:56:06 +04:00
|
|
|
.Ic sysctl
|
|
|
|
interface, and is provided
|
|
|
|
primarily for diagnostic purposes.
|
|
|
|
.Sh TYPES
|
2001-10-04 23:39:41 +04:00
|
|
|
Several types are defined in
|
2003-06-30 16:10:40 +04:00
|
|
|
.Aq Pa sys/properties.h .
|
2001-10-04 23:39:41 +04:00
|
|
|
.Pp
|
2001-10-04 22:56:06 +04:00
|
|
|
.Bl -ohang -compact
|
|
|
|
.It Fa propdb_t
|
2001-10-04 23:39:41 +04:00
|
|
|
.Pp
|
|
|
|
The
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa probdb_t
|
|
|
|
type is used to contain a handle for a property database.
|
|
|
|
.Pp
|
|
|
|
.It Fa opaque_t
|
2001-10-04 23:39:41 +04:00
|
|
|
.Pp
|
|
|
|
The
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa opaque_t
|
|
|
|
type is a 64-bit scalar type used to store arbitrary object identifiers.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nm
|
2001-10-04 23:39:41 +04:00
|
|
|
makes no type distinctions, but it does associate a type datum with each
|
2002-10-14 17:43:14 +04:00
|
|
|
property.
|
|
|
|
Users of the interface can use that field to help determine what
|
|
|
|
information is stored in the value field of the property.
|
|
|
|
There are three base types:
|
2001-10-04 22:56:06 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
2001-10-04 23:39:41 +04:00
|
|
|
.Bl -tag -width "PROP_ELSZ(type) " -compact -offset indent
|
2001-10-04 22:56:06 +04:00
|
|
|
.It PROP_INT
|
|
|
|
Property is an integer type.
|
|
|
|
.It PROP_STRING
|
|
|
|
Property is a string.
|
|
|
|
.It PROP_AGGREGATE
|
|
|
|
Property is an aggregation of different types.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Which can be further modified:
|
|
|
|
.Pp
|
2001-10-04 23:39:41 +04:00
|
|
|
.Bl -tag -width "PROP_ELSZ(type) " -compact -offset indent
|
2001-10-04 22:56:06 +04:00
|
|
|
.It PROP_ARRAY
|
|
|
|
Property is an array of values.
|
|
|
|
.It PROP_CONST
|
|
|
|
Property value has static storage and is maintained outside the database.
|
2001-10-04 23:39:41 +04:00
|
|
|
.It PROP_ELSZ Pq Fa size
|
2002-10-14 17:43:14 +04:00
|
|
|
Encode element size into the type field.
|
|
|
|
This is primarily used to describe the size of individual elements
|
|
|
|
of an array.
|
2001-10-04 22:56:06 +04:00
|
|
|
.El
|
|
|
|
.Sh FUNCTIONS
|
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Fn "propdb_t propdb_create" "const char *name"
|
|
|
|
.Pp
|
2001-10-04 23:39:41 +04:00
|
|
|
Allocate and initialize a kernel database object, and associate
|
|
|
|
.Fa name
|
|
|
|
with the database.
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa name
|
2003-01-06 15:29:48 +03:00
|
|
|
may later be used to access this database from userland through the
|
2002-10-14 17:43:14 +04:00
|
|
|
userland database query interface.
|
|
|
|
This operation may block.
|
2001-10-04 23:39:41 +04:00
|
|
|
Returns
|
|
|
|
.Li NULL
|
2001-10-04 22:56:06 +04:00
|
|
|
on failure.
|
|
|
|
.Pp
|
|
|
|
.It Fn "void propdb_destroy" "propdb_t db"
|
2002-10-14 17:43:14 +04:00
|
|
|
Destroy and deallocate a kernel database and all data within.
|
|
|
|
This routine deallocates all properties contained within the database.
|
2001-10-04 22:56:06 +04:00
|
|
|
.Pp
|
|
|
|
.It Fn "int prop_set" "propdb_t db" "opaque_t object" "const char *name" \
|
|
|
|
"void *val" "size_t len" "int type" "int wait"
|
2001-10-04 23:39:41 +04:00
|
|
|
Create a property
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa name
|
2001-10-04 23:39:41 +04:00
|
|
|
associated with
|
|
|
|
.Fa object
|
|
|
|
inside database
|
|
|
|
.Fa db ,
|
2001-10-04 22:56:06 +04:00
|
|
|
with a
|
|
|
|
.Fa len
|
2001-10-04 23:39:41 +04:00
|
|
|
byte value copied from location
|
|
|
|
.Fa val .
|
|
|
|
The database must already have been initialized with
|
|
|
|
.Fn propdb_create .
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa object
|
2002-10-14 17:43:14 +04:00
|
|
|
is treated as an opaque value.
|
|
|
|
If
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa len
|
2001-10-04 23:39:41 +04:00
|
|
|
is
|
2001-10-04 22:56:06 +04:00
|
|
|
.Li 0
|
2002-10-14 17:43:14 +04:00
|
|
|
then no data is copied.
|
|
|
|
This can be used to create properties which convey information by
|
|
|
|
their presence or absence.
|
|
|
|
The
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa type
|
2002-10-14 17:43:14 +04:00
|
|
|
field is used to identify what the format of the object is.
|
|
|
|
This value is usually only used to help programs dump property values
|
|
|
|
into human readable formats.
|
|
|
|
However, if
|
2001-10-04 23:39:41 +04:00
|
|
|
.Li PROP_CONST
|
|
|
|
is specified in the
|
|
|
|
.Fa type
|
|
|
|
field, no storage is allocated for the value, and when the property is
|
|
|
|
queried it will copy
|
|
|
|
.Fa len
|
|
|
|
bytes directly from the location specified by
|
|
|
|
.Fa val ,
|
2002-10-14 17:43:14 +04:00
|
|
|
so that data cannot be freed or the kernel may panic.
|
|
|
|
If
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa wait
|
2001-10-04 23:39:41 +04:00
|
|
|
is zero then
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fn prop_set
|
2002-10-14 17:43:14 +04:00
|
|
|
will not sleep for resource shortage.
|
|
|
|
Returns
|
2001-10-04 23:39:41 +04:00
|
|
|
.Li 0
|
2001-10-04 22:56:06 +04:00
|
|
|
on success, or an error value.
|
|
|
|
.Pp
|
|
|
|
.It Fn "size_t prop_get" "propdb_t db" "opaque_t object" "const char *name" \
|
|
|
|
"void *val" "size_t len" "int *type"
|
2001-10-04 23:39:41 +04:00
|
|
|
Retrieve a property called
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa name
|
2001-10-04 23:39:41 +04:00
|
|
|
associated with
|
|
|
|
.Fa object .
|
|
|
|
.Fa name
|
2002-10-14 17:43:14 +04:00
|
|
|
is a pointer to a string.
|
|
|
|
The property that matches both
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa object
|
2001-10-04 23:39:41 +04:00
|
|
|
and
|
|
|
|
.Fa name
|
|
|
|
will be selected, and the data and type information associated with that
|
|
|
|
property will be returned in the buffers pointed to by
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa val
|
2001-10-04 23:39:41 +04:00
|
|
|
and
|
|
|
|
.Fa type
|
2001-10-04 22:56:06 +04:00
|
|
|
as appropriate.
|
|
|
|
.Pp
|
2001-10-04 23:39:41 +04:00
|
|
|
Returns
|
|
|
|
.Li \-1
|
|
|
|
if the property cannot be found, otherwise it returns the length of the
|
|
|
|
value data, and copies up to
|
|
|
|
.Fa len
|
|
|
|
bytes of the property data to the location pointed to by
|
|
|
|
.Fa val .
|
|
|
|
If
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa type
|
2001-10-04 23:39:41 +04:00
|
|
|
is not
|
2001-10-04 22:56:06 +04:00
|
|
|
.Li NULL ,
|
2001-10-04 23:39:41 +04:00
|
|
|
the type information associated with that property is stored in the location
|
2001-10-04 22:56:06 +04:00
|
|
|
it points to.
|
|
|
|
.Pp
|
|
|
|
.It Fn "int prop_delete" "propdb_t db" "opaque_t object" "const char *name"
|
2002-10-14 17:43:14 +04:00
|
|
|
Remove a property from a database.
|
|
|
|
If a
|
2001-10-04 23:39:41 +04:00
|
|
|
.Li NULL
|
|
|
|
is supplied for
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa name ,
|
2001-10-04 23:39:41 +04:00
|
|
|
.Fn prop_delete
|
|
|
|
will remove all properties associated with
|
|
|
|
.Fa object .
|
2001-10-04 22:56:06 +04:00
|
|
|
It returns the number of properties deleted.
|
|
|
|
.Pp
|
|
|
|
.It Fn "int prop_copy" "propdb_t db" "opaque_t source" "opaque_t dest" \
|
|
|
|
"int wait"
|
2001-10-04 23:39:41 +04:00
|
|
|
Copy all properties associated with
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa source
|
2001-10-04 23:39:41 +04:00
|
|
|
to
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa dest
|
2002-10-14 17:43:14 +04:00
|
|
|
structure.
|
|
|
|
If
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa wait
|
2001-10-04 23:39:41 +04:00
|
|
|
is zero then
|
|
|
|
.Fn prop_copy
|
2002-10-14 17:43:14 +04:00
|
|
|
will not sleep for resource shortage.
|
|
|
|
Returns
|
2001-10-04 23:39:41 +04:00
|
|
|
.Li 0
|
2002-10-14 17:43:14 +04:00
|
|
|
on success or an error value.
|
|
|
|
The state of properties is undefined if the operation fails.
|
2001-10-04 22:56:06 +04:00
|
|
|
.It Fn "size_t prop_objs" "propdb_t db" "opaque_t *objects" "size_t len"
|
2002-10-14 17:43:14 +04:00
|
|
|
Get a list of objects identifiers from a database.
|
2003-04-06 19:52:38 +04:00
|
|
|
An array of object identifiers will be copied into the buffer pointed
|
2002-10-14 17:43:14 +04:00
|
|
|
to by
|
2001-10-04 23:39:41 +04:00
|
|
|
.Fa objects
|
|
|
|
up to
|
2001-10-04 22:56:06 +04:00
|
|
|
.Fa len
|
2002-10-14 17:43:14 +04:00
|
|
|
bytes.
|
|
|
|
It returns the amount of memory needed to store the entire list.
|
2001-10-04 22:56:06 +04:00
|
|
|
.Pp
|
|
|
|
.It Fn "size_t prop_list" "propdb_t db" "opaque_t object" "char *names" \
|
|
|
|
"size_t len"
|
2002-10-14 17:43:14 +04:00
|
|
|
Get a list of an object's properties from the database.
|
|
|
|
It queries the database to locate all properties associated with
|
2001-10-04 22:56:06 +04:00
|
|
|
.Pa object
|
2003-04-06 19:52:38 +04:00
|
|
|
object identifier, and copies up to
|
2001-10-04 23:39:41 +04:00
|
|
|
.Pa len
|
|
|
|
bytes of
|
|
|
|
.Li NUL
|
|
|
|
terminated property names into the buffer pointed to by
|
|
|
|
.Pa names .
|
2001-10-04 22:56:06 +04:00
|
|
|
Partial strings are not copied, and another NUL character to indicate the
|
2002-10-14 17:43:14 +04:00
|
|
|
termination of the list.
|
|
|
|
It returns the size needed to hold the entire list.
|
2001-10-04 22:56:06 +04:00
|
|
|
.El
|
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nx
|
|
|
|
property management system first appeared in
|
|
|
|
.Nx 1.6 .
|
2001-10-04 23:39:41 +04:00
|
|
|
.Sh AUTHORS
|
|
|
|
The
|
|
|
|
.Nx
|
|
|
|
property management system was developed by
|
2003-02-14 18:20:17 +03:00
|
|
|
.An Eduardo Horvath
|
|
|
|
.Aq eeh@NetBSD.org .
|