2005-04-20 19:11:05 +00:00
|
|
|
.\" Copyright (c) 2005 Gleb Smirnoff <glebius@FreeBSD.org>
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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$
|
|
|
|
.\"
|
2017-10-11 21:53:50 +00:00
|
|
|
.Dd October 4, 2017
|
2011-04-27 01:10:15 +00:00
|
|
|
.Dt UNR 9
|
2005-04-20 19:11:05 +00:00
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm new_unrhdr ,
|
2017-10-11 21:53:50 +00:00
|
|
|
.Nm clear_unrhdr ,
|
2005-04-20 19:11:05 +00:00
|
|
|
.Nm delete_unrhdr ,
|
|
|
|
.Nm alloc_unr ,
|
2010-07-05 16:23:55 +00:00
|
|
|
.Nm alloc_unr_specific ,
|
2005-04-20 19:11:05 +00:00
|
|
|
.Nm free_unr
|
|
|
|
.Nd "kernel unit number allocator"
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In sys/systm.h
|
|
|
|
.Ft "struct unrhdr *"
|
|
|
|
.Fn new_unrhdr "int low" "int high" "struct mtx *mutex"
|
|
|
|
.Ft void
|
2017-10-11 21:53:50 +00:00
|
|
|
.Fn clear_unrhdr "struct unrhdr *uh"
|
|
|
|
.Ft void
|
2005-04-20 19:11:05 +00:00
|
|
|
.Fn delete_unrhdr "struct unrhdr *uh"
|
|
|
|
.Ft int
|
|
|
|
.Fn alloc_unr "struct unrhdr *uh"
|
|
|
|
.Ft int
|
|
|
|
.Fn alloc_unrl "struct unrhdr *uh"
|
2010-07-05 16:23:55 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn alloc_unr_specific "struct unrhdr *uh" "u_int item"
|
2005-04-20 19:11:05 +00:00
|
|
|
.Ft void
|
|
|
|
.Fn free_unr "struct unrhdr *uh" "u_int item"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The kernel unit number allocator is a generic facility, which allows to allocate
|
|
|
|
unit numbers within a specified range.
|
2005-06-16 18:46:17 +00:00
|
|
|
.Bl -tag -width indent
|
2005-04-20 19:11:05 +00:00
|
|
|
.It Fn new_unrhdr low high mutex
|
|
|
|
Initialize a new unit number allocator entity.
|
2005-06-16 18:46:17 +00:00
|
|
|
The
|
2005-04-20 19:11:05 +00:00
|
|
|
.Fa low
|
|
|
|
and
|
|
|
|
.Fa high
|
2005-06-16 18:46:17 +00:00
|
|
|
arguments
|
2005-04-20 19:11:05 +00:00
|
|
|
specify minimum and maximum number of unit numbers.
|
|
|
|
There is no cost associated with the range of unit numbers, so unless the resource
|
|
|
|
really is finite,
|
2005-06-16 18:46:17 +00:00
|
|
|
.Dv INT_MAX
|
2005-04-20 19:11:05 +00:00
|
|
|
can be used.
|
|
|
|
If
|
|
|
|
.Fa mutex
|
|
|
|
is not
|
2005-06-16 18:46:17 +00:00
|
|
|
.Dv NULL ,
|
2005-04-20 19:11:05 +00:00
|
|
|
it is used for locking when allocating and freeing units.
|
2005-06-16 18:46:17 +00:00
|
|
|
Otherwise, internal mutex is used.
|
2017-10-11 21:53:50 +00:00
|
|
|
.It Fn clear_unrhdr uh
|
|
|
|
Clear all units from the specified unit number allocator entity.
|
|
|
|
This function resets the entity as if it were just initialized with
|
|
|
|
.Fn new_unrhdr .
|
2005-04-20 19:11:05 +00:00
|
|
|
.It Fn delete_unrhdr uh
|
2017-10-11 21:53:50 +00:00
|
|
|
Delete specified unit number allocator entity.
|
|
|
|
This function frees the memory associated with the entity, it does not free
|
|
|
|
any units.
|
|
|
|
To free all units use
|
|
|
|
.Fn clear_unrhdr .
|
2005-04-20 19:11:05 +00:00
|
|
|
.It Fn alloc_unr uh
|
|
|
|
Return a new unit number.
|
|
|
|
The lowest free number is always allocated.
|
|
|
|
This function does not allocate memory and never sleeps, however it may
|
2005-06-16 18:46:17 +00:00
|
|
|
block on a mutex.
|
|
|
|
If no free unit numbers are left,
|
|
|
|
.Li \-1
|
2005-04-20 19:11:05 +00:00
|
|
|
is returned.
|
|
|
|
.It Fn alloc_unrl uh
|
|
|
|
Same as
|
|
|
|
.Fn alloc_unr
|
2005-06-16 18:46:17 +00:00
|
|
|
except that mutex is assumed to be already locked and thus is not used.
|
2010-07-05 16:23:55 +00:00
|
|
|
.It Fn alloc_unr_specific uh item
|
|
|
|
Allocate a specific unit number.
|
|
|
|
This function allocates memory and thus may sleep.
|
|
|
|
The allocated unit number is returned on success.
|
|
|
|
If the specified number is already allocated or out of the range,
|
|
|
|
.Li \-1
|
|
|
|
is returned.
|
2010-02-07 20:36:23 +00:00
|
|
|
.It Fn free_unr uh item
|
2005-04-20 19:11:05 +00:00
|
|
|
Free a previously allocated unit number.
|
|
|
|
This function may require allocating memory, and thus it can sleep.
|
|
|
|
There is no pre-locked variant.
|
|
|
|
.El
|
|
|
|
.Sh CODE REFERENCES
|
|
|
|
The above functions are implemented in
|
|
|
|
.Pa sys/kern/subr_unit.c .
|
|
|
|
.Sh HISTORY
|
|
|
|
Kernel unit number allocator first appeared in
|
2005-11-24 09:25:10 +00:00
|
|
|
.Fx 6.0 .
|
2005-04-20 19:11:05 +00:00
|
|
|
.Sh AUTHORS
|
|
|
|
.An -nosplit
|
|
|
|
Kernel unit number allocator was written by
|
|
|
|
.An Poul-Henning Kamp .
|
|
|
|
This manpage was written by
|
|
|
|
.An Gleb Smirnoff .
|