2 * list.h - Linked list implementation. Part of the Linux-NTFS project.
4 * Copyright (c) 2000-2002 Anton Altaparmakov and others
6 * This program/include file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program/include file is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program (in the main directory of the Linux-NTFS
18 * distribution in the file COPYING); if not, write to the Free Software
19 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Simple doubly linked list implementation. - Copied from Linux kernel
27 * 2.4.2-ac18 into Linux-NTFS (with minor modifications). - AIA
29 * Some of the internal functions ("__xxx") are useful when
30 * manipulating whole lists rather than single entries, as
31 * sometimes we already know the next/prev entries and we can
32 * generate better code by using them directly rather than
33 * using the generic single-entry routines.
37 struct list_head *next, *prev;
40 #define LIST_HEAD_INIT(name) { &(name), &(name) }
42 #define LIST_HEAD(name) \
43 struct list_head name = LIST_HEAD_INIT(name)
45 #define INIT_LIST_HEAD(ptr) do { \
46 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
50 * Insert a new entry between two known consecutive entries.
52 * This is only for internal list manipulation where we know the prev/next
55 static __inline__ void __list_add(struct list_head * new,
56 struct list_head * prev, struct list_head * next)
65 * list_add - add a new entry
66 * @new: new entry to be added
67 * @head: list head to add it after
69 * Insert a new entry after the specified head.
70 * This is good for implementing stacks.
72 static __inline__ void list_add(struct list_head *new, struct list_head *head)
74 __list_add(new, head, head->next);
78 * list_add_tail - add a new entry
79 * @new: new entry to be added
80 * @head: list head to add it before
82 * Insert a new entry before the specified head.
83 * This is useful for implementing queues.
85 static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
87 __list_add(new, head->prev, head);
91 * Delete a list entry by making the prev/next entries point to each other.
93 * This is only for internal list manipulation where we know the prev/next
96 static __inline__ void __list_del(struct list_head * prev,
97 struct list_head * next)
104 * list_del - deletes entry from list.
105 * @entry: the element to delete from the list.
107 * Note: list_empty on entry does not return true after this, the entry is in
108 * an undefined state.
110 static __inline__ void list_del(struct list_head *entry)
112 __list_del(entry->prev, entry->next);
116 * list_del_init - deletes entry from list and reinitialize it.
117 * @entry: the element to delete from the list.
119 static __inline__ void list_del_init(struct list_head *entry)
121 __list_del(entry->prev, entry->next);
122 INIT_LIST_HEAD(entry);
126 * list_empty - tests whether a list is empty
127 * @head: the list to test.
129 static __inline__ int list_empty(struct list_head *head)
131 return head->next == head;
135 * list_splice - join two lists
136 * @list: the new list to add.
137 * @head: the place to add it in the first list.
139 static __inline__ void list_splice(struct list_head *list,
140 struct list_head *head)
142 struct list_head *first = list->next;
145 struct list_head *last = list->prev;
146 struct list_head *at = head->next;
157 * list_entry - get the struct for this entry
158 * @ptr: the &struct list_head pointer.
159 * @type: the type of the struct this is embedded in.
160 * @member: the name of the list_struct within the struct.
162 #define list_entry(ptr, type, member) \
163 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
166 * list_for_each - iterate over a list
167 * @pos: the &struct list_head to use as a loop counter.
168 * @head: the head for your list.
170 #define list_for_each(pos, head) \
171 for (pos = (head)->next; pos != (head); pos = pos->next)
174 * list_for_each_safe - iterate over a list safe against removal of list entry
175 * @pos: the &struct list_head to use as a loop counter.
176 * @n: another &struct list_head to use as temporary storage
177 * @head: the head for your list.
179 #define list_for_each_safe(pos, n, head) \
180 for (pos = (head)->next, n = pos->next; pos != (head); \
181 pos = n, n = pos->next)
183 #endif /* defined _NTFS_LIST_H */