UNR(9)

NAME
new_unrhdr, delete_unrhdr, alloc_unr, alloc_unr1, free_unr - kernel unit number allocator

SYNOPSIS
#include <sys/systm.h>
int
alloc_unr(struct unrhdr *uh);
int
alloc_unrl(struct unrhdr *uh);
void
delete_unrhdr(struct unrhdr *uh);
void
free_unr(struct unrhdr *uh, u_int item);
struct unrhdr *
new_unrhdr(int low, int high, struct lock *lock);

DESCRIPTION
The kernel unit number allocator is a generic facility, which allows to allocate unit numbers within a specified range.

new_unrhdr(low, high, lock)
    Initialize a new unit number allocator entity. The low and high arguments 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, INT_MAX can be used. If lock is not NULL, it is used for locking when allocating and freeing units.

delete_unrhdr(uh)
    Delete specified unit number allocator entity. This function frees the memory associated with the entity, it does not free any units.

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 block on a lock. If no free unit numbers are left, -1 is returned.

alloc_unrl(uh)
    Same as alloc_unr() except that lock is assumed to be already locked and thus is not used.

free_unr(uh, item)
    Free a previously allocated unit number. This function may require allocating memory, and thus it can sleep. There is no pre-locked variant.

FILES
The above functions are implemented in sys/kern/subr_unit.c.

SEE ALSO
idr(9)

HISTORY
Kernel unit number allocator first appeared in FreeBSD 6.0, and was imported into DragonFly 3.5.

AUTHORS
-nosplit Kernel unit number allocator was written by Poul-Henning Kamp. This manpage was written by Gleb Smirnoff.