diff options
author | Mike Frysinger <vapier@gentoo.org> | 2005-05-09 22:10:42 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2005-05-09 22:10:42 +0000 |
commit | 1fd98e039d146dcff02a5350f509cabca65fd29c (patch) | |
tree | 1564707d41a6271bb44cf3fa5b88b9cc70fedd35 /e2fsprogs/ext2fs/kernel-list.h | |
parent | b32011943a0764872ca1ea17f13b53176ace8e69 (diff) | |
download | busybox-w32-1fd98e039d146dcff02a5350f509cabca65fd29c.tar.gz busybox-w32-1fd98e039d146dcff02a5350f509cabca65fd29c.tar.bz2 busybox-w32-1fd98e039d146dcff02a5350f509cabca65fd29c.zip |
import ext2fs lib to prep for new e2fsprogs
Diffstat (limited to 'e2fsprogs/ext2fs/kernel-list.h')
-rw-r--r-- | e2fsprogs/ext2fs/kernel-list.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/e2fsprogs/ext2fs/kernel-list.h b/e2fsprogs/ext2fs/kernel-list.h new file mode 100644 index 000000000..24e6ab4a1 --- /dev/null +++ b/e2fsprogs/ext2fs/kernel-list.h | |||
@@ -0,0 +1,112 @@ | |||
1 | #ifndef _LINUX_LIST_H | ||
2 | #define _LINUX_LIST_H | ||
3 | |||
4 | /* | ||
5 | * Simple doubly linked list implementation. | ||
6 | * | ||
7 | * Some of the internal functions ("__xxx") are useful when | ||
8 | * manipulating whole lists rather than single entries, as | ||
9 | * sometimes we already know the next/prev entries and we can | ||
10 | * generate better code by using them directly rather than | ||
11 | * using the generic single-entry routines. | ||
12 | */ | ||
13 | |||
14 | struct list_head { | ||
15 | struct list_head *next, *prev; | ||
16 | }; | ||
17 | |||
18 | #define LIST_HEAD_INIT(name) { &(name), &(name) } | ||
19 | |||
20 | #define LIST_HEAD(name) \ | ||
21 | struct list_head name = { &name, &name } | ||
22 | |||
23 | #define INIT_LIST_HEAD(ptr) do { \ | ||
24 | (ptr)->next = (ptr); (ptr)->prev = (ptr); \ | ||
25 | } while (0) | ||
26 | |||
27 | #if (!defined(__GNUC__) && !defined(__WATCOMC__)) | ||
28 | #define __inline__ | ||
29 | #endif | ||
30 | |||
31 | /* | ||
32 | * Insert a new entry between two known consecutive entries. | ||
33 | * | ||
34 | * This is only for internal list manipulation where we know | ||
35 | * the prev/next entries already! | ||
36 | */ | ||
37 | static __inline__ void __list_add(struct list_head * new, | ||
38 | struct list_head * prev, | ||
39 | struct list_head * next) | ||
40 | { | ||
41 | next->prev = new; | ||
42 | new->next = next; | ||
43 | new->prev = prev; | ||
44 | prev->next = new; | ||
45 | } | ||
46 | |||
47 | /* | ||
48 | * Insert a new entry after the specified head.. | ||
49 | */ | ||
50 | static __inline__ void list_add(struct list_head *new, struct list_head *head) | ||
51 | { | ||
52 | __list_add(new, head, head->next); | ||
53 | } | ||
54 | |||
55 | /* | ||
56 | * Insert a new entry at the tail | ||
57 | */ | ||
58 | static __inline__ void list_add_tail(struct list_head *new, struct list_head *head) | ||
59 | { | ||
60 | __list_add(new, head->prev, head); | ||
61 | } | ||
62 | |||
63 | /* | ||
64 | * Delete a list entry by making the prev/next entries | ||
65 | * point to each other. | ||
66 | * | ||
67 | * This is only for internal list manipulation where we know | ||
68 | * the prev/next entries already! | ||
69 | */ | ||
70 | static __inline__ void __list_del(struct list_head * prev, | ||
71 | struct list_head * next) | ||
72 | { | ||
73 | next->prev = prev; | ||
74 | prev->next = next; | ||
75 | } | ||
76 | |||
77 | static __inline__ void list_del(struct list_head *entry) | ||
78 | { | ||
79 | __list_del(entry->prev, entry->next); | ||
80 | } | ||
81 | |||
82 | static __inline__ int list_empty(struct list_head *head) | ||
83 | { | ||
84 | return head->next == head; | ||
85 | } | ||
86 | |||
87 | /* | ||
88 | * Splice in "list" into "head" | ||
89 | */ | ||
90 | static __inline__ void list_splice(struct list_head *list, struct list_head *head) | ||
91 | { | ||
92 | struct list_head *first = list->next; | ||
93 | |||
94 | if (first != list) { | ||
95 | struct list_head *last = list->prev; | ||
96 | struct list_head *at = head->next; | ||
97 | |||
98 | first->prev = head; | ||
99 | head->next = first; | ||
100 | |||
101 | last->next = at; | ||
102 | at->prev = last; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | #define list_entry(ptr, type, member) \ | ||
107 | ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) | ||
108 | |||
109 | #define list_for_each(pos, head) \ | ||
110 | for (pos = (head)->next; pos != (head); pos = pos->next) | ||
111 | |||
112 | #endif | ||