• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static list */
48 #define YLIST_HEAD(name) \
49 struct ylist_head name = { &(name), &(name)}
50 
51 
52 
53 /* Initialise a list head to an empty list */
54 #define YINIT_LIST_HEAD(p) \
55 do { \
56 	(p)->next = (p);\
57 	(p)->prev = (p); \
58 } while (0)
59 
60 
61 /* Add an element to a list */
ylist_add(struct ylist_head * newEntry,struct ylist_head * list)62 static __inline__ void ylist_add(struct ylist_head *newEntry,
63 				struct ylist_head *list)
64 {
65 	struct ylist_head *listNext = list->next;
66 
67 	list->next = newEntry;
68 	newEntry->prev = list;
69 	newEntry->next = listNext;
70 	listNext->prev = newEntry;
71 
72 }
73 
ylist_add_tail(struct ylist_head * newEntry,struct ylist_head * list)74 static __inline__ void ylist_add_tail(struct ylist_head *newEntry,
75 				 struct ylist_head *list)
76 {
77 	struct ylist_head *listPrev = list->prev;
78 
79 	list->prev = newEntry;
80 	newEntry->next = list;
81 	newEntry->prev = listPrev;
82 	listPrev->next = newEntry;
83 
84 }
85 
86 
87 /* Take an element out of its current list, with or without
88  * reinitialising the links.of the entry*/
ylist_del(struct ylist_head * entry)89 static __inline__ void ylist_del(struct ylist_head *entry)
90 {
91 	struct ylist_head *listNext = entry->next;
92 	struct ylist_head *listPrev = entry->prev;
93 
94 	listNext->prev = listPrev;
95 	listPrev->next = listNext;
96 
97 }
98 
ylist_del_init(struct ylist_head * entry)99 static __inline__ void ylist_del_init(struct ylist_head *entry)
100 {
101 	ylist_del(entry);
102 	entry->next = entry->prev = entry;
103 }
104 
105 
106 /* Test if the list is empty */
ylist_empty(struct ylist_head * entry)107 static __inline__ int ylist_empty(struct ylist_head *entry)
108 {
109 	return (entry->next == entry);
110 }
111 
112 
113 /* ylist_entry takes a pointer to a list entry and offsets it to that
114  * we can find a pointer to the object it is embedded in.
115  */
116 
117 
118 #define ylist_entry(entry, type, member) \
119 	((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
120 
121 
122 /* ylist_for_each and list_for_each_safe  iterate over lists.
123  * ylist_for_each_safe uses temporary storage to make the list delete safe
124  */
125 
126 #define ylist_for_each(itervar, list) \
127 	for (itervar = (list)->next; itervar != (list); itervar = itervar->next)
128 
129 #define ylist_for_each_safe(itervar, saveVar, list) \
130 	for (itervar = (list)->next, saveVar = (list)->next->next; \
131 		itervar != (list); itervar = saveVar, saveVar = saveVar->next)
132 
133 
134 #if !(defined __KERNEL__)
135 
136 
137 #ifndef WIN32
138 #include <sys/stat.h>
139 #endif
140 
141 
142 #ifdef CONFIG_YAFFS_PROVIDE_DEFS
143 /* File types */
144 
145 
146 #define DT_UNKNOWN	0
147 #define DT_FIFO		1
148 #define DT_CHR		2
149 #define DT_DIR		4
150 #define DT_BLK		6
151 #define DT_REG		8
152 #define DT_LNK		10
153 #define DT_SOCK		12
154 #define DT_WHT		14
155 
156 
157 #ifndef WIN32
158 #include <sys/stat.h>
159 #endif
160 
161 /*
162  * Attribute flags.  These should be or-ed together to figure out what
163  * has been changed!
164  */
165 #define ATTR_MODE	1
166 #define ATTR_UID	2
167 #define ATTR_GID	4
168 #define ATTR_SIZE	8
169 #define ATTR_ATIME	16
170 #define ATTR_MTIME	32
171 #define ATTR_CTIME	64
172 
173 struct iattr {
174 	unsigned int ia_valid;
175 	unsigned ia_mode;
176 	unsigned ia_uid;
177 	unsigned ia_gid;
178 	unsigned ia_size;
179 	unsigned ia_atime;
180 	unsigned ia_mtime;
181 	unsigned ia_ctime;
182 	unsigned int ia_attr_flags;
183 };
184 
185 #endif
186 
187 #else
188 
189 #include <linux/types.h>
190 #include <linux/fs.h>
191 #include <linux/stat.h>
192 
193 #endif
194 
195 
196 #endif
197