yaffs direct: Fix yaffs_access to follow symbolic links.
[yaffs2.git] / direct / 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 list_head {
35         struct list_head *next; /* next in chain */
36         struct list_head *prev; /* previous in chain */
37 };
38
39
40 /* Initialise a static list */
41 #define LIST_HEAD(name) \
42 struct list_head name = { &(name), &(name)}
43
44
45
46 /* Initialise a list head to an empty list */
47 #define INIT_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 list_add(struct list_head *new_entry,
56                                 struct list_head *list)
57 {
58         struct list_head *list_next = list->next;
59
60         list->next = new_entry;
61         new_entry->prev = list;
62         new_entry->next = list_next;
63         list_next->prev = new_entry;
64
65 }
66
67 static Y_INLINE void list_add_tail(struct list_head *new_entry,
68                                  struct list_head *list)
69 {
70         struct list_head *list_prev = list->prev;
71
72         list->prev = new_entry;
73         new_entry->next = list;
74         new_entry->prev = list_prev;
75         list_prev->next = new_entry;
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 list_del(struct list_head *entry)
83 {
84         struct list_head *list_next = entry->next;
85         struct list_head *list_prev = entry->prev;
86
87         list_next->prev = list_prev;
88         list_prev->next = list_next;
89
90 }
91
92 static Y_INLINE void list_del_init(struct list_head *entry)
93 {
94         list_del(entry);
95         entry->next = entry->prev = entry;
96 }
97
98
99 /* Test if the list is empty */
100 static Y_INLINE int list_empty(struct list_head *entry)
101 {
102         return (entry->next == entry);
103 }
104
105
106 /* list_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 list_entry(entry, type, member) \
112         ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
113
114
115 /* list_for_each and list_for_each_safe  iterate over lists.
116  * list_for_each_safe uses temporary storage to make the list delete safe
117  */
118
119 #define list_for_each(itervar, list) \
120         for (itervar = (list)->next; itervar != (list); itervar = itervar->next)
121
122 #define list_for_each_safe(itervar, save_var, list) \
123         for (itervar = (list)->next, save_var = (list)->next->next; \
124                 itervar != (list); itervar = save_var, save_var = save_var->next)
125
126
127 #endif