2 * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
4 * Copyright (C) 2002-2011 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License version 2.1 as
11 * published by the Free Software Foundation.
13 * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
17 * This file is just holds extra declarations of macros that would normally
18 * be providesd in the Linux kernel. These macros have been written from
19 * scratch but are functionally equivalent to the Linux ones.
23 #ifndef __YAFFS_LIST_H__
24 #define __YAFFS_LIST_H__
28 * This is a simple doubly linked list implementation that matches the
29 * way the Linux kernel doubly linked list implementation works.
33 struct list_head
*next
; /* next in chain */
34 struct list_head
*prev
; /* previous in chain */
38 /* Initialise a static list */
39 #define LIST_HEAD(name) \
40 struct list_head name = { &(name), &(name)}
44 /* Initialise a list head to an empty list */
45 #define INIT_LIST_HEAD(p) \
52 /* Add an element to a list */
53 static inline void list_add(struct list_head
*new_entry
,
54 struct list_head
*list
)
56 struct list_head
*list_next
= list
->next
;
58 list
->next
= new_entry
;
59 new_entry
->prev
= list
;
60 new_entry
->next
= list_next
;
61 list_next
->prev
= new_entry
;
65 static inline void list_add_tail(struct list_head
*new_entry
,
66 struct list_head
*list
)
68 struct list_head
*list_prev
= list
->prev
;
70 list
->prev
= new_entry
;
71 new_entry
->next
= list
;
72 new_entry
->prev
= list_prev
;
73 list_prev
->next
= new_entry
;
78 /* Take an element out of its current list, with or without
79 * reinitialising the links.of the entry*/
80 static inline void list_del(struct list_head
*entry
)
82 struct list_head
*list_next
= entry
->next
;
83 struct list_head
*list_prev
= entry
->prev
;
85 list_next
->prev
= list_prev
;
86 list_prev
->next
= list_next
;
90 static inline void list_del_init(struct list_head
*entry
)
93 entry
->next
= entry
->prev
= entry
;
97 /* Test if the list is empty */
98 static inline int list_empty(struct list_head
*entry
)
100 return (entry
->next
== entry
);
104 /* list_entry takes a pointer to a list entry and offsets it to that
105 * we can find a pointer to the object it is embedded in.
109 #define list_entry(entry, type, member) \
110 ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
113 /* list_for_each and list_for_each_safe iterate over lists.
114 * list_for_each_safe uses temporary storage to make the list delete safe
117 #define list_for_each(itervar, list) \
118 for (itervar = (list)->next; itervar != (list); itervar = itervar->next)
120 #define list_for_each_safe(itervar, save_var, list) \
121 for (itervar = (list)->next, save_var = (list)->next->next; \
123 itervar = save_var, save_var = save_var->next)