*** empty log message ***
[yaffs/.git] / devextras.h
1 /*\r
2  * YAFFS: Yet another FFS. A NAND-flash specific file system. \r
3  * devextras.h\r
4  *\r
5  * Copyright (C) 2002 Aleph One Ltd.\r
6  *   for Toby Churchill Ltd and Brightstar Engineering\r
7  *\r
8  * Created by Charles Manning <charles@aleph1.co.uk>\r
9  *\r
10  * This program is free software; you can redistribute it and/or modify\r
11  * it under the terms of the GNU General Public License version 2 as\r
12  * published by the Free Software Foundation.\r
13  *\r
14  * This file is just holds extra declarations used during development.\r
15  * Most of these are from kernel includes placed here so we can use them in \r
16  * applications.\r
17  *\r
18  */\r
19  \r
20 #ifndef __EXTRAS_H__\r
21 #define __EXTRAS_H__\r
22 \r
23 #if defined WIN32\r
24 #define __inline__ __inline\r
25 #define new newHack\r
26 #endif\r
27 \r
28 #if !(defined __KERNEL__) || (defined WIN32)\r
29 \r
30 // User space defines\r
31 \r
32 typedef unsigned char   __u8;\r
33 typedef unsigned short  __u16;\r
34 typedef unsigned        __u32;\r
35 \r
36 \r
37 /*\r
38  * Simple doubly linked list implementation.\r
39  *\r
40  * Some of the internal functions ("__xxx") are useful when\r
41  * manipulating whole lists rather than single entries, as\r
42  * sometimes we already know the next/prev entries and we can\r
43  * generate better code by using them directly rather than\r
44  * using the generic single-entry routines.\r
45  */\r
46  \r
47  #define prefetch(x) 1\r
48  \r
49 \r
50 struct list_head {\r
51         struct list_head *next, *prev;\r
52 };\r
53 \r
54 #define LIST_HEAD_INIT(name) { &(name), &(name) }\r
55 \r
56 #define LIST_HEAD(name) \\r
57         struct list_head name = LIST_HEAD_INIT(name)\r
58 \r
59 #define INIT_LIST_HEAD(ptr) do { \\r
60         (ptr)->next = (ptr); (ptr)->prev = (ptr); \\r
61 } while (0)\r
62 \r
63 /*\r
64  * Insert a new entry between two known consecutive entries.\r
65  *\r
66  * This is only for internal list manipulation where we know\r
67  * the prev/next entries already!\r
68  */\r
69 static __inline__ void __list_add(struct list_head * new,\r
70         struct list_head * prev,\r
71         struct list_head * next)\r
72 {\r
73         next->prev = new;\r
74         new->next = next;\r
75         new->prev = prev;\r
76         prev->next = new;\r
77 }\r
78 \r
79 /**\r
80  * list_add - add a new entry\r
81  * @new: new entry to be added\r
82  * @head: list head to add it after\r
83  *\r
84  * Insert a new entry after the specified head.\r
85  * This is good for implementing stacks.\r
86  */\r
87 static __inline__ void list_add(struct list_head *new, struct list_head *head)\r
88 {\r
89         __list_add(new, head, head->next);\r
90 }\r
91 \r
92 /**\r
93  * list_add_tail - add a new entry\r
94  * @new: new entry to be added\r
95  * @head: list head to add it before\r
96  *\r
97  * Insert a new entry before the specified head.\r
98  * This is useful for implementing queues.\r
99  */\r
100 static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)\r
101 {\r
102         __list_add(new, head->prev, head);\r
103 }\r
104 \r
105 /*\r
106  * Delete a list entry by making the prev/next entries\r
107  * point to each other.\r
108  *\r
109  * This is only for internal list manipulation where we know\r
110  * the prev/next entries already!\r
111  */\r
112 static __inline__ void __list_del(struct list_head * prev,\r
113                                   struct list_head * next)\r
114 {\r
115         next->prev = prev;\r
116         prev->next = next;\r
117 }\r
118 \r
119 /**\r
120  * list_del - deletes entry from list.\r
121  * @entry: the element to delete from the list.\r
122  * Note: list_empty on entry does not return true after this, the entry is in an undefined state.\r
123  */\r
124 static __inline__ void list_del(struct list_head *entry)\r
125 {\r
126         __list_del(entry->prev, entry->next);\r
127 }\r
128 \r
129 /**\r
130  * list_del_init - deletes entry from list and reinitialize it.\r
131  * @entry: the element to delete from the list.\r
132  */\r
133 static __inline__ void list_del_init(struct list_head *entry)\r
134 {\r
135         __list_del(entry->prev, entry->next);\r
136         INIT_LIST_HEAD(entry);\r
137 }\r
138 \r
139 /**\r
140  * list_empty - tests whether a list is empty\r
141  * @head: the list to test.\r
142  */\r
143 static __inline__ int list_empty(struct list_head *head)\r
144 {\r
145         return head->next == head;\r
146 }\r
147 \r
148 /**\r
149  * list_splice - join two lists\r
150  * @list: the new list to add.\r
151  * @head: the place to add it in the first list.\r
152  */\r
153 static __inline__ void list_splice(struct list_head *list, struct list_head *head)\r
154 {\r
155         struct list_head *first = list->next;\r
156 \r
157         if (first != list) {\r
158                 struct list_head *last = list->prev;\r
159                 struct list_head *at = head->next;\r
160 \r
161                 first->prev = head;\r
162                 head->next = first;\r
163 \r
164                 last->next = at;\r
165                 at->prev = last;\r
166         }\r
167 }\r
168 \r
169 /**\r
170  * list_entry - get the struct for this entry\r
171  * @ptr:        the &struct list_head pointer.\r
172  * @type:       the type of the struct this is embedded in.\r
173  * @member:     the name of the list_struct within the struct.\r
174  */\r
175 #define list_entry(ptr, type, member) \\r
176         ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))\r
177 \r
178 /**\r
179  * list_for_each        -       iterate over a list\r
180  * @pos:        the &struct list_head to use as a loop counter.\r
181  * @head:       the head for your list.\r
182  */\r
183 #define list_for_each(pos, head) \\r
184         for (pos = (head)->next, prefetch(pos->next); pos != (head); \\r
185                 pos = pos->next, prefetch(pos->next))\r
186 \r
187 /**\r
188  * list_for_each_safe   -       iterate over a list safe against removal of list entry\r
189  * @pos:        the &struct list_head to use as a loop counter.\r
190  * @n:          another &struct list_head to use as temporary storage\r
191  * @head:       the head for your list.\r
192  */\r
193 #define list_for_each_safe(pos, n, head) \\r
194         for (pos = (head)->next, n = pos->next; pos != (head); \\r
195                 pos = n, n = pos->next)\r
196 \r
197 \r
198 \r
199 \r
200 /*\r
201  * File types\r
202  */\r
203 #define DT_UNKNOWN      0\r
204 #define DT_FIFO         1\r
205 #define DT_CHR          2\r
206 #define DT_DIR          4\r
207 #define DT_BLK          6\r
208 #define DT_REG          8\r
209 #define DT_LNK          10\r
210 #define DT_SOCK         12\r
211 #define DT_WHT          14\r
212 \r
213 #ifndef WIN32\r
214 #include <sys/stat.h>\r
215 #endif\r
216 \r
217 /*\r
218  * Attribute flags.  These should be or-ed together to figure out what\r
219  * has been changed!\r
220  */\r
221 #define ATTR_MODE       1\r
222 #define ATTR_UID        2\r
223 #define ATTR_GID        4\r
224 #define ATTR_SIZE       8\r
225 #define ATTR_ATIME      16\r
226 #define ATTR_MTIME      32\r
227 #define ATTR_CTIME      64\r
228 #define ATTR_ATIME_SET  128\r
229 #define ATTR_MTIME_SET  256\r
230 #define ATTR_FORCE      512     /* Not a change, but a change it */\r
231 #define ATTR_ATTR_FLAG  1024\r
232 \r
233 \r
234 struct iattr {\r
235         unsigned int    ia_valid;\r
236         unsigned                ia_mode;\r
237         unsigned                ia_uid;\r
238         unsigned                ia_gid;\r
239         unsigned                ia_size;\r
240         unsigned                ia_atime;\r
241         unsigned        ia_mtime;\r
242         unsigned        ia_ctime;\r
243         unsigned int    ia_attr_flags;\r
244 };\r
245 \r
246 #define KERN_DEBUG\r
247 \r
248 \r
249 #else\r
250 \r
251 #ifndef WIN32\r
252 #include <linux/types.h>\r
253 #include <linux/list.h>\r
254 #include <linux/fs.h>\r
255 #include <linux/stat.h>\r
256 #endif\r
257 \r
258 #endif\r
259 \r
260 \r
261 \r
262 #if defined WIN32\r
263 #undef new\r
264 #endif \r
265 \r
266 #endif\r
267 \r