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_first_entry(ptr, type, member) \
115 list_entry((ptr)->next, type, member)
117 #define list_for_each(p, head) \
118 for (p = (head)->next; p != (head); p = p->next)
120 #define list_for_each_safe(p, n, head) \
121 for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next)
123 #define list_for_each_entry(p, h, field) \
124 for (p = list_entry((h)->next, typeof(*p), field); &p->field != (h); \
125 p = list_entry(p->field.next, typeof(*p), field))
127 #define list_for_each_entry_safe(p, n, h, field) \
128 for (p = list_entry((h)->next, typeof(*p), field), \
129 n = list_entry(p->field.next, typeof(*p), field); &p->field != (h);\
130 p = n, n = list_entry(n->field.next, typeof(*n), field))
132 #define list_for_each_entry_reverse(p, h, field) \
133 for (p = list_entry((h)->prev, typeof(*p), field); &p->field != (h); \
134 p = list_entry(p->field.prev, typeof(*p), field))
136 #define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = p->prev)
139 list_add(struct list_head *new, struct list_head *head)
142 _list_add(new, head, head->next);
146 list_add_tail(struct list_head *new, struct list_head *head)
149 _list_add(new, head->prev, head);
153 list_move(struct list_head *list, struct list_head *head)
157 list_add(list, head);
161 list_move_tail(struct list_head *entry, struct list_head *head)
165 list_add_tail(entry, head);
169 _list_splice(const struct list_head *list, struct list_head *prev,
170 struct list_head *next)
172 struct list_head *first;
173 struct list_head *last;
175 if (list_empty(list))
186 list_splice(const struct list_head *list, struct list_head *head)
189 _list_splice(list, head, head->next);
193 list_splice_tail(struct list_head *list, struct list_head *head)
196 _list_splice(list, head->prev, head);
200 list_splice_init(struct list_head *list, struct list_head *head)
203 _list_splice(list, head, head->next);
204 INIT_LIST_HEAD(list);
208 list_splice_tail_init(struct list_head *list, struct list_head *head)
211 _list_splice(list, head->prev, head);
212 INIT_LIST_HEAD(list);
216 #define LIST_HEAD(name) struct list_head name = { &(name), &(name) }
220 struct hlist_node *first;
224 struct hlist_node *next, **pprev;
227 #define HLIST_HEAD_INIT { }
228 #define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
229 #define INIT_HLIST_HEAD(head) (head)->first = NULL
230 #define INIT_HLIST_NODE(node) \
232 (node)->next = NULL; \
233 (node)->pprev = NULL; \
237 hlist_unhashed(const struct hlist_node *h)
244 hlist_empty(const struct hlist_head *h)
251 hlist_del(struct hlist_node *n)
255 n->next->pprev = n->pprev;
260 hlist_del_init(struct hlist_node *n)
263 if (hlist_unhashed(n))
270 hlist_add_head(struct hlist_node *n, struct hlist_head *h)
275 h->first->pprev = &n->next;
277 n->pprev = &h->first;
281 hlist_add_before(struct hlist_node *n, struct hlist_node *next)
284 n->pprev = next->pprev;
286 next->pprev = &n->next;
291 hlist_add_after(struct hlist_node *n, struct hlist_node *next)
294 next->next = n->next;
296 next->pprev = &n->next;
298 next->next->pprev = &next->next;
302 hlist_move_list(struct hlist_head *old, struct hlist_head *new)
305 new->first = old->first;
307 new->first->pprev = &new->first;
311 #define hlist_entry(ptr, type, field) container_of(ptr, type, field)
313 #define hlist_for_each(p, head) \
314 for (p = (head)->first; p; p = p->next)
316 #define hlist_for_each_safe(p, n, head) \
317 for (p = (head)->first; p && ({ n = p->next; 1; }); p = n)
319 #define hlist_for_each_entry(tp, p, head, field) \
320 for (p = (head)->first; \
321 p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
323 #define hlist_for_each_entry_continue(tp, p, field) \
324 for (p = (p)->next; \
325 p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
327 #define hlist_for_each_entry_from(tp, p, field) \
328 for (; p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
330 #define hlist_for_each_entry_safe(tp, p, n, head, field) \
331 for (p = (head)->first; p ? \
332 (n = p->next) | (tp = hlist_entry(p, typeof(*tp), field)) : \
335 #endif /* _LINUX_LIST_H_ */