xref: /dflybsd-src/share/man/man9/idr.9 (revision e404160590a0a01eabc429da7b328c5f14611151)
1de78443eSSascha Wildner.\"
2181ede86SVishesh Yadav.\" Copyright (c) 2012 Vishesh Yadav
3181ede86SVishesh Yadav.\" All rights reserved.
4181ede86SVishesh Yadav.\"
5181ede86SVishesh Yadav.\" Redistribution and use in source and binary forms, with or without
6181ede86SVishesh Yadav.\" modification, are permitted provided that the following conditions
7181ede86SVishesh Yadav.\" are met:
8181ede86SVishesh Yadav.\" 1. Redistributions of source code must retain the above copyright
9181ede86SVishesh Yadav.\"    notice, this list of conditions and the following disclaimer.
10181ede86SVishesh Yadav.\" 2. Redistributions in binary form must reproduce the above copyright
11181ede86SVishesh Yadav.\"    notice, this list of conditions and the following disclaimer in the
12181ede86SVishesh Yadav.\"    documentation and/or other materials provided with the distribution.
13181ede86SVishesh Yadav.\" 3. The name of the author may not be used to endorse or promote products
14181ede86SVishesh Yadav.\"    derived from this software without specific prior written permission.
15181ede86SVishesh Yadav.\"
16181ede86SVishesh Yadav.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17181ede86SVishesh Yadav.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18181ede86SVishesh Yadav.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19181ede86SVishesh Yadav.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20181ede86SVishesh Yadav.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21181ede86SVishesh Yadav.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22181ede86SVishesh Yadav.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23181ede86SVishesh Yadav.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24181ede86SVishesh Yadav.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25181ede86SVishesh Yadav.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26181ede86SVishesh Yadav.\"
27*e4041605SSascha Wildner.Dd March 16, 2019
28181ede86SVishesh Yadav.Dt IDR 9
29181ede86SVishesh Yadav.Os
30181ede86SVishesh Yadav.Sh NAME
31181ede86SVishesh Yadav.Nm idr ,
32181ede86SVishesh Yadav.Nm idr_destroy ,
33181ede86SVishesh Yadav.Nm idr_find ,
34181ede86SVishesh Yadav.Nm idr_for_each ,
35181ede86SVishesh Yadav.Nm idr_get_new ,
36181ede86SVishesh Yadav.Nm idr_get_new_above ,
37181ede86SVishesh Yadav.Nm idr_init ,
38181ede86SVishesh Yadav.Nm idr_pre_get ,
39181ede86SVishesh Yadav.Nm idr_remove ,
40181ede86SVishesh Yadav.Nm idr_remove_all ,
41181ede86SVishesh Yadav.Nm idr_replace
42f5f75637SSascha Wildner.Nd integer ID management library
43181ede86SVishesh Yadav.Sh SYNOPSIS
44181ede86SVishesh Yadav.In sys/idr.h
45181ede86SVishesh Yadav.Ft void
46181ede86SVishesh Yadav.Fn idr_destroy "struct idr *idp"
47181ede86SVishesh Yadav.Ft void *
48181ede86SVishesh Yadav.Fn idr_find "struct idr *idp" "int id"
49181ede86SVishesh Yadav.Ft int
50181ede86SVishesh Yadav.Fn idr_for_each "struct idr *idp" "int (*fn)(int id, void *p, void *data)" "void *data"
51181ede86SVishesh Yadav.Ft int
52181ede86SVishesh Yadav.Fn idr_get_new "struct idr *idp" "void *ptr" "int *id"
53181ede86SVishesh Yadav.Ft int
54181ede86SVishesh Yadav.Fn idr_get_new_above "struct idr *idp" "void *ptr" "int sid" "int *id"
55181ede86SVishesh Yadav.Ft void
56181ede86SVishesh Yadav.Fn idr_init "struct idr *idp"
57181ede86SVishesh Yadav.Ft int
58c824b4f9SFrançois Tigeot.Fn idr_pre_get "struct idr *idp" "unsigned gfp_mask"
59*e4041605SSascha Wildner.Ft void *
60181ede86SVishesh Yadav.Fn idr_remove "struct idr *idp" "int id"
61181ede86SVishesh Yadav.Ft void
62181ede86SVishesh Yadav.Fn idr_remove_all "struct idr *idp"
63181ede86SVishesh Yadav.Ft void *
64181ede86SVishesh Yadav.Fn idr_replace "struct idr *idp" "void *ptr" "int id"
65181ede86SVishesh Yadav.Sh DESCRIPTION
66f5f75637SSascha WildnerThe
67de78443eSSascha Wildner.Fn idr_init
68de78443eSSascha Wildnerfunction initialize an
69de78443eSSascha Wildner.Nm
70de78443eSSascha Wildnerhandle that will be used by other functions of this API.
71de78443eSSascha Wildner.Pp
72de78443eSSascha WildnerThe
73f5f75637SSascha Wildner.Fn idr_destroy
74f5f75637SSascha Wildnerfunction frees all resources taken by the specified
75f5f75637SSascha Wildner.Nm
76f5f75637SSascha Wildnerhandle
77f5f75637SSascha Wildner.Fa idp .
78181ede86SVishesh Yadav.Pp
79f5f75637SSascha WildnerThe
80f5f75637SSascha Wildner.Fn idr_find
81f5f75637SSascha Wildnerfunction returns the data pointer that is mapped with the specified
82f5f75637SSascha Wildner.Fa id .
83181ede86SVishesh Yadav.Pp
84f5f75637SSascha WildnerThe
85f5f75637SSascha Wildner.Fn idr_for_each
86f5f75637SSascha Wildnerfunction iterates through all pointers registered with the specified
87f5f75637SSascha Wildner.Nm
88f5f75637SSascha Wildnerhandle
89f5f75637SSascha Wildner.Fa idp
90f5f75637SSascha Wildnerand calls the callback function
91f5f75637SSascha Wildner.Fn fn
92f5f75637SSascha Wildnerfor each pointer.
93f5f75637SSascha WildnerIt is not safe to modify the
94f5f75637SSascha Wildner.Nm
95f5f75637SSascha Wildnertree through the callback function.
96f5f75637SSascha WildnerIf the callback function returns a non-zero integer, it stops and returns the
97181ede86SVishesh Yadavvalue.
98181ede86SVishesh Yadav.Pp
99f5f75637SSascha WildnerThe
100f5f75637SSascha Wildner.Fn idr_get_new
101f5f75637SSascha Wildnerand
102f5f75637SSascha Wildner.Fn idr_get_new_above
103f5f75637SSascha Wildnerfunctions allocate a new integer mapped with the specified pointer
104f5f75637SSascha Wildner.Fa ptr .
105f5f75637SSascha WildnerThe new ID will be stored in
106f5f75637SSascha Wildner.Fa id .
10704876a76SFrançois TigeotIf the tree becomes full, these functions will return
108de78443eSSascha Wildner.Fl Ns Er EAGAIN .
109f5f75637SSascha WildnerIn this case,
110181ede86SVishesh Yadav.Fn idr_pre_get
111181ede86SVishesh Yadavshould be called to grow the tree.
112181ede86SVishesh Yadav.Pp
113f5f75637SSascha WildnerThe
114f5f75637SSascha Wildner.Fn idr_pre_get
115de78443eSSascha Wildnerfunction should be called prior to calling
116de78443eSSascha Wildner.Fn idr_get_new
117de78443eSSascha Wildnerand
118de78443eSSascha Wildner.Fn idr_get_new_above
119de78443eSSascha Wildnerand preallocates enough memory for subsequent calls to these functions.
120de78443eSSascha WildnerIt should be called without any locks held and returns 1 if enough memory
121de78443eSSascha Wildnerwas successfully allocated, otherwise 0.
122c824b4f9SFrançois TigeotThe
123de78443eSSascha Wildner.Fa gfp_mask
124de78443eSSascha Wildneris only present for compatibility with the Linux implementation of
125c824b4f9SFrançois Tigeotthis API and is unused on
126c824b4f9SFrançois Tigeot.Dx .
127181ede86SVishesh Yadav.Pp
128f5f75637SSascha WildnerThe
129f5f75637SSascha Wildner.Fn idr_remove
130f5f75637SSascha Wildnerfunction removes the specified
131f5f75637SSascha Wildner.Fa id
132d0975e24SMatthew Dillonfrom the tree, returning its pointer.
133d0975e24SMatthew DillonNULL is returned if the id could not be found.
134181ede86SVishesh Yadav.Pp
135f5f75637SSascha WildnerThe
136f5f75637SSascha Wildner.Fn idr_remove_all
137f5f75637SSascha Wildnerfunction removes all entries in the
138f5f75637SSascha Wildner.Nm
139f5f75637SSascha Wildnertree
140f5f75637SSascha Wildner.Fa idp .
141181ede86SVishesh Yadav.Pp
142f5f75637SSascha WildnerThe
143f5f75637SSascha Wildner.Fn idr_replace
144f5f75637SSascha Wildnerfunction replaces the pointer for the specified
145f5f75637SSascha Wildner.Fa id
146f5f75637SSascha Wildnerwith the new pointer
147f5f75637SSascha Wildner.Fa ptr .
148f5f75637SSascha WildnerIt returns
149f5f75637SSascha Wildner.Dv NULL
150d0975e24SMatthew Dillonif the id is not found.
151d0975e24SMatthew DillonThis behavior is different from the Linux API, which returns ERR_PTR(-ENOENT)
152d0975e24SMatthew Dillonif the id could not be found.
153