Clean up some yaffs1 mode issues.
[yaffs2.git] / 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  */\r
15 \r
16 /*\r
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  *\r
21  */\r
22 \r
23 #ifndef __EXTRAS_H__\r
24 #define __EXTRAS_H__\r
25 \r
26 \r
27 #if !(defined __KERNEL__) \r
28 \r
29 /* Definition of types */
30 typedef unsigned char __u8;\r
31 typedef unsigned short __u16;\r
32 typedef unsigned __u32;\r
33 \r
34 #endif
35 \r
36 /*\r
37  * This is a simple doubly linked list implementation that matches the \r
38  * way the Linux kernel doubly linked list implementation works.\r
39  */\r
40 \r
41 struct ylist_head {
42         struct ylist_head *next; /* next in chain */
43         struct ylist_head *prev; /* previous in chain */
44 };\r
45 \r
46 \r
47 /* Initialise a list head to an empty list */\r
48 #define YINIT_LIST_HEAD(p) \
49 do { \\r
50  (p)->next = (p);\\r
51  (p)->prev = (p); \
52 } while(0)\r
53 \r
54 \r
55 /* Add an element to a list */\r
56 static __inline__ void ylist_add(struct ylist_head *newEntry, 
57                                  struct ylist_head *list)
58 {\r
59         struct ylist_head *listNext = list->next;
60         \r
61         list->next = newEntry;\r
62         newEntry->prev = list;\r
63         newEntry->next = listNext;
64         listNext->prev = newEntry;
65         
66 }
67
68 \r
69 /* Take an element out of its current list, with or without\r
70  * reinitialising the links.of the entry*/\r
71 static __inline__ void ylist_del(struct ylist_head *entry)
72 {\r
73         struct ylist_head *listNext = entry->next;
74         struct ylist_head *listPrev = entry->prev;
75         \r
76         listNext->prev = listPrev;\r
77         listPrev->next = listNext;\r
78         \r
79 }\r
80 \r
81 static __inline__ void ylist_del_init(struct ylist_head *entry)
82 {\r
83         ylist_del(entry);
84         entry->next = entry->prev = entry;\r
85 }\r
86 \r
87 \r
88 /* Test if the list is empty */\r
89 static __inline__ int ylist_empty(struct ylist_head *entry)
90 {\r
91         return (entry->next == entry);\r
92 }\r
93 \r
94 \r
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.\r
97  */\r
98  \r
99  \r
100 #define ylist_entry(entry, type, member) \
101         ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))\r
102 \r
103 \r
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  */\r
107 \r
108 #define ylist_for_each(itervar, list) \
109         for (itervar = (list)->next; itervar != (list); itervar = itervar->next )\r
110 \r
111 #define ylist_for_each_safe(itervar,saveVar, list) \
112         for (itervar = (list)->next, saveVar = (list)->next->next; itervar != (list); \\r
113          itervar = saveVar, saveVar = saveVar->next)\r
114 \r
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 */\r
126 \r
127
128 #define DT_UNKNOWN      0\r
129 #define DT_FIFO         1\r
130 #define DT_CHR          2\r
131 #define DT_DIR          4
132 #define DT_BLK          6
133 #define DT_REG          8\r
134 #define DT_LNK          10\r
135 #define DT_SOCK         12\r
136 #define DT_WHT          14
137 \r
138 \r
139 #ifndef WIN32\r
140 #include <sys/stat.h>\r
141 #endif\r
142 \r
143 /*\r
144  * Attribute flags.  These should be or-ed together to figure out what\r
145  * has been changed!\r
146  */\r
147 #define ATTR_MODE       1\r
148 #define ATTR_UID        2\r
149 #define ATTR_GID        4
150 #define ATTR_SIZE       8
151 #define ATTR_ATIME      16
152 #define ATTR_MTIME      32
153 #define ATTR_CTIME      64
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;\r
165 };\r
166 \r
167 #endif
168
169
170 #define KERN_DEBUG\r
171 \r
172 #else\r
173 \r
174 #include <linux/types.h>\r
175 #include <linux/fs.h>\r
176 #include <linux/stat.h>\r
177 \r
178 #endif\r
179 \r
180 \r
181 #endif\r