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