ia64/xen-unstable

view tools/blktap2/include/list.h @ 19817:b7f73a7f3078

blktap2: portability fixes for NetBSD

- Use standard off_t and lseek() instead of non-portable off64_t and
lseek64()
- Use uuid API as documented in DCE 1.1 RPC specification
- Add NetBSD implementation for blk_getimagesize() and
blk_getsectorsize()
- Use blk_getimagesize() and blk_getsectorsize()
- Fix uuid header check

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jun 23 17:24:14 2009 +0100 (2009-06-23)
parents 1c627434605e
children
line source
1 /*
2 * list.h
3 *
4 * This is a subset of linux's list.h intended to be used in user-space.
5 * XXX The namespace conflicts with NetBSD's <sys/queue.h>
6 *
7 */
9 #ifndef __LIST_H__
10 #define __LIST_H__
12 #define LIST_POISON1 ((void *) 0x00100100)
13 #define LIST_POISON2 ((void *) 0x00200200)
15 struct list_head {
16 struct list_head *next, *prev;
17 };
19 /* XXX workaround for conflicts. The list API should use its own
20 * namespace prefix, i.e. BLK_
21 */
22 #ifdef LIST_HEAD_INIT
23 #undef LIST_HEAD_INIT
24 #endif
25 #ifndef LIST_HEAD
26 #undef LIST_HEAD
27 #endif
29 #define LIST_HEAD_INIT(name) { &(name), &(name) }
31 #define LIST_HEAD(name) \
32 struct list_head name = LIST_HEAD_INIT(name)
34 static inline void INIT_LIST_HEAD(struct list_head *list)
35 {
36 list->next = list;
37 list->prev = list;
38 }
40 static inline void __list_add(struct list_head *new,
41 struct list_head *prev,
42 struct list_head *next)
43 {
44 next->prev = new;
45 new->next = next;
46 new->prev = prev;
47 prev->next = new;
48 }
50 static inline void list_add(struct list_head *new, struct list_head *head)
51 {
52 __list_add(new, head, head->next);
53 }
55 static inline void list_add_tail(struct list_head *new, struct list_head *head)
56 {
57 __list_add(new, head->prev, head);
58 }
60 static inline void __list_del(struct list_head * prev, struct list_head * next)
61 {
62 next->prev = prev;
63 prev->next = next;
64 }
66 static inline void list_del(struct list_head *entry)
67 {
68 __list_del(entry->prev, entry->next);
69 entry->next = LIST_POISON1;
70 entry->prev = LIST_POISON2;
71 }
73 static inline void list_del_init(struct list_head *entry)
74 {
75 __list_del(entry->prev, entry->next);
76 INIT_LIST_HEAD(entry);
77 }
79 static inline int list_empty(const struct list_head *head)
80 {
81 return head->next == head;
82 }
84 static inline int list_is_last(const struct list_head *list,
85 const struct list_head *head)
86 {
87 return list->next == head;
88 }
90 #define list_entry(ptr, type, member) \
91 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
93 #define list_for_each_entry(pos, head, member) \
94 for (pos = list_entry((head)->next, typeof(*pos), member); \
95 &pos->member != (head); \
96 pos = list_entry(pos->member.next, typeof(*pos), member))
98 #define list_for_each_entry_safe(pos, n, head, member) \
99 for (pos = list_entry((head)->next, typeof(*pos), member), \
100 n = list_entry(pos->member.next, typeof(*pos), member); \
101 &pos->member != (head); \
102 pos = n, n = list_entry(n->member.next, typeof(*n), member))
104 #endif /* __LIST_H__ */