2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2002 Red Hat, Inc.
6 * Created by Jonathan Larmour <jlarmour@redhat.com>
8 *===========================================================================
9 *####ECOSGPLCOPYRIGHTBEGIN####
10 * -------------------------------------------
11 * This file is part of eCos, the Embedded Configurable Operating System.
12 * Copyright (C) 2003 Red Hat.
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.
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
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.
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.
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.
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 *===========================================================================
45 #ifndef CYGONCE_FS_JFFS2_LIST_H
46 #define CYGONCE_FS_JFFS2_LIST_H
49 /* -----------------------------------------------------------------------*/
51 /* Doubly linked list implementation to replace the GPL'd one used in
55 #include <cyg/infra/cyg_type.h>
60 struct list_head *next;
61 struct list_head *prev;
66 #define LIST_HEAD_INIT(name) { &(name), &(name) }
68 #define LIST_HEAD(name) \
69 struct list_head name = LIST_HEAD_INIT(name)
71 #define INIT_LIST_HEAD( _list_ ) \
73 (_list_)->next = (_list_)->prev = (_list_); \
78 /* Insert an entry _after_ the specified entry */
79 static __inline__ void
80 list_add( struct list_head *newent, struct list_head *afterthisent )
82 struct list_head *next = afterthisent->next;
84 newent->prev = afterthisent;
85 afterthisent->next = newent;
89 /* Insert an entry _before_ the specified entry */
90 static __inline__ void
91 list_add_tail( struct list_head *newent, struct list_head *beforethisent )
93 struct list_head *prev = beforethisent->prev;
95 newent->next = beforethisent;
96 beforethisent->prev = newent;
98 } /* list_add_tail() */
100 /* Delete the specified entry */
101 static __inline__ void
102 list_del( struct list_head *ent )
104 ent->prev->next = ent->next;
105 ent->next->prev = ent->prev;
108 /* Is this list empty? */
109 static __inline__ int
110 list_empty( struct list_head *list )
112 return ( list->next == list );
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 */
120 #define list_entry( _list_, _type_, _member_ ) \
121 ((_type_ *)((char *)(_list_)-(char *)(offsetof(_type_,_member_))))
123 /* list_for_each - using _ent_, iterate through list _list_ */
125 #define list_for_each( _ent_, _list_ ) \
126 for ( (_ent_) = (_list_)->next; \
127 (_ent_) != (_list_); \
128 (_ent_) = (_ent_)->next )
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_
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_))
139 /* -----------------------------------------------------------------------*/
140 #endif /* #ifndef CYGONCE_FS_JFFS2_LIST_H */