2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef _LINUX_LIST_H_
29 #define _LINUX_LIST_H_
32 * Since LIST_HEAD conflicts with the linux definition we must include any
33 * FreeBSD header which requires it here so it is resolved with the correct
34 * definition prior to the undef.
36 #include <linux/types.h>
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/queue.h>
41 #include <sys/cpuset.h>
43 #include <sys/mutex.h>
45 #include <sys/vnode.h>
47 #include <sys/socket.h>
52 #include <net/if_types.h>
53 #include <net/if_media.h>
55 #include <netinet/in.h>
56 #include <netinet/in_pcb.h>
58 #include <netinet6/in6_var.h>
59 #include <netinet6/nd6.h>
62 #include <vm/vm_object.h>
67 struct list_head *next;
68 struct list_head *prev;
72 INIT_LIST_HEAD(struct list_head *list)
75 list->next = list->prev = list;
79 list_empty(const struct list_head *head)
82 return (head->next == head);
86 list_del(struct list_head *entry)
89 entry->next->prev = entry->prev;
90 entry->prev->next = entry->next;
94 _list_add(struct list_head *new, struct list_head *prev,
95 struct list_head *next)
105 list_del_init(struct list_head *entry)
109 INIT_LIST_HEAD(entry);
112 #define list_entry(ptr, type, field) container_of(ptr, type, field)
114 #define list_for_each(p, head) \
115 for (p = (head)->next; p != (head); p = p->next)
117 #define list_for_each_safe(p, n, head) \
118 for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next)
120 #define list_for_each_entry(p, h, field) \
121 for (p = list_entry((h)->next, typeof(*p), field); &p->field != (h); \
122 p = list_entry(p->field.next, typeof(*p), field))
124 #define list_for_each_entry_safe(p, n, h, field) \
125 for (p = list_entry((h)->next, typeof(*p), field), \
126 n = list_entry(p->field.next, typeof(*p), field); &p->field != (h);\
127 p = n, n = list_entry(n->field.next, typeof(*n), field))
129 #define list_for_each_entry_reverse(p, h, field) \
130 for (p = list_entry((h)->prev, typeof(*p), field); &p->field != (h); \
131 p = list_entry(p->field.prev, typeof(*p), field))
133 #define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = p->prev)
136 list_add(struct list_head *new, struct list_head *head)
139 _list_add(new, head, head->next);
143 list_add_tail(struct list_head *new, struct list_head *head)
146 _list_add(new, head->prev, head);
150 list_move(struct list_head *list, struct list_head *head)
154 list_add(list, head);
158 list_move_tail(struct list_head *entry, struct list_head *head)
162 list_add_tail(entry, head);
166 _list_splice(const struct list_head *list, struct list_head *prev,
167 struct list_head *next)
169 struct list_head *first;
170 struct list_head *last;
172 if (list_empty(list))
183 list_splice(const struct list_head *list, struct list_head *head)
186 _list_splice(list, head, head->next);
190 list_splice_tail(struct list_head *list, struct list_head *head)
193 _list_splice(list, head->prev, head);
197 list_splice_init(struct list_head *list, struct list_head *head)
200 _list_splice(list, head, head->next);
201 INIT_LIST_HEAD(list);
205 list_splice_tail_init(struct list_head *list, struct list_head *head)
208 _list_splice(list, head->prev, head);
209 INIT_LIST_HEAD(list);
213 #define LIST_HEAD(name) struct list_head name = { &(name), &(name) }
217 struct hlist_node *first;
221 struct hlist_node *next, **pprev;
224 #define HLIST_HEAD_INIT { }
225 #define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
226 #define INIT_HLIST_HEAD(head) (head)->first = NULL
227 #define INIT_HLIST_NODE(node) \
229 (node)->next = NULL; \
230 (node)->pprev = NULL; \
234 hlist_unhashed(const struct hlist_node *h)
241 hlist_empty(const struct hlist_head *h)
248 hlist_del(struct hlist_node *n)
252 n->next->pprev = n->pprev;
257 hlist_del_init(struct hlist_node *n)
260 if (hlist_unhashed(n))
267 hlist_add_head(struct hlist_node *n, struct hlist_head *h)
272 h->first->pprev = &n->next;
274 n->pprev = &h->first;
278 hlist_add_before(struct hlist_node *n, struct hlist_node *next)
281 n->pprev = next->pprev;
283 next->pprev = &n->next;
288 hlist_add_after(struct hlist_node *n, struct hlist_node *next)
291 next->next = n->next;
293 next->pprev = &n->next;
295 next->next->pprev = &next->next;
299 hlist_move_list(struct hlist_head *old, struct hlist_head *new)
302 new->first = old->first;
304 new->first->pprev = &new->first;
308 #define hlist_entry(ptr, type, field) container_of(ptr, type, field)
310 #define hlist_for_each(p, head) \
311 for (p = (head)->first; p; p = p->next)
313 #define hlist_for_each_safe(p, n, head) \
314 for (p = (head)->first; p && ({ n = p->next; 1; }); p = n)
316 #define hlist_for_each_entry(tp, p, head, field) \
317 for (p = (head)->first; \
318 p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
320 #define hlist_for_each_entry_continue(tp, p, field) \
321 for (p = (p)->next; \
322 p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
324 #define hlist_for_each_entry_from(tp, p, field) \
325 for (; p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
327 #define hlist_for_each_entry_safe(tp, p, n, head, field) \
328 for (p = (head)->first; p ? \
329 (n = p->next) | (tp = hlist_entry(p, typeof(*tp), field)) : \
332 #endif /* _LINUX_LIST_H_ */