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