2 * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 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__
30 * This is a simple doubly linked list implementation that matches the
31 * way the Linux kernel doubly linked list implementation works.
35 struct ylist_head *next; /* next in chain */
36 struct ylist_head *prev; /* previous in chain */
40 /* Initialise a static list */
41 #define YLIST_HEAD(name) \
42 struct ylist_head name = { &(name), &(name)}
46 /* Initialise a list head to an empty list */
47 #define YINIT_LIST_HEAD(p) \
54 /* Add an element to a list */
55 static Y_INLINE void ylist_add(struct ylist_head *newEntry,
56 struct ylist_head *list)
58 struct ylist_head *listNext = list->next;
60 list->next = newEntry;
61 newEntry->prev = list;
62 newEntry->next = listNext;
63 listNext->prev = newEntry;
67 static Y_INLINE void ylist_add_tail(struct ylist_head *newEntry,
68 struct ylist_head *list)
70 struct ylist_head *listPrev = list->prev;
72 list->prev = newEntry;
73 newEntry->next = list;
74 newEntry->prev = listPrev;
75 listPrev->next = newEntry;
80 /* Take an element out of its current list, with or without
81 * reinitialising the links.of the entry*/
82 static Y_INLINE void ylist_del(struct ylist_head *entry)
84 struct ylist_head *listNext = entry->next;
85 struct ylist_head *listPrev = entry->prev;
87 listNext->prev = listPrev;
88 listPrev->next = listNext;
92 static Y_INLINE void ylist_del_init(struct ylist_head *entry)
95 entry->next = entry->prev = entry;
99 /* Test if the list is empty */
100 static Y_INLINE int ylist_empty(struct ylist_head *entry)
102 return (entry->next == entry);
106 /* ylist_entry takes a pointer to a list entry and offsets it to that
107 * we can find a pointer to the object it is embedded in.
111 #define ylist_entry(entry, type, member) \
112 ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
115 /* ylist_for_each and list_for_each_safe iterate over lists.
116 * ylist_for_each_safe uses temporary storage to make the list delete safe
119 #define ylist_for_each(itervar, list) \
120 for (itervar = (list)->next; itervar != (list); itervar = itervar->next)
122 #define ylist_for_each_safe(itervar, saveVar, list) \
123 for (itervar = (list)->next, saveVar = (list)->next->next; \
124 itervar != (list); itervar = saveVar, saveVar = saveVar->next)