Change list macros
[yaffs2.git] / devextras.h
1 /*
2  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2007 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 __EXTRAS_H__
24 #define __EXTRAS_H__
25
26 #if defined WIN32
27 #define __inline__ __inline
28 #define new newHack
29 #endif
30
31 #if !(defined __KERNEL__) || (defined WIN32)
32
33 /* Definition of types */
34 typedef unsigned char __u8;
35 typedef unsigned short __u16;
36 typedef unsigned __u32;
37
38 /*
39  * This is a simple doubly linked list implementation that matches the 
40  * way the Linux kernel doubly linked list implementation works.
41  */
42
43 struct list_head {
44         struct list_head *next; /* next in chain */
45         struct list_head *prev; /* previous in chain */
46 };
47
48
49 /* Initialise a list head to an empty list */
50 #define INIT_LIST_HEAD(p) \
51 do { \
52  (p)->next = (p);\
53  (p)->next = (p); \
54 } while(0)
55
56
57 /* Add an element to a list */
58 static __inline__ void list_add(struct list_head *newEntry, 
59                                 struct list_head *list)
60 {
61         struct list_head *listNext = list->next;
62         
63         list->next = newEntry;
64         newEntry->prev = list;
65         newEntry->next = listNext;
66         listNext->prev = newEntry;
67         
68 }
69
70
71 /* Take an element out of its current list, with or without
72  * reinitialising the links.of the entry*/
73 static __inline__ void list_del(struct list_head *entry)
74 {
75         struct list_head *listNext = entry->next;
76         struct list_head *listPrev = entry->prev;
77         
78         listNext->prev = listPrev;
79         listPrev->next = listNext;
80         
81 }
82
83 static __inline__ void list_del_init(struct list_head *entry)
84 {
85         list_del(entry);
86         entry->next = entry->prev = entry;
87 }
88
89
90 /* Test if the list is empty */
91 static __inline__ int list_empty(struct list_head *entry)
92 {
93         return (entry->next == entry);
94 }
95
96
97 /* list_entry takes a pointer to a list entry and offsets it to that
98  * we can find a pointer to the object it is embedded in.
99  */
100  
101  
102 #define list_entry(entry, type, member) \
103         ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
104
105
106 /* list_for_each and list_for_each_safe  iterate over lists.
107  * list_for_each_safe uses temporary storage to make the list delete safe
108  */
109
110 #define list_for_each(itervar, list) \
111         for (itervar = (list)->next; itervar != (list); itervar = itervar->next )
112
113 #define list_for_each_safe(itervar,saveVar, list) \
114         for (itervar = (list)->next, saveVar = (list)->next->next; itervar != (list); \
115          itervar = saveVar, saveVar = saveVar->next)
116
117 /* File types */
118
119 #define DT_UNKNOWN      0
120 #define DT_FIFO         1
121 #define DT_CHR          2
122 #define DT_DIR          4
123 #define DT_BLK          6
124 #define DT_REG          8
125 #define DT_LNK          10
126 #define DT_SOCK         12
127 #define DR_WHT          14
128
129
130 #ifndef WIN32
131 #include <sys/stat.h>
132 #endif
133
134 /*
135  * Attribute flags.
136  */
137 #define ATTR_MODE       1
138 #define ATTR_UID        2
139 #define ATTR_GID        4
140 #define ATTR_SIZE       8
141 #define ATTR_ATIME      16
142 #define ATTR_MTIME      32
143 #define ATTR_CTIME      64
144
145
146 struct iattr {
147         unsigned int ia_valid;
148         unsigned ia_mode;
149         unsigned ia_uid;
150         unsigned ia_gid;
151         unsigned ia_size;
152         unsigned ia_atime;
153         unsigned ia_mtime;
154         unsigned ia_ctime;
155         unsigned int ia_attr_flags;
156 };
157
158 #define KERN_DEBUG
159
160 #else
161
162 #ifndef WIN32
163 #include <linux/types.h>
164 #include <linux/list.h>
165 #include <linux/fs.h>
166 #include <linux/stat.h>
167 #endif
168
169 #endif
170
171 #if defined WIN32
172 #undef new
173 #endif
174
175 #endif