yaffs Yaffs importer now works with hardlinks and symlink.
[yaffs2.git] / yaffs_list.h
1 /*
2  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
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.
12  *
13  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
14  */
15
16 /*
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.
20  *
21  */
22
23 #ifndef __YAFFS_LIST_H__
24 #define __YAFFS_LIST_H__
25
26
27 #include "yportenv.h"
28
29 /*
30  * This is a simple doubly linked list implementation that matches the
31  * way the Linux kernel doubly linked list implementation works.
32  */
33
34 struct ylist_head {
35         struct ylist_head *next; /* next in chain */
36         struct ylist_head *prev; /* previous in chain */
37 };
38
39
40 /* Initialise a static list */
41 #define YLIST_HEAD(name) \
42 struct ylist_head name = { &(name), &(name)}
43
44
45
46 /* Initialise a list head to an empty list */
47 #define YINIT_LIST_HEAD(p) \
48 do { \
49         (p)->next = (p);\
50         (p)->prev = (p); \
51 } while (0)
52
53
54 /* Add an element to a list */
55 static Y_INLINE void ylist_add(struct ylist_head *newEntry,
56                                 struct ylist_head *list)
57 {
58         struct ylist_head *listNext = list->next;
59
60         list->next = newEntry;
61         newEntry->prev = list;
62         newEntry->next = listNext;
63         listNext->prev = newEntry;
64
65 }
66
67 static Y_INLINE void ylist_add_tail(struct ylist_head *newEntry,
68                                  struct ylist_head *list)
69 {
70         struct ylist_head *listPrev = list->prev;
71
72         list->prev = newEntry;
73         newEntry->next = list;
74         newEntry->prev = listPrev;
75         listPrev->next = newEntry;
76
77 }
78
79
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)
83 {
84         struct ylist_head *listNext = entry->next;
85         struct ylist_head *listPrev = entry->prev;
86
87         listNext->prev = listPrev;
88         listPrev->next = listNext;
89
90 }
91
92 static Y_INLINE void ylist_del_init(struct ylist_head *entry)
93 {
94         ylist_del(entry);
95         entry->next = entry->prev = entry;
96 }
97
98
99 /* Test if the list is empty */
100 static Y_INLINE int ylist_empty(struct ylist_head *entry)
101 {
102         return (entry->next == entry);
103 }
104
105
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.
108  */
109
110
111 #define ylist_entry(entry, type, member) \
112         ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
113
114
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
117  */
118
119 #define ylist_for_each(itervar, list) \
120         for (itervar = (list)->next; itervar != (list); itervar = itervar->next)
121
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)
125
126
127 #endif