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