Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:17

0001 /*
0002  * JFFS2 -- Journalling Flash File System, Version 2.
0003  *
0004  *
0005  * Created by Jonathan Larmour <jlarmour@redhat.com>
0006  * 
0007  *===========================================================================
0008  * ####ECOSGPLCOPYRIGHTBEGIN####                                            
0009  * -------------------------------------------                              
0010  * This file is part of eCos, the Embedded Configurable Operating System.   
0011  * Copyright (C) 2002, 2003 Free Software Foundation, Inc.                  
0012  *
0013  * eCos is free software; you can redistribute it and/or modify it under    
0014  * the terms of the GNU General Public License as published by the Free     
0015  * Software Foundation; either version 2 or (at your option) any later      
0016  * version.                                                                 
0017  *
0018  * eCos is distributed in the hope that it will be useful, but WITHOUT      
0019  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
0020  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
0021  * for more details.                                                        
0022  *
0023  * You should have received a copy of the GNU General Public License        
0024  * along with eCos; if not, write to the Free Software Foundation, Inc.,    
0025  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
0026  *
0027  * As a special exception, if other files instantiate templates or use      
0028  * macros or inline functions from this file, or you compile this file      
0029  * and link it with other works to produce a work based on this file,       
0030  * this file does not by itself cause the resulting work to be covered by   
0031  * the GNU General Public License. However the source code for this file    
0032  * must still be made available in accordance with section (3) of the GNU   
0033  * General Public License v2.                                               
0034  *
0035  * This exception does not invalidate any other reasons why a work based    
0036  * on this file might be covered by the GNU General Public License.         
0037  * -------------------------------------------                              
0038  * ####ECOSGPLCOPYRIGHTEND####                                              
0039  *===========================================================================
0040  *
0041  */
0042 
0043 #ifndef CYGONCE_FS_JFFS2_LIST_H
0044 #define CYGONCE_FS_JFFS2_LIST_H
0045 
0046 
0047 /* -----------------------------------------------------------------------*/
0048 
0049 /* Doubly linked list implementation to replace the GPL'd one used in
0050    the Linux kernel. */
0051 
0052 #include <stddef.h>
0053 #include <cyg/infra/cyg_type.h>
0054 
0055 /* TYPES */
0056 
0057 struct list_head {
0058     struct list_head *next;
0059     struct list_head *prev;
0060 };
0061 
0062 /* MACROS */
0063 
0064 #define LIST_HEAD_INIT(name) { &(name), &(name) }
0065 
0066 #define LIST_HEAD(name) \
0067         struct list_head name = LIST_HEAD_INIT(name)
0068 
0069 #define INIT_LIST_HEAD( _list_ )              \
0070 CYG_MACRO_START                               \
0071 (_list_)->next = (_list_)->prev = (_list_);   \
0072 CYG_MACRO_END
0073 
0074 /* FUNCTIONS */
0075 
0076 /* Insert an entry _after_ the specified entry */
0077 static __inline__ void
0078 list_add( struct list_head *newent, struct list_head *afterthisent )
0079 {
0080     struct list_head *next = afterthisent->next;
0081     newent->next = next;
0082     newent->prev = afterthisent;
0083     afterthisent->next = newent;
0084     next->prev = newent;
0085 } /* list_add() */
0086 
0087 /* Insert an entry _before_ the specified entry */
0088 static __inline__ void
0089 list_add_tail( struct list_head *newent, struct list_head *beforethisent )
0090 {
0091     struct list_head *prev = beforethisent->prev;
0092     newent->prev = prev;
0093     newent->next = beforethisent;
0094     beforethisent->prev = newent;
0095     prev->next = newent;
0096 } /* list_add_tail() */
0097 
0098 /* Delete the specified entry */
0099 static __inline__ void
0100 list_del( struct list_head *ent )
0101 {
0102     ent->prev->next = ent->next;
0103     ent->next->prev = ent->prev;
0104 } /* list_del() */
0105 
0106 static __inline__ void
0107 list_move( struct list_head *list, struct list_head *head )
0108 {
0109     list_del( list );
0110     list_add( list, head );
0111 }
0112 
0113 static __inline__ void
0114 list_move_tail( struct list_head *list, struct list_head *head )
0115 {
0116     list_del( list );
0117     list_add_tail( list, head );
0118 }
0119 
0120 /* Is this list empty? */
0121 static __inline__ int
0122 list_empty( struct list_head *list )
0123 {
0124     return ( list->next == list );
0125 } /* list_empty() */
0126 
0127 /* list_entry - Assuming you have a struct of type _type_ that contains a
0128    list which has the name _member_ in that struct type, then given the
0129    address of that list in the struct, _list_, this returns the address
0130    of the container structure */
0131 
0132 #define list_entry( _list_, _type_, _member_ ) \
0133     ((_type_ *)((char *)(_list_)-(char *)(offsetof(_type_,_member_))))
0134 
0135 /* list_for_each - using _ent_, iterate through list _list_ */
0136 
0137 #define list_for_each( _ent_, _list_ )   \
0138     for ( (_ent_) = (_list_)->next;      \
0139     (_ent_) != (_list_);                 \
0140     (_ent_) = (_ent_)->next )
0141 
0142 /* list_for_each_safe - using _ent_, iterate through list _list_
0143    while protecting against removal of list elements */
0144 
0145 #define list_for_each_safe( _ent_, _tmp_, _list_ )           \
0146     for ( (_ent_) = (_list_)->next, (_tmp_) = (_ent_)->next; \
0147     (_ent_) != (_list_);                                     \
0148     (_ent_) = (_tmp_), (_tmp_) = (_ent_)->next )
0149 
0150 /*
0151  * list_for_each_entry - this function can be use to iterate over all
0152  * items in a list* _list_ with it's head at _head_ and link _item_
0153  */
0154 #define list_for_each_entry(_list_, _head_, _item_)                     \
0155 for ((_list_) = list_entry((_head_)->next, typeof(*_list_), _item_); \
0156      &((_list_)->_item_) != (_head_);                                 \
0157      (_list_) = list_entry((_list_)->_item_.next, typeof(*_list_), _item_))
0158 
0159 /* -----------------------------------------------------------------------*/
0160 #endif /* #ifndef CYGONCE_FS_JFFS2_LIST_H */
0161 /* EOF list.h */