|
|
beb904 |
autofs-5.1.6 - update list.h
|
|
|
beb904 |
|
|
|
beb904 |
From: Ian Kent <raven@themaw.net>
|
|
|
beb904 |
|
|
|
beb904 |
Update autofs include/list.h mostly to include the hlist
|
|
|
beb904 |
implementation but also to simplify bits of it.
|
|
|
beb904 |
|
|
|
beb904 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
beb904 |
---
|
|
|
beb904 |
CHANGELOG | 1
|
|
|
beb904 |
include/list.h | 402 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
|
|
|
beb904 |
2 files changed, 378 insertions(+), 25 deletions(-)
|
|
|
beb904 |
|
|
|
beb904 |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
beb904 |
+++ autofs-5.1.4/CHANGELOG
|
|
|
beb904 |
@@ -116,6 +116,7 @@ xx/xx/2018 autofs-5.1.5
|
|
|
beb904 |
- fix additional typing errors.
|
|
|
beb904 |
- make bind mounts propagation slave by default.
|
|
|
beb904 |
- fix browse dir not re-created on symlink expire.
|
|
|
beb904 |
+- update list.h.
|
|
|
beb904 |
|
|
|
beb904 |
19/12/2017 autofs-5.1.4
|
|
|
beb904 |
- fix spec file url.
|
|
|
beb904 |
--- autofs-5.1.4.orig/include/list.h
|
|
|
beb904 |
+++ autofs-5.1.4/include/list.h
|
|
|
beb904 |
@@ -1,6 +1,27 @@
|
|
|
beb904 |
#ifndef _LINUX_LIST_H
|
|
|
beb904 |
#define _LINUX_LIST_H
|
|
|
beb904 |
|
|
|
beb904 |
+#include <stddef.h>
|
|
|
beb904 |
+
|
|
|
beb904 |
+/*
|
|
|
beb904 |
+ * Casts a member of a structure out to the containing structure
|
|
|
beb904 |
+ * @param ptr the pointer to the member.
|
|
|
beb904 |
+ * @param type the type of the container struct this is embedded in.
|
|
|
beb904 |
+ * @param member the name of the member within the struct.
|
|
|
beb904 |
+ *
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define container_of(ptr, type, member) ({ \
|
|
|
beb904 |
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
|
beb904 |
+ (type *)( (char *)__mptr - offsetof(type,member) );})
|
|
|
beb904 |
+
|
|
|
beb904 |
+/*
|
|
|
beb904 |
+ * These are non-NULL pointers that will result in page faults
|
|
|
beb904 |
+ * under normal circumstances, used to verify that nobody uses
|
|
|
beb904 |
+ * non-initialized list entries.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define LIST_POISON1 ((void *) 0x00100100)
|
|
|
beb904 |
+#define LIST_POISON2 ((void *) 0x00200200)
|
|
|
beb904 |
+
|
|
|
beb904 |
/*
|
|
|
beb904 |
* Simple doubly linked list implementation.
|
|
|
beb904 |
*
|
|
|
beb904 |
@@ -25,14 +46,14 @@ struct list_head {
|
|
|
beb904 |
} while (0)
|
|
|
beb904 |
|
|
|
beb904 |
/*
|
|
|
beb904 |
- * Insert a new entry between two known consecutive entries.
|
|
|
beb904 |
+ * Insert a new entry between two known consecutive entries.
|
|
|
beb904 |
*
|
|
|
beb904 |
* This is only for internal list manipulation where we know
|
|
|
beb904 |
* the prev/next entries already!
|
|
|
beb904 |
*/
|
|
|
beb904 |
-static __inline__ void __list_add(struct list_head * new,
|
|
|
beb904 |
- struct list_head * prev,
|
|
|
beb904 |
- struct list_head * next)
|
|
|
beb904 |
+static inline void __list_add(struct list_head *new,
|
|
|
beb904 |
+ struct list_head *prev,
|
|
|
beb904 |
+ struct list_head *next)
|
|
|
beb904 |
{
|
|
|
beb904 |
next->prev = new;
|
|
|
beb904 |
new->next = next;
|
|
|
beb904 |
@@ -48,7 +69,7 @@ static __inline__ void __list_add(struct
|
|
|
beb904 |
* Insert a new entry after the specified head.
|
|
|
beb904 |
* This is good for implementing stacks.
|
|
|
beb904 |
*/
|
|
|
beb904 |
-static __inline__ void list_add(struct list_head *new, struct list_head *head)
|
|
|
beb904 |
+static inline void list_add(struct list_head *new, struct list_head *head)
|
|
|
beb904 |
{
|
|
|
beb904 |
__list_add(new, head, head->next);
|
|
|
beb904 |
}
|
|
|
beb904 |
@@ -61,7 +82,7 @@ static __inline__ void list_add(struct l
|
|
|
beb904 |
* Insert a new entry before the specified head.
|
|
|
beb904 |
* This is useful for implementing queues.
|
|
|
beb904 |
*/
|
|
|
beb904 |
-static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
|
|
|
beb904 |
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
|
|
beb904 |
{
|
|
|
beb904 |
__list_add(new, head->prev, head);
|
|
|
beb904 |
}
|
|
|
beb904 |
@@ -73,8 +94,7 @@ static __inline__ void list_add_tail(str
|
|
|
beb904 |
* This is only for internal list manipulation where we know
|
|
|
beb904 |
* the prev/next entries already!
|
|
|
beb904 |
*/
|
|
|
beb904 |
-static __inline__ void __list_del(struct list_head * prev,
|
|
|
beb904 |
- struct list_head * next)
|
|
|
beb904 |
+static inline void __list_del(struct list_head * prev, struct list_head * next)
|
|
|
beb904 |
{
|
|
|
beb904 |
next->prev = prev;
|
|
|
beb904 |
prev->next = next;
|
|
|
beb904 |
@@ -83,50 +103,96 @@ static __inline__ void __list_del(struct
|
|
|
beb904 |
/**
|
|
|
beb904 |
* list_del - deletes entry from list.
|
|
|
beb904 |
* @entry: the element to delete from the list.
|
|
|
beb904 |
- * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
|
|
|
beb904 |
+ * Note: list_empty on entry does not return true after this, the entry is
|
|
|
beb904 |
+ * in an undefined state.
|
|
|
beb904 |
*/
|
|
|
beb904 |
-static __inline__ void list_del(struct list_head *entry)
|
|
|
beb904 |
+static inline void list_del(struct list_head *entry)
|
|
|
beb904 |
{
|
|
|
beb904 |
__list_del(entry->prev, entry->next);
|
|
|
beb904 |
+ entry->next = LIST_POISON1;
|
|
|
beb904 |
+ entry->prev = LIST_POISON2;
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
/**
|
|
|
beb904 |
* list_del_init - deletes entry from list and reinitialize it.
|
|
|
beb904 |
* @entry: the element to delete from the list.
|
|
|
beb904 |
*/
|
|
|
beb904 |
-static __inline__ void list_del_init(struct list_head *entry)
|
|
|
beb904 |
+static inline void list_del_init(struct list_head *entry)
|
|
|
beb904 |
{
|
|
|
beb904 |
__list_del(entry->prev, entry->next);
|
|
|
beb904 |
- INIT_LIST_HEAD(entry);
|
|
|
beb904 |
+ INIT_LIST_HEAD(entry);
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+/*
|
|
|
beb904 |
+ * list_move - delete from one list and add as another's head
|
|
|
beb904 |
+ * @list: the entry to move
|
|
|
beb904 |
+ * @head: the head that will precede our entry
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+static inline void list_move(struct list_head *list, struct list_head *head)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ __list_del(list->prev, list->next);
|
|
|
beb904 |
+ list_add(list, head);
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_move_tail - delete from one list and add as another's tail
|
|
|
beb904 |
+ * @list: the entry to move
|
|
|
beb904 |
+ * @head: the head that will follow our entry
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+static inline void list_move_tail(struct list_head *list,
|
|
|
beb904 |
+ struct list_head *head)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ __list_del(list->prev, list->next);
|
|
|
beb904 |
+ list_add_tail(list, head);
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
/**
|
|
|
beb904 |
* list_empty - tests whether a list is empty
|
|
|
beb904 |
* @head: the list to test.
|
|
|
beb904 |
*/
|
|
|
beb904 |
-static __inline__ int list_empty(struct list_head *head)
|
|
|
beb904 |
+static inline int list_empty(const struct list_head *head)
|
|
|
beb904 |
{
|
|
|
beb904 |
return head->next == head;
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
+static inline void __list_splice(struct list_head *list,
|
|
|
beb904 |
+ struct list_head *head)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct list_head *first = list->next;
|
|
|
beb904 |
+ struct list_head *last = list->prev;
|
|
|
beb904 |
+ struct list_head *at = head->next;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ first->prev = head;
|
|
|
beb904 |
+ head->next = first;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ last->next = at;
|
|
|
beb904 |
+ at->prev = last;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
/**
|
|
|
beb904 |
* list_splice - join two lists
|
|
|
beb904 |
* @list: the new list to add.
|
|
|
beb904 |
* @head: the place to add it in the first list.
|
|
|
beb904 |
*/
|
|
|
beb904 |
-static __inline__ void list_splice(struct list_head *list, struct list_head *head)
|
|
|
beb904 |
+static inline void list_splice(struct list_head *list, struct list_head *head)
|
|
|
beb904 |
{
|
|
|
beb904 |
- struct list_head *first = list->next;
|
|
|
beb904 |
-
|
|
|
beb904 |
- if (first != list) {
|
|
|
beb904 |
- struct list_head *last = list->prev;
|
|
|
beb904 |
- struct list_head *at = head->next;
|
|
|
beb904 |
-
|
|
|
beb904 |
- first->prev = head;
|
|
|
beb904 |
- head->next = first;
|
|
|
beb904 |
+ if (!list_empty(list))
|
|
|
beb904 |
+ __list_splice(list, head);
|
|
|
beb904 |
+}
|
|
|
beb904 |
|
|
|
beb904 |
- last->next = at;
|
|
|
beb904 |
- at->prev = last;
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_splice_init - join two lists and reinitialise the emptied list.
|
|
|
beb904 |
+ * @list: the new list to add.
|
|
|
beb904 |
+ * @head: the place to add it in the first list.
|
|
|
beb904 |
+ *
|
|
|
beb904 |
+ * The list at @list is reinitialised
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+static inline void list_splice_init(struct list_head *list,
|
|
|
beb904 |
+ struct list_head *head)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ if (!list_empty(list)) {
|
|
|
beb904 |
+ __list_splice(list, head);
|
|
|
beb904 |
+ INIT_LIST_HEAD(list);
|
|
|
beb904 |
}
|
|
|
beb904 |
}
|
|
|
beb904 |
|
|
|
beb904 |
@@ -137,7 +203,45 @@ static __inline__ void list_splice(struc
|
|
|
beb904 |
* @member: the name of the list_struct within the struct.
|
|
|
beb904 |
*/
|
|
|
beb904 |
#define list_entry(ptr, type, member) \
|
|
|
beb904 |
- ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
|
|
|
beb904 |
+ container_of(ptr, type, member)
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_first_entry - get the first element from a list
|
|
|
beb904 |
+ * @ptr: the list head to take the element from.
|
|
|
beb904 |
+ * @type: the type of the struct this is embedded in.
|
|
|
beb904 |
+ * @member: the name of the list_head within the struct.
|
|
|
beb904 |
+ *
|
|
|
beb904 |
+ * Note, that list is expected to be not empty.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_first_entry(ptr, type, member) \
|
|
|
beb904 |
+ list_entry((ptr)->next, type, member)
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_last_entry - get the last element from a list
|
|
|
beb904 |
+ * @ptr: the list head to take the element from.
|
|
|
beb904 |
+ * @type: the type of the struct this is embedded in.
|
|
|
beb904 |
+ * @member: the name of the list_head within the struct.
|
|
|
beb904 |
+ *
|
|
|
beb904 |
+ * Note, that list is expected to be not empty.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_last_entry(ptr, type, member) \
|
|
|
beb904 |
+ list_entry((ptr)->prev, type, member)
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_next_entry - get the next element in list
|
|
|
beb904 |
+ * @pos: the type * to cursor
|
|
|
beb904 |
+ * @member: the name of the list_head within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_next_entry(pos, member) \
|
|
|
beb904 |
+ list_entry((pos)->member.next, typeof(*(pos)), member)
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_prev_entry - get the prev element in list
|
|
|
beb904 |
+ * @pos: the type * to cursor
|
|
|
beb904 |
+ * @member: the name of the list_head within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_prev_entry(pos, member) \
|
|
|
beb904 |
+ list_entry((pos)->member.prev, typeof(*(pos)), member)
|
|
|
beb904 |
|
|
|
beb904 |
/**
|
|
|
beb904 |
* list_for_each - iterate over a list
|
|
|
beb904 |
@@ -155,4 +259,252 @@ static __inline__ void list_splice(struc
|
|
|
beb904 |
#define list_for_each_prev(pos, head) \
|
|
|
beb904 |
for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
|
|
beb904 |
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_for_each_safe - iterate over a list safe against removal of list entry
|
|
|
beb904 |
+ * @pos: the &struct list_head to use as a loop counter.
|
|
|
beb904 |
+ * @n: another &struct list_head to use as temporary storage
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_for_each_safe(pos, n, head) \
|
|
|
beb904 |
+ for (pos = (head)->next, n = pos->next; pos != (head); \
|
|
|
beb904 |
+ pos = n, n = pos->next)
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_for_each_entry - iterate over list of given type
|
|
|
beb904 |
+ * @pos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ * @member: the name of the list_struct within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_for_each_entry(pos, head, member) \
|
|
|
beb904 |
+ for (pos = list_entry((head)->next, typeof(*pos), member); \
|
|
|
beb904 |
+ &pos->member != (head); \
|
|
|
beb904 |
+ pos = list_next_entry(pos, member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_for_each_entry_reverse - iterate backwards over list of given type.
|
|
|
beb904 |
+ * @pos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ * @member: the name of the list_struct within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_for_each_entry_reverse(pos, head, member) \
|
|
|
beb904 |
+ for (pos = list_last_entry(head, typeof(*pos), member); \
|
|
|
beb904 |
+ &pos->member != (head); \
|
|
|
beb904 |
+ pos = list_prev_entry(pos, member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_prepare_entry - prepare a pos entry for use as a start point in
|
|
|
beb904 |
+ * list_for_each_entry_continue
|
|
|
beb904 |
+ * @pos: the type * to use as a start point
|
|
|
beb904 |
+ * @head: the head of the list
|
|
|
beb904 |
+ * @member: the name of the list_struct within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_prepare_entry(pos, head, member) \
|
|
|
beb904 |
+ ((pos) ? : list_entry(head, typeof(*pos), member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_for_each_entry_continue - iterate over list of given type
|
|
|
beb904 |
+ * continuing after existing point
|
|
|
beb904 |
+ * @pos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ * @member: the name of the list_struct within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_for_each_entry_continue(pos, head, member) \
|
|
|
beb904 |
+ for (pos = list_next_entry(pos, member); \
|
|
|
beb904 |
+ &pos->member != (head); \
|
|
|
beb904 |
+ pos = list_next_entry(pos, member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
|
|
beb904 |
+ * @pos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @n: another type * to use as temporary storage
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ * @member: the name of the list_struct within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_for_each_entry_safe(pos, n, head, member) \
|
|
|
beb904 |
+ for (pos = list_first_entry(head, typeof(*pos), member), \
|
|
|
beb904 |
+ n = list_next_entry(pos, member); \
|
|
|
beb904 |
+ &pos->member != (head); \
|
|
|
beb904 |
+ pos = n, n = list_next_entry(n, member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_for_each_entry_safe_continue - iterate over list of given type
|
|
|
beb904 |
+ * continuing after existing point safe against removal of list entry
|
|
|
beb904 |
+ * @pos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @n: another type * to use as temporary storage
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ * @member: the name of the list_struct within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_for_each_entry_safe_continue(pos, n, head, member) \
|
|
|
beb904 |
+ for (pos = list_next_entry(pos, member), \
|
|
|
beb904 |
+ n = list_next_entry(pos, member); \
|
|
|
beb904 |
+ &pos->member != (head); \
|
|
|
beb904 |
+ pos = n, n = list_next_entry(n, member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
|
|
|
beb904 |
+ * removal of list entry
|
|
|
beb904 |
+ * @pos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @n: another type * to use as temporary storage
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ * @member: the name of the list_struct within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
|
|
|
beb904 |
+ for (pos = list_last_entry(head, typeof(*pos), member), \
|
|
|
beb904 |
+ n = list_prev_entry(pos, member); \
|
|
|
beb904 |
+ &pos->member != (head); \
|
|
|
beb904 |
+ pos = n, n = list_prev_entry(n, member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+
|
|
|
beb904 |
+
|
|
|
beb904 |
+
|
|
|
beb904 |
+/*
|
|
|
beb904 |
+ * Double linked lists with a single pointer list head.
|
|
|
beb904 |
+ * Mostly useful for hash tables where the two pointer list head is
|
|
|
beb904 |
+ * too wasteful.
|
|
|
beb904 |
+ * You lose the ability to access the tail in O(1).
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+
|
|
|
beb904 |
+struct hlist_head {
|
|
|
beb904 |
+ struct hlist_node *first;
|
|
|
beb904 |
+};
|
|
|
beb904 |
+
|
|
|
beb904 |
+struct hlist_node {
|
|
|
beb904 |
+ struct hlist_node *next, **pprev;
|
|
|
beb904 |
+};
|
|
|
beb904 |
+
|
|
|
beb904 |
+#define HLIST_HEAD_INIT { .first = NULL }
|
|
|
beb904 |
+#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
|
|
|
beb904 |
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
|
|
|
beb904 |
+#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
|
|
|
beb904 |
+
|
|
|
beb904 |
+static inline int hlist_unhashed(const struct hlist_node *h)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ return !h->pprev;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static inline int hlist_empty(const struct hlist_head *h)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ return !h->first;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static inline void __hlist_del(struct hlist_node *n)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct hlist_node *next = n->next;
|
|
|
beb904 |
+ struct hlist_node **pprev = n->pprev;
|
|
|
beb904 |
+ *pprev = next;
|
|
|
beb904 |
+ if (next)
|
|
|
beb904 |
+ next->pprev = pprev;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static inline void hlist_del(struct hlist_node *n)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ __hlist_del(n);
|
|
|
beb904 |
+ n->next = LIST_POISON1;
|
|
|
beb904 |
+ n->pprev = LIST_POISON2;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+
|
|
|
beb904 |
+static inline void hlist_del_init(struct hlist_node *n)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ if (n->pprev) {
|
|
|
beb904 |
+ __hlist_del(n);
|
|
|
beb904 |
+ INIT_HLIST_NODE(n);
|
|
|
beb904 |
+ }
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ struct hlist_node *first = h->first;
|
|
|
beb904 |
+ n->next = first;
|
|
|
beb904 |
+ if (first)
|
|
|
beb904 |
+ first->pprev = &n->next;
|
|
|
beb904 |
+ h->first = n;
|
|
|
beb904 |
+ n->pprev = &h->first;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+
|
|
|
beb904 |
+
|
|
|
beb904 |
+/* next must be != NULL */
|
|
|
beb904 |
+static inline void hlist_add_before(struct hlist_node *n,
|
|
|
beb904 |
+ struct hlist_node *next)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ n->pprev = next->pprev;
|
|
|
beb904 |
+ n->next = next;
|
|
|
beb904 |
+ next->pprev = &n->next;
|
|
|
beb904 |
+ *(n->pprev) = n;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+static inline void hlist_add_after(struct hlist_node *n,
|
|
|
beb904 |
+ struct hlist_node *next)
|
|
|
beb904 |
+{
|
|
|
beb904 |
+ next->next = n->next;
|
|
|
beb904 |
+ n->next = next;
|
|
|
beb904 |
+ next->pprev = &n->next;
|
|
|
beb904 |
+
|
|
|
beb904 |
+ if(next->next)
|
|
|
beb904 |
+ next->next->pprev = &next->next;
|
|
|
beb904 |
+}
|
|
|
beb904 |
+
|
|
|
beb904 |
+
|
|
|
beb904 |
+
|
|
|
beb904 |
+#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
|
|
|
beb904 |
+
|
|
|
beb904 |
+#define hlist_for_each(pos, head) \
|
|
|
beb904 |
+ for (pos = (head)->first; pos; pos = pos->next)
|
|
|
beb904 |
+
|
|
|
beb904 |
+#define hlist_for_each_safe(pos, n, head) \
|
|
|
beb904 |
+ for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
|
|
|
beb904 |
+ pos = n)
|
|
|
beb904 |
+
|
|
|
beb904 |
+#define hlist_entry_safe(ptr, type, member) \
|
|
|
beb904 |
+ ({ typeof(ptr) ____ptr = (ptr); \
|
|
|
beb904 |
+ ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
|
|
|
beb904 |
+ })
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * hlist_for_each_entry - iterate over list of given type
|
|
|
beb904 |
+ * @tpos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @pos: the &struct hlist_node to use as a loop counter.
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ * @member: the name of the hlist_node within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define hlist_for_each_entry(pos, head, member) \
|
|
|
beb904 |
+ for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
|
|
|
beb904 |
+ pos; \
|
|
|
beb904 |
+ pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
|
|
|
beb904 |
+ * @tpos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @pos: the &struct hlist_node to use as a loop counter.
|
|
|
beb904 |
+ * @member: the name of the hlist_node within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define hlist_for_each_entry_continue(pos, member) \
|
|
|
beb904 |
+ for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\
|
|
|
beb904 |
+ pos; \
|
|
|
beb904 |
+ pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
|
|
|
beb904 |
+ * @tpos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @pos: the &struct hlist_node to use as a loop counter.
|
|
|
beb904 |
+ * @member: the name of the hlist_node within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define hlist_for_each_entry_from(pos, member) \
|
|
|
beb904 |
+ for (; pos; \
|
|
|
beb904 |
+ pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
|
|
|
beb904 |
+
|
|
|
beb904 |
+/**
|
|
|
beb904 |
+ * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
|
|
beb904 |
+ * @tpos: the type * to use as a loop counter.
|
|
|
beb904 |
+ * @pos: the &struct hlist_node to use as a loop counter.
|
|
|
beb904 |
+ * @n: another &struct hlist_node to use as temporary storage
|
|
|
beb904 |
+ * @head: the head for your list.
|
|
|
beb904 |
+ * @member: the name of the hlist_node within the struct.
|
|
|
beb904 |
+ */
|
|
|
beb904 |
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
|
|
|
beb904 |
+ for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
|
|
|
beb904 |
+ pos && ({ n = pos->next; 1; }) && \
|
|
|
beb904 |
+ pos = hlist_entry_safe(n, typeof(*pos), member))
|
|
|
beb904 |
+
|
|
|
beb904 |
#endif
|