*** empty log message ***
[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.1 2004-11-03 08:14:07 charles 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 /*
42  * Simple doubly linked list implementation.
43  *
44  * Some of the internal functions ("__xxx") are useful when
45  * manipulating whole lists rather than single entries, as
46  * sometimes we already know the next/prev entries and we can
47  * generate better code by using them directly rather than
48  * using the generic single-entry routines.
49  */
50  
51  #define prefetch(x) 1
52  
53
54 struct list_head {
55         struct list_head *next, *prev;
56 };
57
58 #define LIST_HEAD_INIT(name) { &(name), &(name) }
59
60 #define LIST_HEAD(name) \
61         struct list_head name = LIST_HEAD_INIT(name)
62
63 #define INIT_LIST_HEAD(ptr) do { \
64         (ptr)->next = (ptr); (ptr)->prev = (ptr); \
65 } while (0)
66
67 /*
68  * Insert a new entry between two known consecutive entries.
69  *
70  * This is only for internal list manipulation where we know
71  * the prev/next entries already!
72  */
73 static __inline__ void __list_add(struct list_head * new,
74         struct list_head * prev,
75         struct list_head * next)
76 {
77         next->prev = new;
78         new->next = next;
79         new->prev = prev;
80         prev->next = new;
81 }
82
83 /**
84  * list_add - add a new entry
85  * @new: new entry to be added
86  * @head: list head to add it after
87  *
88  * Insert a new entry after the specified head.
89  * This is good for implementing stacks.
90  */
91 static __inline__ void list_add(struct list_head *new, struct list_head *head)
92 {
93         __list_add(new, head, head->next);
94 }
95
96 /**
97  * list_add_tail - add a new entry
98  * @new: new entry to be added
99  * @head: list head to add it before
100  *
101  * Insert a new entry before the specified head.
102  * This is useful for implementing queues.
103  */
104 static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
105 {
106         __list_add(new, head->prev, head);
107 }
108
109 /*
110  * Delete a list entry by making the prev/next entries
111  * point to each other.
112  *
113  * This is only for internal list manipulation where we know
114  * the prev/next entries already!
115  */
116 static __inline__ void __list_del(struct list_head * prev,
117                                   struct list_head * next)
118 {
119         next->prev = prev;
120         prev->next = next;
121 }
122
123 /**
124  * list_del - deletes entry from list.
125  * @entry: the element to delete from the list.
126  * Note: list_empty on entry does not return true after this, the entry is 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, struct list_head *head)
158 {
159         struct list_head *first = list->next;
160
161         if (first != list) {
162                 struct list_head *last = list->prev;
163                 struct list_head *at = head->next;
164
165                 first->prev = head;
166                 head->next = first;
167
168                 last->next = at;
169                 at->prev = last;
170         }
171 }
172
173 /**
174  * list_entry - get the struct for this entry
175  * @ptr:        the &struct list_head pointer.
176  * @type:       the type of the struct this is embedded in.
177  * @member:     the name of the list_struct within the struct.
178  */
179 #define list_entry(ptr, type, member) \
180         ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
181
182 /**
183  * list_for_each        -       iterate over a list
184  * @pos:        the &struct list_head to use as a loop counter.
185  * @head:       the head for your list.
186  */
187 #define list_for_each(pos, head) \
188         for (pos = (head)->next, prefetch(pos->next); pos != (head); \
189                 pos = pos->next, prefetch(pos->next))
190
191 /**
192  * list_for_each_safe   -       iterate over a list safe against removal of list entry
193  * @pos:        the &struct list_head to use as a loop counter.
194  * @n:          another &struct list_head to use as temporary storage
195  * @head:       the head for your list.
196  */
197 #define list_for_each_safe(pos, n, head) \
198         for (pos = (head)->next, n = pos->next; pos != (head); \
199                 pos = n, n = pos->next)
200
201
202
203
204 /*
205  * File types
206  */
207 #define DT_UNKNOWN      0
208 #define DT_FIFO         1
209 #define DT_CHR          2
210 #define DT_DIR          4
211 #define DT_BLK          6
212 #define DT_REG          8
213 #define DT_LNK          10
214 #define DT_SOCK         12
215 #define DT_WHT          14
216
217 #ifndef WIN32
218 #include <sys/stat.h>
219 #endif
220
221 /*
222  * Attribute flags.  These should be or-ed together to figure out what
223  * has been changed!
224  */
225 #define ATTR_MODE       1
226 #define ATTR_UID        2
227 #define ATTR_GID        4
228 #define ATTR_SIZE       8
229 #define ATTR_ATIME      16
230 #define ATTR_MTIME      32
231 #define ATTR_CTIME      64
232 #define ATTR_ATIME_SET  128
233 #define ATTR_MTIME_SET  256
234 #define ATTR_FORCE      512     /* Not a change, but a change it */
235 #define ATTR_ATTR_FLAG  1024
236
237
238 struct iattr {
239         unsigned int    ia_valid;
240         unsigned                ia_mode;
241         unsigned                ia_uid;
242         unsigned                ia_gid;
243         unsigned                ia_size;
244         unsigned                ia_atime;
245         unsigned        ia_mtime;
246         unsigned        ia_ctime;
247         unsigned int    ia_attr_flags;
248 };
249
250 #define KERN_DEBUG
251
252
253 #else
254
255 #ifndef WIN32
256 #include <linux/types.h>
257 #include <linux/list.h>
258 #include <linux/fs.h>
259 #include <linux/stat.h>
260 #endif
261
262 #endif
263
264
265
266 #if defined WIN32
267 #undef new
268 #endif 
269
270 #endif
271