/src/e2fsprogs/lib/ext2fs/kernel-list.h
Line | Count | Source |
1 | | #ifndef _LINUX_LIST_H |
2 | | #define _LINUX_LIST_H |
3 | | |
4 | | #include "compiler.h" |
5 | | |
6 | | /* |
7 | | * Simple doubly linked list implementation. |
8 | | * |
9 | | * Some of the internal functions ("__xxx") are useful when |
10 | | * manipulating whole lists rather than single entries, as |
11 | | * sometimes we already know the next/prev entries and we can |
12 | | * generate better code by using them directly rather than |
13 | | * using the generic single-entry routines. |
14 | | */ |
15 | | |
16 | | struct list_head { |
17 | | struct list_head *next, *prev; |
18 | | }; |
19 | | |
20 | | #define LIST_HEAD_INIT(name) { &(name), &(name) } |
21 | | |
22 | | #define INIT_LIST_HEAD(ptr) do { \ |
23 | | (ptr)->next = (ptr); (ptr)->prev = (ptr); \ |
24 | | } while (0) |
25 | | |
26 | | #if (!defined(__GNUC__) && !defined(__WATCOMC__)) |
27 | | #define __inline__ |
28 | | #endif |
29 | | |
30 | | /* |
31 | | * Insert a new entry between two known consecutive entries. |
32 | | * |
33 | | * This is only for internal list manipulation where we know |
34 | | * the prev/next entries already! |
35 | | */ |
36 | | static __inline__ void __list_add(struct list_head * new, |
37 | | struct list_head * prev, |
38 | | struct list_head * next) |
39 | 0 | { |
40 | 0 | next->prev = new; |
41 | 0 | new->next = next; |
42 | 0 | new->prev = prev; |
43 | 0 | prev->next = new; |
44 | 0 | } |
45 | | |
46 | | /* |
47 | | * Insert a new entry after the specified head.. |
48 | | */ |
49 | | static __inline__ void list_add(struct list_head *new, struct list_head *head) |
50 | 0 | { |
51 | 0 | __list_add(new, head, head->next); |
52 | 0 | } |
53 | | |
54 | | /* |
55 | | * Insert a new entry at the tail |
56 | | */ |
57 | | static __inline__ void list_add_tail(struct list_head *new, struct list_head *head) |
58 | 0 | { |
59 | 0 | __list_add(new, head->prev, head); |
60 | 0 | } |
61 | | |
62 | | /* |
63 | | * Delete a list entry by making the prev/next entries |
64 | | * point to each other. |
65 | | * |
66 | | * This is only for internal list manipulation where we know |
67 | | * the prev/next entries already! |
68 | | */ |
69 | | static __inline__ void __list_del(struct list_head * prev, |
70 | | struct list_head * next) |
71 | 0 | { |
72 | 0 | next->prev = prev; |
73 | 0 | prev->next = next; |
74 | 0 | } |
75 | | |
76 | | static __inline__ void list_del(struct list_head *entry) |
77 | 0 | { |
78 | 0 | __list_del(entry->prev, entry->next); |
79 | 0 | } |
80 | | |
81 | | static __inline__ int list_empty(struct list_head *head) |
82 | 0 | { |
83 | 0 | return head->next == head; |
84 | 0 | } |
85 | | |
86 | | /* |
87 | | * Splice in "list" into "head" |
88 | | */ |
89 | | static __inline__ void list_splice(struct list_head *list, struct list_head *head) |
90 | 0 | { |
91 | 0 | struct list_head *first = list->next; |
92 | 0 |
|
93 | 0 | if (first != list) { |
94 | 0 | struct list_head *last = list->prev; |
95 | 0 | struct list_head *at = head->next; |
96 | 0 |
|
97 | 0 | first->prev = head; |
98 | 0 | head->next = first; |
99 | 0 |
|
100 | 0 | last->next = at; |
101 | 0 | at->prev = last; |
102 | 0 | } |
103 | 0 | } |
104 | | |
105 | | #define list_entry(ptr, type, member) \ |
106 | | container_of(ptr, type, member) |
107 | | |
108 | | #define list_for_each(pos, head) \ |
109 | | for (pos = (head)->next; pos != (head); pos = pos->next) |
110 | | |
111 | | #endif |