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