generic-2.6: sync yaffs code with the official CVS tree
[openwrt/openwrt.git] / target / linux / generic-2.6 / files / fs / yaffs2 / devextras.h
1 /*
2 * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
3 *
4 * Copyright (C) 2002-2007 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
6 *
7 * Created by Charles Manning <charles@aleph1.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License version 2.1 as
11 * published by the Free Software Foundation.
12 *
13 * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
14 */
15
16 /*
17 * This file is just holds extra declarations of macros that would normally
18 * be providesd in the Linux kernel. These macros have been written from
19 * scratch but are functionally equivalent to the Linux ones.
20 *
21 */
22
23 #ifndef __EXTRAS_H__
24 #define __EXTRAS_H__
25
26
27 #if !(defined __KERNEL__)
28
29 /* Definition of types */
30 typedef unsigned char __u8;
31 typedef unsigned short __u16;
32 typedef unsigned __u32;
33
34 #endif
35
36 /*
37 * This is a simple doubly linked list implementation that matches the
38 * way the Linux kernel doubly linked list implementation works.
39 */
40
41 struct ylist_head {
42 struct ylist_head *next; /* next in chain */
43 struct ylist_head *prev; /* previous in chain */
44 };
45
46
47 /* Initialise a list head to an empty list */
48 #define YINIT_LIST_HEAD(p) \
49 do { \
50 (p)->next = (p);\
51 (p)->prev = (p); \
52 } while(0)
53
54
55 /* Add an element to a list */
56 static __inline__ void ylist_add(struct ylist_head *newEntry,
57 struct ylist_head *list)
58 {
59 struct ylist_head *listNext = list->next;
60
61 list->next = newEntry;
62 newEntry->prev = list;
63 newEntry->next = listNext;
64 listNext->prev = newEntry;
65
66 }
67
68
69 /* Take an element out of its current list, with or without
70 * reinitialising the links.of the entry*/
71 static __inline__ void ylist_del(struct ylist_head *entry)
72 {
73 struct ylist_head *listNext = entry->next;
74 struct ylist_head *listPrev = entry->prev;
75
76 listNext->prev = listPrev;
77 listPrev->next = listNext;
78
79 }
80
81 static __inline__ void ylist_del_init(struct ylist_head *entry)
82 {
83 ylist_del(entry);
84 entry->next = entry->prev = entry;
85 }
86
87
88 /* Test if the list is empty */
89 static __inline__ int ylist_empty(struct ylist_head *entry)
90 {
91 return (entry->next == entry);
92 }
93
94
95 /* ylist_entry takes a pointer to a list entry and offsets it to that
96 * we can find a pointer to the object it is embedded in.
97 */
98
99
100 #define ylist_entry(entry, type, member) \
101 ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
102
103
104 /* ylist_for_each and list_for_each_safe iterate over lists.
105 * ylist_for_each_safe uses temporary storage to make the list delete safe
106 */
107
108 #define ylist_for_each(itervar, list) \
109 for (itervar = (list)->next; itervar != (list); itervar = itervar->next )
110
111 #define ylist_for_each_safe(itervar,saveVar, list) \
112 for (itervar = (list)->next, saveVar = (list)->next->next; itervar != (list); \
113 itervar = saveVar, saveVar = saveVar->next)
114
115
116 #if !(defined __KERNEL__)
117
118
119 #ifndef WIN32
120 #include <sys/stat.h>
121 #endif
122
123
124 #ifdef CONFIG_YAFFS_PROVIDE_DEFS
125 /* File types */
126
127
128 #define DT_UNKNOWN 0
129 #define DT_FIFO 1
130 #define DT_CHR 2
131 #define DT_DIR 4
132 #define DT_BLK 6
133 #define DT_REG 8
134 #define DT_LNK 10
135 #define DT_SOCK 12
136 #define DT_WHT 14
137
138
139 #ifndef WIN32
140 #include <sys/stat.h>
141 #endif
142
143 /*
144 * Attribute flags.
145 */
146 #define ATTR_MODE 1
147 #define ATTR_UID 2
148 #define ATTR_GID 4
149 #define ATTR_SIZE 8
150 #define ATTR_ATIME 16
151 #define ATTR_MTIME 32
152 #define ATTR_CTIME 64
153
154
155 struct iattr {
156 unsigned int ia_valid;
157 unsigned ia_mode;
158 unsigned ia_uid;
159 unsigned ia_gid;
160 unsigned ia_size;
161 unsigned ia_atime;
162 unsigned ia_mtime;
163 unsigned ia_ctime;
164 unsigned int ia_attr_flags;
165 };
166
167 #endif
168
169
170 #define KERN_DEBUG
171
172 #else
173
174 #include <linux/types.h>
175 #include <linux/fs.h>
176 #include <linux/stat.h>
177
178 #endif
179
180
181 #endif