]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/compat/linux/v2_0/include/linux/list.h
Initial revision
[karo-tx-redboot.git] / packages / compat / linux / v2_0 / include / linux / list.h
1 /*
2  * JFFS2 -- Journalling Flash File System, Version 2.
3  *
4  * Copyright (C) 2002 Red Hat, Inc.
5  *
6  * Created by Jonathan Larmour <jlarmour@redhat.com>
7  * 
8  *===========================================================================
9  *####ECOSGPLCOPYRIGHTBEGIN####
10  * -------------------------------------------
11  * This file is part of eCos, the Embedded Configurable Operating System.
12  * Copyright (C) 2003 Red Hat.
13  *
14  * eCos is free software; you can redistribute it and/or modify it under
15  * the terms of the GNU General Public License as published by the Free
16  * Software Foundation; either version 2 or (at your option) any later version.
17  *
18  * eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with eCos; if not, write to the Free Software Foundation, Inc.,
25  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26  *
27  * As a special exception, if other files instantiate templates or use macros
28  * or inline functions from this file, or you compile this file and link it
29  * with other works to produce a work based on this file, this file does not
30  * by itself cause the resulting work to be covered by the GNU General Public
31  * License. However the source code for this file must still be made available
32  * in accordance with section (3) of the GNU General Public License.
33  *
34  * This exception does not invalidate any other reasons why a work based on
35  * this file might be covered by the GNU General Public License.
36  *
37  * Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38  * at http://sources.redhat.com/ecos/ecos-license/
39  * -------------------------------------------
40  *####ECOSGPLCOPYRIGHTEND####
41  *===========================================================================
42  *
43  */
44
45 #ifndef CYGONCE_FS_JFFS2_LIST_H
46 #define CYGONCE_FS_JFFS2_LIST_H
47
48
49 /* -----------------------------------------------------------------------*/
50
51 /* Doubly linked list implementation to replace the GPL'd one used in
52    the Linux kernel. */
53
54 #include <stddef.h>
55 #include <cyg/infra/cyg_type.h>
56
57 /* TYPES */
58
59 struct list_head {
60     struct list_head *next;
61     struct list_head *prev;
62 };
63
64 /* MACROS */
65
66 #define LIST_HEAD_INIT(name) { &(name), &(name) }
67
68 #define LIST_HEAD(name) \
69         struct list_head name = LIST_HEAD_INIT(name)
70
71 #define INIT_LIST_HEAD( _list_ )              \
72 CYG_MACRO_START                               \
73 (_list_)->next = (_list_)->prev = (_list_);   \
74 CYG_MACRO_END
75
76 /* FUNCTIONS */
77
78 /* Insert an entry _after_ the specified entry */
79 static __inline__ void
80 list_add( struct list_head *newent, struct list_head *afterthisent )
81 {
82     struct list_head *next = afterthisent->next;
83     newent->next = next;
84     newent->prev = afterthisent;
85     afterthisent->next = newent;
86     next->prev = newent;
87 } /* list_add() */
88
89 /* Insert an entry _before_ the specified entry */
90 static __inline__ void
91 list_add_tail( struct list_head *newent, struct list_head *beforethisent )
92 {
93     struct list_head *prev = beforethisent->prev;
94     newent->prev = prev;
95     newent->next = beforethisent;
96     beforethisent->prev = newent;
97     prev->next = newent;
98 } /* list_add_tail() */
99
100 /* Delete the specified entry */
101 static __inline__ void
102 list_del( struct list_head *ent )
103 {
104     ent->prev->next = ent->next;
105     ent->next->prev = ent->prev;
106 } /* list_del() */
107
108 /* Is this list empty? */
109 static __inline__ int
110 list_empty( struct list_head *list )
111 {
112     return ( list->next == list );
113 } /* list_empty() */
114
115 /* list_entry - Assuming you have a struct of type _type_ that contains a
116    list which has the name _member_ in that struct type, then given the
117    address of that list in the struct, _list_, this returns the address
118    of the container structure */
119
120 #define list_entry( _list_, _type_, _member_ ) \
121     ((_type_ *)((char *)(_list_)-(char *)(offsetof(_type_,_member_))))
122
123 /* list_for_each - using _ent_, iterate through list _list_ */
124
125 #define list_for_each( _ent_, _list_ )   \
126     for ( (_ent_) = (_list_)->next;      \
127     (_ent_) != (_list_);                 \
128     (_ent_) = (_ent_)->next )
129
130 /*
131  * list_for_each_entry - this function can be use to iterate over all
132  * items in a list* _list_ with it's head at _head_ and link _item_
133  */
134 #define list_for_each_entry(_list_, _head_, _item_)                     \
135 for ((_list_) = list_entry((_head_)->next, typeof(*_list_), _item_); \
136      &((_list_)->_item_) != (_head_);                                 \
137      (_list_) = list_entry((_list_)->_item_.next, typeof(*_list_), _item_))
138
139 /* -----------------------------------------------------------------------*/
140 #endif /* #ifndef CYGONCE_FS_JFFS2_LIST_H */
141 /* EOF list.h */